本文介绍了在数据框列表上使用lapply的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个称为列表"的数据框列表,并希望仅选择列表中每个数据集的某些列.

I created a list of dataframes called "list" and want to select only certain columns of every dataset in the list.

library(dplyr)
new_list <- lapply(list, select(list, Date))

它返回一个错误,因为class(list [1])不是数据帧,而是列表. class(list [[1]])是数据帧.我不明白,因为列表中的元素应该是数据帧,而且我也不知道如何使用"lapply".

It returns an error because class(list[1]) is not dataframe but still a list. class(list[[1]]) is dataframe. I don't understand that because the elements in my list should be dataframes and I also don't know how I can use "lapply" anyway.

感谢您的帮助!

推荐答案

我认为您的语法略有不足.尝试改用匿名函数:

I think your syntax is just a little off. Try using an anonymous function instead:

l <- list(mtcars,mtcars)
lapply(l,function(x) select(x,cyl,mpg))

这篇关于在数据框列表上使用lapply的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:45