Using R Programming Structures: Functions & Environments

R Programming    |    Intermediate
  • 13 videos | 1h 40m 27s
  • Includes Assessment
  • Earns a Badge
Rating 4.3 of 14 users Rating 4.3 of 14 users (14)
R supports several powerful features, such as first-class functions, functions on the left-hand side of an assignment, and explicit environment objects that bind variables to values. Taken together, these make R a powerful language for functional programming. This course will show you how to work effectively with functions in R. Specifically, you'll learn how to create and invoke functions in R and leverage R support for functional programming and first-class functions. You'll recognize how an R environment is a virtual binding between variable names and values. You'll create nested environments and leverage the fact that individual functions have their own local environments. You'll also create and invoke closures as well as replacement functions. By the end of the course, you'll have the confidence to work with functions in your R programming projects.

WHAT YOU WILL LEARN

  • Discover the key concepts covered in this course
    Recall how built-in functions can be viewed and new functions created
    Introduce the return function and recall ways of returning data without invoking it
    Implement the use of named arguments to pass in data to functions
    Specify default arguments for functions
    Specify functions as input arguments to other functions
    Use functions with switch statements and store functions in other data structures
  • Recall the use of r environments as bindings of variable names to values
    Create inner nested functions within outer functions
    Recognize the nested environments created by default within a function
    Implement closures, which include the environment, body, and input arguments to a function
    Create and use replacement functions to specify functions that can be l-values
    Summarize the key concepts covered in this course

IN THIS COURSE

  • 2m 32s
    In this video, you’ll learn more about your instructor and this course. In this course, you’ll learn the basics of functions in R. You’ll see how functions are basically blocks of code that can be invoked in a parameterized fashion. You’ll learn about the use of the return function in order to return values, and you’ll learn why R is set to support functions as first-class citizens. You’ll create nested environments as well. FREE ACCESS
  • 7m 9s
    In this video, you’ll watch a demo. In this demo, you’ll see function in R is pretty much like a function in any other programming language. You’ll see it's a block of code you can invoke by name and that you can parameterize, you can pass in specific input arguments, and the return value will usually change accordingly. You’ll start with some built-in functions. Onscreen, you’ll see the question mark operator with the function sample. FREE ACCESS
  • Locked
    3.  Returning Data from Functions in R
    9m 37s
    In this video, you’ll watch a demo. In this demo, you’ll continue working with functions. You'll pick up right where you left off at the end of the last demo. You had just defined your first custom function and invoked it. The output of that invocation is visible onscreen now. You’ll see any function must be defined before it can be invoked. Here you’ll type out the name of a function called compute_square. FREE ACCESS
  • Locked
    4.  Using Named Arguments in R
    8m 51s
    In this video, you’ll watch a demo. In this demo, you’ll continue to explore functions in R. You’re building up towards the idea of functions as first-class objects. First, you’ll have to understand some basic properties of R functions. To begin with, you’ll learn functions in R can return complex types. Onscreen, you’ll see a function which returns a list. FREE ACCESS
  • Locked
    5.  Using Default Arguments in R
    12m 21s
    In this video, you’ll watch a demo. In this demo, you’ll pick up where you left off in the last one. Now, you’ll start with a simple redefinition of the function append_student_row. Here you've specified a default value for input arguments. You’ve specified name= Unknown and gpa=3.0. This was done while defining the function. FREE ACCESS
  • Locked
    6.  Working with First-class Functions in R
    5m 48s
    In this video, you’ll watch a demo. This demo is about functions in R as first-class objects. This term has a very specific meaning. It implies functions satisfy four properties. You’ll learn functions can be assigned to variables. Functions can be passed in as input arguments to other functions. They can be stored in vectors and lists, and functions can be returned as return values from other functions. FREE ACCESS
  • Locked
    7.  Storing Functions & Using Them in Switch Statements
    6m 46s
    In this video, you’ll watch a demo. This demo is about writing your own functions and pass those in to apply function. Onscreen you’ll see two such functions, quantile 25 and quantile 75. You’ll see the quote for both these functions is almost identical. Each takes in a vector, each invokes the built-in quantile function on that vector defines the names property of the result to be null and returns that result. FREE ACCESS
  • Locked
    8.  Working with R Environments
    11m 5s
    In this video, you’ll watch a demo. This demo will build on the idea of how R supports for functions as first-class objects. This will lead into the idea of closures in R. First, you’ll learn about environments. The idea of an environment in R is like that of a namespace in other programming languages. It refers to a virtual binding between variable names and their values. Every R function has its own environment. FREE ACCESS
  • Locked
    9.  Creating Inner Functions in R
    8m 14s
    In this video, you’ll watch a demo. In previous demos, you’ve learned about environments and functions as objects. In this demo, you’ll begin to tie those two ideas together. You’ll start building up to the idea of functions and closures in R. You’ll begin by examining the environment associated with every function. Every function has its own little internal environment. You’ll start by defining some variables. FREE ACCESS
  • Locked
    10.  Recognizing R Functions and Environments
    10m 32s
    In this video, you’ll watch a demo. In this demo, you’ll pick up right where you left off. You’ll create another function called outer_b. This function exists in the global environment and also has an inner function. This inner function is called inner_b. You can see the structure of outer_b and inner_b mirrors the structures of outer_a and inner_a. FREE ACCESS
  • Locked
    11.  Working with Closures in R
    5m 57s
    In this video, you’ll watch a demo. In this demo, you’ll work more with closures. In R, all functions are Closures. A Closure contains all the arguments passed into the function, the body of the function, and the environment of the function. Now, you’ll see how this works. Onscreen you’ll see a function called get_counter. This function internally defines a variable that's called counter and defines a function called counter.fn. FREE ACCESS
  • Locked
    12.  Working with Replacement Functions in R
    9m 47s
    In this video, you’ll watch a demo. Onscreen, you’ll see a flashback to a previous demo. You can see that in this code cell, the first seven elements of the letters built-in variable have been assigned to the rownames property of our variable students.dataframe. You’ll also see the output down below. students.dataframe now has row names A through G. FREE ACCESS
  • Locked
    13.  Course Summary
    1m 48s
    In this video, you’ll summarize what you’ve learned in the course. In this course, you learned that functions are blocks of code that can be executed wherever invoked. You saw some of the definitions of built-in functions and created basic function which printed extra screen when invoked. You learned input arguments to specify values for a function to use. You also learned about the use of the return function to return values from a function. FREE ACCESS

EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE

Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.

Digital badges are yours to keep, forever.

YOU MIGHT ALSO LIKE

Rating 4.3 of 86 users Rating 4.3 of 86 users (86)
Rating 4.5 of 15 users Rating 4.5 of 15 users (15)
Rating 4.5 of 75 users Rating 4.5 of 75 users (75)

PEOPLE WHO VIEWED THIS ALSO VIEWED THESE

Rating 4.4 of 11 users Rating 4.4 of 11 users (11)
Rating 4.2 of 18 users Rating 4.2 of 18 users (18)
Rating 4.5 of 239 users Rating 4.5 of 239 users (239)