如何通过R在文件中写入特定的行和列?

时间:2015-03-18 22:51:44

标签: r

我有一个模型,可以计算3000小时的每小时疾病严重程度,并将它们写入csv文件(3000行和8列)。除了这样的输出,我还想要一个只有特定行(这里是几小时)和相同列数的文件。换句话说,我想要一个只在行(小时)10,20,30,40,50,100,120和150(或任何其他所需的行号)中写入结果的文件?如果有人帮我在R中做到这一点,我将不胜感激。

由于

1 个答案:

答案 0 :(得分:2)

在R中,您可以直接选择行/列:for tableX

tableX[Row,Column]

#Select all columns and only the rows you want:
export <- tableX[c("10","20","30","40","50","100","120","150"),]

#To select the first 8 columns as well:
export <- tableX[c("10","20","30","40","50","100","120","150"),1:8]

#Then export:
write.csv2(export, file= "disease.csv")