Hello,
I'd like to transpose data to create an analysis-friendly dataframe. See
below for an example, I was unable to use t(x) and I couldn't find a
function with options like PROC TRANSPOSE in SAS.
The ideal solution handles variable quantities of SITE - but beggars can't
be choosers. :-)
Thank you in advance,
Mike
## INPUT DATA
USER_ID<-c(1,1,1,2,2,2,3,3,4)
SITE
<-c("SITE1","SITE2","SITE3","SITE1","SITE2","SITE3","SITE1","SITE2","SITE3")
COUNTS <-c(10,13,22,10,12,12,13,44,99)
RAW<-data.frame(USER_ID,SITE,COUNTS)
RAW
#ANSWER SHOULD LOOK LIKE
a<-c(1,2,3,4)
b<-c(10,10,13,0)
c<-c(13,12,44,0)
d<-c(22,12,0,99)
RESULT<-data.frame(a,b,c,d)
names(RESULT)<-c("USER_ID","SITE1","SITE2","SITE3")
RESULT
--
Michael Schumacher
[email protected]
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.