Re: [R] merging dataframes in a list

2016-06-06 Thread MacQueen, Don
I would probably do it this way, tmp <- list(data.frame(name="sample1", red=20), data.frame(name="sample1", green=15), data.frame(name="sample2", red=10), data.frame(name="sample2", green=30)) fun1 <- function(df) data.frame(name=df$name, color=names(df)[2], va

Re: [R] merging dataframes in a list

2016-06-04 Thread jim holtman
Here is how you can to it with tidyr: > x <- list(data.frame(name="sample1", red=20) + , data.frame(name="sample1", green=15) + , data.frame(name="sample2", red=10) + , data.frame(name="sample2", green=30) + ) > library(dplyr) > library(tidyr) > > # convert to 'name, type, value';

Re: [R] merging dataframes in a list

2016-06-03 Thread Ed Siefker
Thanks, ldply got me a data frame straight away. But it filled empty spaces with NA and merge no longer works. > ldply(mylist) name red green 1 sample1 20NA 2 sample1 NA15 3 sample2 10NA 4 sample2 NA30 > mydf <- ldply(mylist) > merge(mydf[1,],mydf[2,]) [1] name red gre

Re: [R] merging dataframes in a list

2016-06-03 Thread ruipbarradas
Hello, Sorry, forget my first answer, I misunderstood what you wanted. Let's try again. First of all you have a typo in your second sample2, you wrote 'sample 2' with a space. Now try this. fun2 <- function(n){     merge(lst[[n]], lst[[n + 1]]) } N <- which(seq_along(lst) %% 2 == 1) lst2 <- l

Re: [R] merging dataframes in a list

2016-06-03 Thread Ulrik Stervbo
You can use ldply in the plyr package to bind all the data.frames together (a regular loop will also work). Afterwards you can summarise using ddply Hope this helps Ulrik Ed Siefker schrieb am Fr., 3. Juni 2016 21:10: > aggregate isn't really what I want. Maybe tapply? I still can't get > it

Re: [R] merging dataframes in a list

2016-06-03 Thread ruipbarradas
Hello, Maybe something like the following. lst <- list(data.frame(name="sample1", red=20), data.frame(name="sample1", green=15), data.frame(name="sample2", red=10), data.frame(name="sample 2", green=30)) fun <- function(DF){     data.frame(name = DF[, 1], color = colnames(DF)[2], colnum = DF

Re: [R] merging dataframes in a list

2016-06-03 Thread Ed Siefker
aggregate isn't really what I want. Maybe tapply? I still can't get it to work. > length(mylist) [1] 4 > length(names) [1] 4 > tapply(mylist, names, merge) Error in tapply(mylist, names, merge) : arguments must have same length I guess because a list isn't an atomic data type. What function wi

Re: [R] merging dataframes in a list

2016-06-03 Thread Ed Siefker
I manually constructed the list of sample names and tried the aggregate call I mentioned. Merge works when called manually, but not when using aggregate. > mylist <- list(data.frame(name="sample1", red=20), data.frame(name="sample1", > green=15), data.frame(name="sample2", red=10), data.frame(na

[R] merging dataframes in a list

2016-06-03 Thread Ed Siefker
I have a list of data as follows. > list(data.frame(name="sample1", red=20), data.frame(name="sample1", > green=15), data.frame(name="sample2", red=10), data.frame(name="sample 2", > green=30)) [[1]] name red 1 sample1 20 [[2]] name green 1 sample115 [[3]] name red 1 sample