r - Merge Multiple Data Frames by Row Names -


i'm trying merge multiple data frames row names.

i know how two:

x = data.frame(a = c(1,2,3), row.names = letters[1:3]) y = data.frame(b = c(1,2,3), row.names = letters[1:3]) merge(x,y, = "row.names") 

but when try using reshape package's merge_all() i'm getting error.

z = data.frame(c = c(1,2,3), row.names = letters[1:3]) l = list(x,y,z) merge_all(l, = "row.names")  error in -ncol(df) : invalid argument unary operator 

what's best way this?

merging row.names weird things - creates column called row.names, makes subsequent merges hard.

to avoid issue can instead create column row names (which better idea anyway - row names limited , hard manipulate). 1 way of doing data given in op (not optimal way, more optimal , easier ways of dealing rectangular data recommend getting know data.table instead):

reduce(merge, lapply(l, function(x) data.frame(x, rn = row.names(x)))) 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -