Assuming that the data frame is called m, you can - split the data frame by the 
values of siteid and date- apply a function to create the new data frame for each such 
group and - use rbind to put it back together like this: fn <- function(x) { y 
<- t(x[,4:5]) data.frame( siteid=x[1,1], date=x[1,2], name=colnames(x)[4:5], 
x01=y[,1], x02=y[,2], x03=y[,3] )}m <- do.call( "rbind", 
lapply(split(m,list(m$siteid,m$date)),fn) )If the order matters then add this line: m 
<- m[ order(m$siteid,m$date), ]--- On Mon 09/29, < [EMAIL PROTECTED] > 
wrote:From: [mailto: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Mon, 29 Sep 2003 13:15:36 
-0400Subject: [R] Data frame transposeHi All,I want to ask if there is a transpose 
function for data frame like theprocedure of transpose in SAS? Because I want to 
partially transpose adata frame which contains 5 columns (siteid, date, time, obs, 
mod), whatI want to do is to put time as the column variables along with siteid,and 
date, and put obs and mod in the row names. specifically totranspose a data 
frame:siteid date time obs modA 7/8 01 2 5A 7/8 02 3 8A 7/8 03 5 8A 7/9 01 3 6A 7/9 02 
5 8A 7/9 03 6 7......B 7/8 01 4 7B 7/8 02 7 19B 7/8 03 4 9......Tositeid date name 01 
02 03 ....A 7/8 obs 2 3 5A 7/8 mod 5 8 8A 7/9 obs 3 5 6A 7/9 mod 6 8 7.......B 7/8 obs 
4 7 4B 7/8 mod 7 19 9........Thank you very [EMAIL PROTECTED] mailing 
listhttps://www.stat.math.ethz.ch/mailman/listinfo/r-help

_______________________________________________
No banners. No pop-ups. No kidding.
Introducing My Way - http://www.myway.com

        [[alternative HTML version deleted]]

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to