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
How about the following, if you really want characters or just leave as
factor
i - round(runif(10, 1, 4))
years - as.character(factor(i, labels = c(Freshman, Sophomore,
Junior, Senior)))
HTH,
ken
__
R-help@stat.math.ethz.ch mailing list
Hi Ken,
Thanks for the help, but I should have mentioned that I want to do
this within a loop. Perhaps it would be better for me to explain my
exact situation.
I am running two loops so that I can calculate estimates for years
1,2,3,4 and a categorical GPA variable that takes on three values
On Fri, 7 Apr 2006, 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
On Fri, Apr 07, 2006 at 02:58:00AM -0400, Brian Quinif wrote:
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
On Fri, Apr 07, 2006 at 09:55:47AM +0200, Philipp Pagel wrote:
On Fri, Apr 07, 2006 at 02:58:00AM -0400, Brian Quinif wrote:
I tried this
years - Freshmen if i==1
years - Sophomores if i==2
What you are looking for is not an if clause but logical indexing:
years[years==Freshmen] - 1