[R] Transpose Data Frame Question
apjaworski@mmm.com
apjaworski at mmm.com
Wed Sep 17 19:49:00 CEST 2003
Here is a brute force way:
mm <- NULL
for(i in unique(ID)){
zz <- data.frame[ID==i, 3]
mm <- rbind(mm, c(i, zz))
}
It will work as long as you have the same number of tests for each ID. If
not, you would need to pad shorter zz vectors with NAs.
Cheers,
Andy
__________________________________
Andy Jaworski
Engineering Systems Technology Center
3M Center, 518-1-01
St. Paul, MN 55144-1000
-----
E-mail: apjaworski at mmm.com
Tel: (651) 733-6092
Fax: (651) 736-3122
|---------+-------------------------------->
| | Bruce Coate |
| | <coate111956 at yahoo.co|
| | m> |
| | Sent by: |
| | r-help-bounces at stat.m|
| | ath.ethz.ch |
| | |
| | |
| | 09/17/2003 12:30 |
| | |
|---------+-------------------------------->
>-----------------------------------------------------------------------------------------------------------------------------|
| |
| To: r-help at stat.math.ethz.ch |
| cc: |
| Subject: [R] Transpose Data Frame Question |
>-----------------------------------------------------------------------------------------------------------------------------|
Hi,
I have a data.frame that has 3 columns (ID, Test, Result) and looks like
this
1, Test1, 120
1, Test2, 34
2, Test1, 132
2, Test2, 28
etc
I would like to turn it around so that it looks like this
1, 120, 34
2, 132, 28
etc
I have played around some with t and reshape, but with no success.
Any suggestions or hints would be greatly appreciated.
Thanks,
Bruce
---------------------------------
[[alternative HTML version deleted]]
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list