[R] character -> list

Liaw, Andy andy_liaw at merck.com
Fri Mar 19 00:58:46 CET 2004


Use as.data.frame() on the matrix.

HTH,
Andy

> From: David Andel
> 
> Hi
> 
> I have a matrix of type "character" (strangly) and am trying to apply 
> the function "aggregate" to it, but unfortunately without success.
> It seems to me that aggregate would work, if I only could get 
> rid of the 
> quotation marks around each item.
> 
> So for a very simple example which looks as my actual data look (of 
> course here I put the quotation marks on purpose, but I have no idea 
> where they come from in my actual data):
> 
>  > x <- matrix(c("a","b","1","a","c","3","b","b","2"), nr=3, byrow=T, 
> dimnames=list(1:3, c("type","group","value")))
>  > x
>    type group value
> 1 "a"  "b"   "1"
> 2 "a"  "c"   "3"
> 3 "b"  "b"   "2"
> 
> I can't access the columns the way I think would be necessary for 
> aggregate to work:
>  > x$type
> NULL
> 
> And this seems to be the problem:
>  > typeof(x)
> [1] "character"
> 
> I think I would need to have type "list" to be able to apply 
> "aggregate".
> 
> How can I accomplish this?
> 
> Thanks,
> David
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 


------------------------------------------------------------------------------Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message.  If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.




More information about the R-help mailing list