Re: [R] String in data frame

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat 16 Apr 2005 - 16:22:50 EST

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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Apr 16 16:29:46 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:12 EST