Tuesday 15 March 2011

data.frame - Combining data frames into specific lists in R -



data.frame - Combining data frames into specific lists in R -

i have 2 data.frames:

data.frame.i <- data.frame(mean.sw.i,mean.rep.i,sd.sw.i,sd.rep.i,n.sw.i,n.rep.i) data.frame.c <- data.frame(mean.sw.c,mean.rep.c,sd.sw.c,sd.rep.c,n.sw.c,n.rep.c)

and i'm trying combined them, means, sd, , n-values in same respective columns (means, sd, n), if came data.frame.i label "i" in additional column (called "group" say) , same info came data.frame.c. i'm asking how combine data.frames?!

any help appreciated! community best :)

it's not clear want result, please provide reproducible illustration , desired result.

you can set info frames list, iterate through them lapply create names consistent, , utilize rbind bring them together.

here's little illustration of that:

(df1 <- data.frame(x.i = 1, y.i = 2)) # x.i y.i # 1 1 2 (df2 <- data.frame(x.c = 3, y.c = 4)) # x.c y.c # 1 3 4 do.call(rbind, lapply(list(df1, df2), function(x) { setnames(x, sub("[.](.*)", "", names(x))) })) # x y # 1 1 2 # 2 3 4

r data.frame combinations

No comments:

Post a Comment