我有许多数据可以打开,并假设它位于名为“CNV”的文件夹中。
我读过这个链接1:Opening all files in a folder, and applying a function,但我还是很困惑。
假设我有文件名a,b,c,d,e.在桌面中的文件夹CNV中z
在这些文件中有相同的列
Sample, start, stop, event, probe, length
qd1234, 2666, 2888, CN gain, 23, 235
cc234, 1000, 1500, CN loss, 5, 500我的问题是如何在打开所有这些文件之后一次打开所有文件。
我想选择探测数大于5,CN损耗探针数大于3,探针/长度小于30的CN增益。
预期结果:
a
Sample, start, stop, event, probe, length, length/probe
qd1234, 2666, 2888, CN gain, 23, 235, 9
qd1534, 1200, 1800, CN loss, 60, 600 10
b
Sample, start, stop, event, probe, length, length/probe
qd234, 2666, 2888, CN gain, 23, 235, 9
qd534, 1200, 1800, CN loss, 60, 600 10发布于 2013-08-09 10:07:46
我想你可能在找这样的东西。在创建crit时,我查看刚刚导入的data.frame的列,并查看哪些行符合指定的标准。在此基础上,我对完整的data.frame进行子集子集,并返回(函数返回最后一行)子集。
my.files <- list.files()
my.df <- sapply(my.files, function(x) {
read.in <- read.table(x, header = TRUE, sep = ",")
crit <- with(read.in, which(probe > 5 & probe > 3 & (probe/length) < 30))
read.in[crit, ]
}, simplify = FALSE)由于我们没有一个可重复的例子,我在下面演示这个子设置是如何工作的。
set.seed(357)
xy <- data.frame(x = 1:10, y = runif(10), z = rnorm(10))
xy # we expect row 6 to satisfy all the conditions
xy[with(xy, which(x > 5 & y < 0.5 & z < 0)), ]https://stackoverflow.com/questions/18140835
复制相似问题