[R] nchar on data.frames

David White dwhite at ling.ohio-state.edu
Thu Mar 29 03:19:02 CEST 2001


Ben mentions using
%data.frame(text=I(temp$text),numbers=temp$numbers))

to read in text and numeric data in data.frame. I have read the help pages
about this, but not understood what was meant by protecting text data with
I. Does this mean that any text entry beginning with "I" will be read as
character string data variable rather than a factor?

Many thanks!

d 

S. David White
sdavidwhite at bigfoot.com
Columbus, Ohio

On Wed, 28 Mar 2001 ben at zoo.ufl.edu wrote:

%
%   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
%
%
%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
%_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
%

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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