Skip to content
Prev 343151 / 398513 Next

reshape a dataset

Dear Sohail,

Using Jim's data set skdat, two more options would be

# first option
d <- with(skdat, table(ID, lettertag))
names <- colnames(d)
d <- c(list(rownames(d)), lapply(1:ncol(d), function(i) as.numeric(d[,i])))
names(d) <- c('ID', names)
d

# second option
d <- with(skdat, table(ID, lettertag))
res <- c(list(rownames(d)), sapply(apply(d, 2, list), "[", 1))
names(res)[1] <- "ID"
res

HTH,
Jorge.-
On Fri, Aug 15, 2014 at 7:19 PM, Jim Lemon <jim at bitwrit.com.au> wrote: