Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Consider
ext <- data.frame(cond = rep(c('a', 'b'), each = 2), dat = runif(4) )
I want
exw <- unstack(ext, dat ~ cond)
But I would like to do it with dcast() in reshape2 (for pedagogical purposes). Is this possible?
dcast()
reshape2
你必须告诉dcast有一个识别行ID:
dcast
例如:
dcast(ext, 1:2~cond) 1:2 a b 1 1 0.5706567 0.4360110 2 2 0.0305229 0.7032459
而且,更一般地说:
ext$id <- sequence(rle(as.character(ext$cond))$lengths) dcast(ext, id~cond, value.var="dat") id a b 1 1 0.5706567 0.4360110 2 2 0.0305229 0.7032459