如何使用 apply 排除列

问题描述 投票:0回答:1

我想排除/复制列表中列表中多个数据帧的行/列。 该代码还不能运行。也许这里有人知道该怎么做。

Zelllysate_extr <- list()

#defining the list

Zelllysate_extr$X0809P3_extr <- X0809P3_extr

#defining the list within the list

X0809P3_extr = lapply(Zelllysate_colr[["X0809P3"]], function(x) {
  as.data.frame(x) <- Zelllysate_colr[["X0809P3_colr"]][2:1500, 1 & 3:4]
  return(x)
}) 

#defining the list for the dataframes to place in; 2:1500, 1 & 3:4 are the rows and columns to copy

谢谢

r list multiple-columns lapply
1个回答
0
投票

不要尝试迭代列表,而是迭代列表的length

X0809P3_extr = lapply(1: length(Zelllysate_colr[["X0809P3"]]), function(x) {
  Zelllysate_colr[["X0809P3_colr"]][[x]][2:1500, c(1, 3:4)]
}) 

您不需要

return
或将值设置为等于
lapply
中的值。

我假设

Zelllysate_colr[["X0809P3"]]
是列表
Zelllysate_colr
中的列表。

大多数时候,

dput(head(dataObject))
的输出就足够了,但我认为您正在使用列表的列表,因此可能不足以查看结构。

© www.soinside.com 2019 - 2024. All rights reserved.