[R] manupulating a data frame column

Steven T.
Thu, 07 Jul 2005 20:00:44 -0000

Could someone tell me how to fix the following error? It looks like
that the reason is that df$x is of the class "factor". Thanks!

> x1<-LETTERS[1:8]; x2<-letters[1:8]; x1[2]<-NA; x1[4]<-NA;
> df<-data.frame(x1=x1, x2=x2)
> idx<-which(is.na(df$x1))
> df[idx,1]<-df[idx,2]
Warning message:
invalid factor level, NAs generated in: "[<-.factor"(`*tmp*`, iseq,
value = c(2, 4))
>