[R] character vectors in data.frames
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Fri Jan 8 15:52:31 CET 1999
Lorenz Gygax <lgygax at access.unizh.ch> writes:
> Dear all,
>
> well, today I just seem to run into these problems ... (I am still working
> on R 0.63.1 on a SuSE 5.2). I would like to have a data.frame that also
> contains character (and NOT factor) vectors. Two things that I tried (the
> second worked in R 0.62.2):
>
> > test.df <- data.frame (X= character (4))
> > test.df$X [1] <- "a"
> Warning: invalid factor level, NAs generated
>
Use I(). Like this:
> test.df <- data.frame (X= I(character (4)))
> test.df$X [1] <- "a"
> test.df
X
1 a
2
3
4
> test.df$X
[1] "a" "" "" ""
attr(,"class")
[1] "AsIs"
And yes, the behaviour that data.frame converts character to factor
unless requested otherwise is weird, but Splus compatible.
--
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