[R] String in data frame

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Apr 16 08:22:50 CEST 2005


Please read `An Introduction to R': R does not have `strings' or 
`namelists' whereas it does have `lists' but d$num is not one.

To communicate, you need a common language with your readers.  You are not 
speaking R, and your `examples' are not R output.

I suspect d$num is a numeric vector and d$name is a factor.  Please look 
up those concepts and the help for c(), noting that `NA' is a logical 
vector.  In particular you need to understand

      The default method combines its arguments to form a vector. All
      arguments are coerced to a common type which is the type of the
      returned value.


On Fri, 15 Apr 2005, Cuichang Zhao wrote:

> hello,
> how can take the string in the data frame.
> right now i have a table that create as a data frame and stored in the file called "data.xls" and now i want to read data frame as a table in my another r program, i used the following command:
> the first column of the data frame is just one number called "num", but the second one a list of string, called "name".
>
> d <- read.table("data.xls", header = T);
>
> what i get for d is a table of 2 columns: num and name:
>
> the one for d$num is just a normal list without any levels with it, and this is what i want. but the second d$name is a list with a levels with it.
> the list i have for d$name is: d$name = (bal bal bal bal bal bal), levlels:bal, however, when i want to have for following code, something different happens:
> namelist <- NA;
> a <- d$name[1]; #this will outputs a = bal, lelvels:bal
> namelist <- c(namelist, a); #this does not outptu (NA, bal), instead it outputs (NA, 1), if i keep #adding a to the namelist, it keeps adding 1 to the namelist instead of bal. However, i want to add bal to the namelist, not 1, so how i can do this?

> 	[[alternative HTML version deleted]]

> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

PLEASE do as we ask (and not sent HTML mail).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list