Hank
Hank

Reputation: 80

how to write specific rows and columns in a file by R?

I have a model that calculates hourly disease severity for 3000 hours and writes them in a csv file ( 3000 rows and eight columns). In addition to such output, I also want to have a file with just specific rows (here hours) and the same number of columns. In other words, I want a file that only writes the results in row(hour) 10, 20, 30, 40, 50, 100, 120 and 150 ( or any other desired row number)? I would be grateful if someone helps me how to do it in R.

Thanks

Upvotes: 1

Views: 10064

Answers (1)

Kvasir EnDevenir
Kvasir EnDevenir

Reputation: 927

In R you can select rows/columns directly: 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")

Upvotes: 2

Related Questions