Try this way
i <- 1
if (i==1) {years <- "Freshmen"}
if (i==1) {years <- "Sophomores"}
it should work!
Brian Quinif wrote:
> I am ashamed to be asking this question, but I couldn't find the
> solution anywhere. Searching for "if" and "R" is not
very
> productive...
>
> 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
> "Freshmen".
>
> 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?
>
> Thanks,
>
> BQ
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
>
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Ennio D. Isaia
~ Dep. of Statistics & Applied Mathematics, University of Torino
~ Piazza Arbarello, 8 - 10122 Torino (Italy)
~ Phone: +39 011 670 57 29 ~~ Fax: +39 011 670 57 83
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~