[R] nchar on data.frames
ben@zoo.ufl.edu
ben at zoo.ufl.edu
Thu Mar 29 00:58:17 CEST 2001
Your character vector got turned into a factor (see ?data.frame). One
way to track this kind of problem down is with the str() function.
For "read.table" there is an "as.is" parameter that will prevent this
happening, but it looks like for data.frame you have to do something like
data.frame(text=I(temp$text),numbers=temp$numbers))
On Wed, 28 Mar 2001, David L. Tabb wrote:
> I don't understand why nchar() gives different string lengths for vectors
> in a list than it does for vectors in a dataframe. Here's a snippet of
> code:
>
> > temp <- list(text=c("thug","jimbob","apple","thug"),numbers=1:4)
> > nchar(temp$text)
> [1] 4 6 5 4
> > temp <- data.frame(temp)
> > nchar(temp$text)
> [1] 1 1 1 1
>
> Could someone explain how I can get the former behavior for a text vector
> in a data.frame?
>
> Thanks! RPM reports I'm using R-base-1.2.1-2.
>
> Dave
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
318 Carr Hall bolker at zoo.ufl.edu
Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker
Box 118525 (ph) 352-392-5697
Gainesville, FL 32611-8525 (fax) 352-392-3704
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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