Skip to content
Prev 343149 / 398513 Next

reshape a dataset

On Thu, 14 Aug 2014 06:08:51 PM Sohail Khan wrote:
52700
1 0
Hi Sohail,
You are doing a bit more than reshaping. This may get you there:

skdat<-read.table(text="A 92315
A 35018
A 56710
B 52700
B 92315
B 15135
C 35018
C 52700",stringsAsFactors=FALSE)
names(skdat)<-c("lettertag","ID")
ID<-unique(skdat$ID)
lettertags<-unique(skdat$lettertag)
newskdat<-list(ID)
for(i in 1:length(lettertags))
 newskdat[[i+1]]<-
  as.numeric(ID %in% skdat$ID[skdat$lettertag==lettertags[i]])
names(newskdat)<-c("ID",lettertags)

I'm assuming that you don't really want your answer as a single string.

Jim