Splitting rows into columns in R using tidyr -


i have dataset looks this-

                                                                              col1  1 atom      1  n   ile  12      67.611  47.640  52.312  1.00 12.44           n   2 atom      2  ca  ile  12      66.381  47.660  51.520  1.00 25.25           c   

it has single column called col1. want separate 12 columns i'm using following command-

try=separate(subset,col1,c("name","s.no","atom name","residue name","symbol","residue number","x-cor","y-cor","z-cor","uk1","uk2","symbol"), sep= " ") 

but keep on getting following error, not understand-

warning message: many values @ 3929 locations: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...

and gives me following output-

 name s.no atom name residue name symbol residue number x-cor y-cor z-cor uk1 uk2 symbol  1 atom                                                       1           n            ile  2 atom                                                       2          ca     ile      

any fixing highly appreciated. thanks!

there should more elegant solution tidyr. without library have

data.frame(do.call(rbind, unlist(apply(subset, 1, function(x) strsplit(x, "\\s+")),recursive=false))) 

logic

i assuming data set name subset. each row of data.frame split space(s), part strsplit(x, "\\s+")). rest have in data.frame.

update

just figured out, in code replace sep= " " sep= "\\s+". \\s+ states @ least on space, whereas " " 1 space.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -