One seldom write IF statements in R. (RStudio is "just" the IDE. R is the stats and graphics environment. There is almost always a better way to do it in R.
You need to explain to us, in substantive terms what you are trying to do.
Start out with a general statement of the project and what kind of analysis you are doing.
What do you want to do.
What is the final outcome of the analysis?
Do you have R code for other parts of your project? If so please supply it.
Also please supply some sample data in .csv or dput() format.
Here is some suggestions on creating an example. They may not be genneally applicable in this case but the instruction on supplying sample data are important (i.e. dput()) Blast it forgot the link.
It is important not to say how you want to do something but what you want to do. If you are used to Excel, you have just entered an alien universe.