[R] Apologies : question on transforming a table
Joachim de Lezardiere
joachim.lezard at gmail.com
Thu May 6 21:38:46 CEST 2010
Can you explain more about the output you want ?
Thank you
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Min-Han Tan
Sent: Thursday, May 06, 2010 2:28 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Apologies : question on transforming a table
Dear R-help list,
Apologies. I am trying to convert one table to another. It feels that it
should be a very straightforward answer with a single (or two) commands with
the right extensions, but I really can't figure this out right now. I have
several hundred pheno factors actually, so manually doing this line by line
is not an option.
My original table is approximately like this :
ID pheno
1 A Breast Cancer
2 A Appendicitis
3 A Microcephaly
4 B Polyps
5 B Autism
6 C Autism
7 D Breast Cancer
8 D Polyps
9 D Appendicitis
10 E Breast Cancer
What I want is this :
ID Breast Cancer Appendicitis Microcephaly Polyps Autism A 1 1 1 B 1
1 C 1 D 1 1 E 1
The data is here
data <-
data.frame(ID=c(rep("A",3),rep("B",2),rep("C",1),rep("D",3),rep("E",1)),
pheno=c("Breast
Cancer","Appendicitis","Microcephaly","Polyps","Autism","Autism","Breast
Cancer","Polyps","Appendicitis","Breast Cancer"))
Thank you very much! Many apologies.
Min-Han
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list