我根据A列中的因子水平从数据框中列出了一个列表。在列表中,我想删除该列。我的头在说,不好意思,但没有其他:P
$A
ID Test
A 1
A 1
$B
ID Test
B 1
B 3
B 5
入这个
$A
Test
1
1
$B
Test
1
3
5
最佳答案
假设您的列表名为myList
,则应如下所示:
lapply(myList, function(x) { x["ID"] <- NULL; x })
更新资料
对于更通用的解决方案,您还可以使用以下方法:
# Sample data
myList <- list(A = data.frame(ID = c("A", "A"),
Test = c(1, 1),
Value = 1:2),
B = data.frame(ID = c("B", "B", "B"),
Test = c(1, 3, 5),
Value = 1:3))
# Keep just the "ID" and "Value" columns
lapply(myList, function(x) x[(names(x) %in% c("ID", "Value"))])
# Drop the "ID" and "Value" columns
lapply(myList, function(x) x[!(names(x) %in% c("ID", "Value"))])
关于r - 删除列表中数据框中的一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12664430/