[R] simple if statement

Brian Quinif bquinif at gmail.com
Fri Apr 7 08:58:00 CEST 2006

I am ashamed to be asking this question, but I couldn't find the
solution anywhere.  Searching for "if" and "R" is not very

I cannot get a simple if statement to work.

I have data on college students.  I want to make a string variable
that has the names of the years.  That is, when the year variable i is
equal to 1, I want to have a variable called years equal to

I tried this
years <- "Freshmen" if i==1
years <- "Sophomores" if i==2

and so on, but I couldn't get it to work.  How can I get this variable to work?



More information about the R-help mailing list