[R] Setting Values of Elements in a Dataframe

Lorenzo Isella lorenzo.isella at gmail.com
Mon Nov 29 16:56:41 CET 2010


Dear All,
I am experiencing some problems in resetting the values of some selected 
elements in a dataframe.

Consider


d<-seq(-1,1,length=16)
dim(d)<-c(4,4)
d<-as.data.frame(d)

sel_pos<-which(d>0, arr.ind=TRUE)

d[sel_pos]<- -9

which returns the error

Error in `[<-.data.frame`(`*tmp*`, sel_pos, value = -9) :
   only logical matrix subscripts are allowed in replacement

which is obscure to me. I am correctly selecting the positive elements 
in a data.frame and I'd like to reset them to another numerical value.
What I am misunderstanding?
Many thanks

Lorenzo



More information about the R-help mailing list