[R] if else statements in data frame

helin_susam helin.susam at gmail.com
Sun Apr 17 00:09:21 CEST 2011


Hi ozgrerg,

I am not a "good" R user, but according to me you can do this;

data <- data.frame(x=c("A","A","B","A"), y=c("A","B","B","B"))
for (i in 1:nrow(data)){
if(data$x[i]=="B"||data$y[i]=="B") z[i]=c("B")
else
z[i]=c("NA")
}

cbind(data,z)

--
View this message in context: http://r.789695.n4.nabble.com/if-else-statements-in-data-frame-tp3454646p3454704.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list