r - How can I divide a dataframe on the basis of values in its columns? -


so, have dataframe this,

1 2 110 10  na  na 2 3 101 100 na  na 3 4 10  na  na  na 3 2 110 100 101 na ................. 

now, want divide dataframe individual files 110,10,101,100,10,101.. , each file contains first 2 columns present in it. example, file 110 contain,

1 2 3 2 

and file, 10 contain,

1 2 3 4 

like this, want divide it. know how divide on basis of column value, since file contains multiple columns, don't know how it? appreciated.

the code able make single column , create text files was,

x <- split(myfile, myfile[, 4])   invisible(lapply(names(x), function(y)    write.table(x[[y]], file = paste0(y, ".txt")))) 

make dataset in long rather wide form, split it:

vals <- apply(dat[3:6], 1, function(x) x[!is.na(x)] ) df <- cbind(dat[1:2][rep(rownames(dat), sapply(vals,length)),], val=unlist(vals)) split(df, intm$val)  #$`10` #    v1 v2 val #1.1  1  2  10 #3    3  4  10 # #$`100` #    v1 v2 val #2.1  2  3 100 #4.1  3  2 100 # #$`101` #    v1 v2 val #2    2  3 101 #4.2  3  2 101 #  #$`110` #  v1 v2 val #1  1  2 110 #4  3  2 110 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -