我有一个非常具体的数据集,但相当不方便,如下所示:
data <- textConnection("rs1050,15,234323,C,T
1,7329,0.1147,-0.0024,0.0048
1,9810,0.6399,0.001174,0.006095
1,16550,0.648541108,0.0061,0.0070
rs7895,NA,NA,A,C
1,997,NA,NA,0.0732
1,9810,0.0339,-0.016131,0.021611
1,16550,0.32739678,0.0014,0.0053
rs995,18,100336,C,T
1,7385,0.2692,-0.0063,0.0035
1,9810,0.5397,-0.002697,0.006012
1,16550,0.651147483,-0.0045,0.0053")
test_data <- read.csv(data, header = FALSE, sep = ",")
如果包含rs####
包含的行NA
(在一列或多列中),则需要将其删除。这本身没有问题,但在这种情况下,该行下方的三行也需要删除(无论这些行中是否存在所有数据)。
因此,在上述数据的情况下,将删除第 5-8 行。
任何解决方案都会很棒,但到目前为止我的努力都是基于 sed。像这样的东西?
sed -i '/rs*\t*\tNA\tNA\t*/~1-3d' test_data
sed -i '/rs*\t*\tNA\tNA\t*/,+3d' test_data
我觉得我很接近,任何想法将不胜感激!