Means from a list of data frames in R

后端 未结 2 615
梦毁少年i
梦毁少年i 2020-12-18 16:29

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

相关标签:
2条回答
  • 2020-12-18 16:38

    If x is a list of 1000 dataframes, you can use lapply to return the means and variances of a subset of this list.

    ix = seq(1, 1000, 3)
    lapply(x[ix], function(df){
        #exclude the first column
        c(mean(df[,-1]), var(df[,-1]))
    })
    
    0 讨论(0)
  • 2020-12-18 16:42

    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))
    }))
    
    0 讨论(0)
提交回复
热议问题