Using R Programming Structures: Functions & Environments
R Programming
| Intermediate
- 13 videos | 1h 40m 27s
- Includes Assessment
- Earns a Badge
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 courseRecall how built-in functions can be viewed and new functions createdIntroduce the return function and recall ways of returning data without invoking itImplement the use of named arguments to pass in data to functionsSpecify default arguments for functionsSpecify functions as input arguments to other functionsUse functions with switch statements and store functions in other data structures
-
Recall the use of r environments as bindings of variable names to valuesCreate inner nested functions within outer functionsRecognize the nested environments created by default within a functionImplement closures, which include the environment, body, and input arguments to a functionCreate and use replacement functions to specify functions that can be l-valuesSummarize the key concepts covered in this course
IN THIS COURSE
-
2m 32sIn 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 9sIn 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
-
9m 37sIn 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
-
8m 51sIn 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
-
12m 21sIn 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
-
5m 48sIn 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
-
6m 46sIn 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
-
11m 5sIn 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
-
8m 14sIn 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
-
10m 32sIn 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
-
5m 57sIn 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
-
9m 47sIn 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
-
1m 48sIn 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.