从R中的数据帧列表中的意思 [英] Means from a list of data frames in R
问题描述
最终需要两个向量:
meanvector = c(mean(data frame(3)),mean(data frame(6) ),...,mean(数据帧(54)))
variancevector = c(var(data frame(3)),var(data frame(6)),...,var(data frame 54)))
这个问题超出了我的知识水平,但我想我可以做到这一点使用某种循环,但我不知道如何做这样的循环。任何帮助将不胜感激!谢谢你提前。
您可以使用 lapply
并传递索引如下:
ids< - seq(3,54,by = 3)
out< - do .call(rbind,lapply(ids,function(idx){
t < - unlist(x [[idx]] [,-1])$ b $ bc(mean(t),var(t)
}))
I am relatively new to R and have a complicated situation to solve. I have uploaded a list of over 1000 data frames into R and called this list x. What I want to do is take certain data frames and take the mean and variance of the entire data frames (excluding the first column of each) and save these into two separate vectors. For example I wish to take the mean and variance of every third data frame in the list starting from element (3) and going to element (54).
So what I ultimately want are two vectors:
meanvector=c(mean(data frame(3)), mean(data frame(6)),..., mean(data frame(54)))
variancevector=c(var(data frame (3)), var(data frame (6)), ..., var(data frame(54)))
This problem is way above my knowledge level but I am thinking I can do this effectively using some sort of loop but I do not know how to go about making such loop. Any help would be much appreciated! Thank you in advance.
You can use lapply
and pass indices as follows:
ids <- seq(3, 54, by=3)
out <- do.call(rbind, lapply(ids, function(idx) {
t <- unlist(x[[idx]][, -1])
c(mean(t), var(t))
}))
这篇关于从R中的数据帧列表中的意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!