【发布时间】:2021-08-31 12:45:15
【问题描述】:
我正在尝试删除所有存在的值都大于 -1 的列(例如:-0.45 或 0.45)。但是,如果至少有一行的值等于或小于 -1(例如:-1.14),我想保留这些列。
我尝试了以下方法,但在数据表中出现错误:
i evaluates to a logical vector length 17645 but there are 24 rows. Recycling of logical i is no longer allowed as it hides more bugs than is worth the rare convenience. Explicitly use rep(...,length=.N) if you really need to recycle.
原始DF(示例)
Cell Gene1 Gene2 Gene3 Gene4 Gene5
Cell1 0.02 -1.100.2 0.002 -1.772.1 -0.0884
Cell2 0.19 -1.098.0 0.068 -1.837.0 0.0685
Cell3 0.13 -1.328.7 -1.580 -1.687.6 0.2554
Cell4 -0.032 -1.245.3 0.004 -1.528.4 -0.2037
所需的 DF(示例)
Cell Gene2 Gene3 Gene4
Cell1 -1.100.2 0.002 -1.772.1
Cell2 -1.098.0 0.068 -1.837.0
Cell3 -1.328.7 -1.580 -1.687.6
Cell4 -1.245.3 0.004 -1.528.4
过滤值的命令
desired_df <- original_df[sapply(original_df, function(x) max(x) <= -1)]
【问题讨论】: