Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 重塑2:dcast tall为wide,不聚合_R_Reshape2 - Fatal编程技术网

R 重塑2:dcast tall为wide,不聚合

R 重塑2:dcast tall为wide,不聚合,r,reshape2,R,Reshape2,考虑 ext <- data.frame(cond = rep(c('a', 'b'), each = 2), dat = runif(4) ) ext您必须告诉dcast有一个识别行id: 例如: 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 <- data.frame(cond = rep(c('a', 'b'), each = 2), dat = runif(4) )

ext您必须告诉
dcast
有一个识别行id:

例如:

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
ext$id
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