[R] If condition using accessors

Vitória Magalhães Piai V.Piai at psych.ru.nl
Fri Nov 27 11:34:03 CET 2009


I'm quite new using R and have got no one to help me get through it. 
Hopefully someone can help me with one problem I've been struggling with 
for the last hours!!
(Sorry if I'm using the wrong terminology as well!)

I have a data matrix in which SIE is one of my variables. What I need to 
do now is to create a new variable (group) if a certain condition in SIE 
is met.
I tried:

if (data2$SIE < 50.646){
which gives me "In if (data2$SIE < 50.646) { :  the condition has length 
 > 1 and only the first element will be used"

ifelse (data2$SIE < 50.64593, data2$group = 
as.factor("small"),data2$group = as.factor("large"))
with "Error: unexpected '=' in "ifelse (data2$SIE < 50.64593, data2$group ="

I tried all other kinds of variations and so far, nothing!!

Is there a good way to do this that someone could teach me?
Thank you so much,

More information about the R-help mailing list