r - How can I make a list of data frames which have the same values in the first column? -
say have multiple data frames, , want make multiple lists of data frames same first column. example, dfs 1-4 have "abc" in columns of first row, dfs 5-7 have "def" in columns of first row, etc. how can write script puts (in case) dfs 1-4 in list called "abc", dfs 5-7 in list called "def"?
this first question, please let me know if there else provide. researched few days no luck :(
thanks!
jack
so guide solution, asked.
first make sure have list of data frames called
l
(all(sapply(l, is.data.frame))
shouldtrue
).then, each element (
df
) of list, need character (string) in first row (in column, example first one). give vector of characters , can using eithersapply
orpurrr::map_chr
.after that, here comes split want do. use
split
first argument vectors of indices (see?seq_along
) , second argument vector of characters you've computed before.finally, use
lapply
transform list of indices in list of data frames (you need know[
accessor list).
if need more guidance, don't hesitate ask.
Comments
Post a Comment