I have big .csv file. I would like to filter that file into a new table.
For example, I have .csv file as below:
f1 f2 f3 f4 f5 f6 f7 f9 f10 f1
sapply(1:nrow(dat), function(x) if (dat[x, "f1"]==1) {
write.csv( dat[ (dat[["f1"]]==1 )& (1:nrow(dat) >= x) , ])
} else {NULL} )
"","f1","f2","f3","f4","f5","f6","f7","f9","f10","f11"
"t1",1,0,1,0,1,0,0,0,0,1
"t2",1,0,0,0,0,1,1,1,1,1
"t4",1,0,0,0,1,0,0,0,0,0
"","f1","f2","f3","f4","f5","f6","f7","f9","f10","f11"
"t2",1,0,0,0,0,1,1,1,1,1
"t4",1,0,0,0,1,0,0,0,0,0
"","f1","f2","f3","f4","f5","f6","f7","f9","f10","f11"
"t4",1,0,0,0,1,0,0,0,0,0
[[1]]
NULL
Will need to construct file names:
invisible(
sapply(1:nrow(dat), function(x) if (dat[x, "f1"]==1) {
write.csv( dat[ (dat[["f1"]]==1 )& (1:nrow(dat) >= x) , ] ,
file = paste0("fil_", x, ".csv") )
} else {NULL} )
)
If this is destined for Excel, as I fear it might be, note that the rownames are included but no column header will be created to designate the rownames.