From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Excel in R: IF

Excel in R: IF

- [Instructor] So I'm going to start talking about some Excel functions and the R equivalents. Let's start out with the Excel version of if. And what I've done here in cell A8 is create an if statement. It says if A1 is greater than one, then it says this is greater than one, and you can see that the value of this cell is in fact this is greater than one. I'm going to switch over to R Studio and I'm going to show you the equivalent of that. The first couple of things we have to do with R is bring in a read Excel library. I'm going to run that from line five. Then in line seven, I use the as.data.frame and read_excel function to import the sample spreadsheet you'll find in the example files. Now we're ready to set up an if-then statement in R. And in line 12, you can see how this is built. First of all, you start with if and then a parenthesis, then we're going to do a subset, which is the equivalent of A1, so…

Contents