2015-07-28 80 views
1

我有一个数据帧列表(列表9)。R:从列表中提取一个值并将其粘贴到数据帧中

> str(list9) 
List of 2 
$ :'data.frame': 64 obs. of 11 variables: 
..$ list$Stimulus   : Factor w/ 7 levels "108.wav","42.wav",..: 1 1 1 1 1 1 1 1 2 2 ... 
..$ list$IndicationStandard: num [1:64] 1 0 1 0 1 0 0 0 0 0 ... 
..$ list$P42    : num [1:64] 0 0 0 0 0 0 0 0 0 0 ... 
..$ list$P53    : num [1:64] 0 0 0 0 0 0 0 0 0 0 ... 
..$ list$P64    : num [1:64] 0.375 0.375 0.375 0.375 0.375 0.375 0.375 0.375 0.375 0.375 ... 
..$ list$P75    : num [1:64] 0.812 0.812 0.812 0.812 0.812 ... 
..$ list$P86    : num [1:64] 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 ... 
..$ list$P97    : num [1:64] 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 ... 
..$ list$P108    : num [1:64] 0.375 0.375 0.375 0.375 0.375 0.375 0.375 0.375 0.375 0.375 ... 
..$ list$TGdispInd1  : num [1:64] 0.317 0.317 0.317 0.317 0.317 ... 
..$ list$TGdispInd2  : num [1:64] 0.756 0.756 0.756 0.756 0.756 ... 
$ :'data.frame': 64 obs. of 11 variables: 
..$ list$Stimulus   : Factor w/ 7 levels "108.wav","42.wav",..: 1 1 1 1 1 1 1 1 2 2 ... 
..$ list$IndicationStandard: num [1:64] 0 0 1 0 1 0 0 0 0 0 ... 
..$ list$P42    : num [1:64] 0 0 0 0 0 0 0 0 0 0 ... 
..$ list$P53    : num [1:64] 0 0 0 0 0 0 0 0 0 0 ... 
..$ list$P64    : num [1:64] 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 ... 
..$ list$P75    : num [1:64] 0.812 0.812 0.812 0.812 0.812 ... 
..$ list$P86    : num [1:64] 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 0.75 ... 
..$ list$P97    : num [1:64] 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 ... 
..$ list$P108    : num [1:64] 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25 ... 
..$ list$TGdispInd1  : num [1:64] 0.351 0.351 0.351 0.351 0.351 ... 
..$ list$TGdispInd2  : num [1:64] 0.784 0.784 0.784 0.784 0.784 ... 

我创建了一个目标的数据帧(结果)

> str(result) 
'data.frame': 2 obs. of 3 variables: 
$ TGdispInd1: num 0 0 
$ TGdispInd2: num 0 0 
$ subject : chr "TG_75ms_Step11_V1-998-1.txt" "TG_75ms_Step11_V1-999-1.txt" 

我想列表中的每个数据帧的列表$ TGdispInd1和列表$ TGdispInd2的第一值粘贴到数据帧“结果”(也可能是列表$ TGdispInd1和列表$ TGdispInd2的均值,因为所有64个值都相等)。

这是得到的数据帧应该怎么看起来像

> result 
    TGdispInd1 TGdispInd2      subject 
1  .317  .756 TG_75ms_Step11_v1-998-1.txt 
2  .351  .784 TG_75ms_Step11_v1-999-1.txt 

是否有人知道如何做到这一点?

+1

它完美,谢谢! – piptoma

回答

1

尝试

result[1:2] <- do.call(rbind,lapply(list9, function(x) 
       x[1, c('list$TGdispInd1', 'list$TGdispInd2'])) 

如果你有兴趣在mean

result[1:2] <- do.call(rbind, lapply(list9, function(x) 
       colMeans(x[c('list$TGdispInd1', 'list$TGdispInd2']))) 
相关问题