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
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';
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
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
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
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
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
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
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
9 matches
Mail list logo