[R] assigning to data frames with whole columns of NAs
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Sat Nov 25 12:35:23 CET 2000
David Firth <david.firth at nuffield.oxford.ac.uk> writes:
> > emptyframe<-data.frame(a=c(NA,NA),b=c(NA,NA))
> > emptyframe
> a b
> 1 NA NA
> 2 NA NA
> > emptyframe[1,]<-c(1,2)
> Warning messages:
> 1: invalid factor level, NAs generated in: [<-.factor(*tmp*, iseq, value = vjj)
> 2: invalid factor level, NAs generated in: [<-.factor(*tmp*, iseq, value = vjj)
Problem, what problem?
> emptyframe
a b
1 NA NA
2 NA NA
> emptyframe[1,]<-c(1,2)
> emptyframe
a b
1 1 2
2 NA NA
OK, I'm pulling your leg. The snag is that NA is logical NA, unless
something coerces it to something else, and when constructing data
frames, logical vectors are coerced to factors. So I had defined:
> emptyframe<-data.frame(a=as.numeric(c(NA,NA)),b=as.numeric(c(NA,NA)))
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list