Hi,

this could be a simple question but I am looking into modifying a data frame
using a "condition" without the need to loop over that data, would that be
possible?

I have tried the following
x<-c(4,5,6,6,8)
y<-c("a","b","b","b","c")
data<-data.frame(x,y)
data
  x y
1 4 a
2 5 b
3 6 b
4 6 b
5 8 c
 if (data$x==6){
data$x<-66
}
Warning message:
In if (data$x == 6) { :
  the condition has length > 1 and only the first element will be used

data[which(data$x == 6), 'x'] <- 66
should be what you want.

I woul dlike to change the 6 in column x into 66
why the above did not work?

Best,
Leon

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to