[R] conditional data replace (recode, change or whatsoever)
Justin
jtor14 at gmail.com
Wed Aug 3 17:43:25 CEST 2011
zcatav <zcatav <at> gmail.com> writes:
>
> Your suggestion works perfect as i pointed previous message. Now have another
> question about data editing. I try this code:
> X[X[,"c"]==1,"b"]<-X[,"d"]
> and results with error: `[<-.data.frame`(`*tmp*`, X[, "c"] == 1, "b", value
> = c(NA, :
> replacement has 9 rows, data has 2
>
is this equivalent and/or preferred to:
X$b[X$c==1]<-X$d[X$c==1] ??
I assume this goes back to the various indexing methods for a dataframe, an
object vector that is a column of a data frame vs. an object data frame that
happens to be one column of a larger data frame.
on a very large data set is one preferable for speed? one for memory use?
I tend to index using $ operators often and if I should quit let me know!!
Thanks,
Justin
> Logically i selected 2 rows with X[,"c"]==1. Than i want to replace in that
> rows its own data from "d" to "b" with X[,"b"]<-X[,"d"]. What is wrong?
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/conditional-data-replace-recode-change-or-whatsoever-tp3714715p3715218.html
> Sent from the R help mailing list archive at Nabble.com.
>
>
More information about the R-help
mailing list