2
I tried in many ways to apply the functions join
of package dplyr
in a list but I can’t do this. With the function Reduce
and merge
This is easy to do, but my intention is to do it with join
as this is a faster function.
With Reduce
and merge
the code looks like this:
newdata <- Reduce(function(x,y) merge(x, y, all = FALSE, by = 'row.names',
incomparables = NA, sort = FALSE),
mylist)
The goal would be to join the data.frames
of mylist
in a single database.
dput
(list) for aid in response:
mylist=structure(list(period1 = structure(list(sell =
c(954.82455776073,
510.810676729307, 744.75243431516, 740.655287634581, 993.685934110545,
866.834087180905, 523.575691389851, 764.874521177262,
817.054593935609,
518.385569332168, 531.494156224653, 843.328540329821,
795.584754319862,
938.056216109544, 710.636245436035, 997.307573445141,
869.842965039425,
771.45393146202, 823.295841924846, 601.494735921733), place =
structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L), .Label = c("a", "b"), class = "factor")), .Names =
c("sell",
"place"), row.names = c(NA, -20L), class = "data.frame"), period10 =
structure(list(
sell = c(733.160433010198, 965.176168596372, 773.615662241355,
871.220104396343, 850.882120081224, 548.022049595602,
621.362034813501,
814.990229788236, 549.271885422058, 695.817611529492,
881.452074856497,
993.035112507641, 771.279759705067, 992.838160018437,
774.461645982228,
517.854797886685, 637.189441244118, 623.788836062886,
780.715740052983,
712.462180759758), place = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("a", "b"), class = "factor")), .Names = c("sell",
"place"), row.names = c(NA, -20L), class = "data.frame"), period11 =
structure(list(
sell = c(533.743410953321, 773.384398664348, 872.096808976494,
842.97708561644, 666.135999024846, 693.793271319009, 863.513759453781,
539.360933355056, 997.354788240045, 752.822959562764,
671.030344441533,
731.102725607343, 580.205574864522, 667.002705973573,
630.402681184933,
899.911671527661, 872.772023198195, 543.33548923023, 682.689820649102,
778.205765294842), place = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("a", "b"), class = "factor")), .Names = c("sell",
"place"), row.names = c(NA, -20L), class = "data.frame"), period12 =
structure(list(
sell = c(947.833278682083, 588.600017828867, 992.308593471535,
763.031872571446, 809.284279122949, 798.120932886377,
645.494438474998,
773.96222949028, 880.193093093112, 681.19038187433, 962.226237053983,
865.827421075664, 837.468956946395, 975.754468236119,
643.590759718791,
701.593282399699, 717.885117628612, 986.66607378982, 866.434537689202,
718.550421763211), place = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("a", "b"), class = "factor")), .Names = c("sell",
"place"), row.names = c(NA, -20L), class = "data.frame")), .Names =
c("period1",
"period10", "period11", "period12"))
Consider by='rownames'
in function.
And, although mylist
has been data.frames
with equal numbers of lines, please consider that these have numbers different. This is why use cbind
recycle, that is, the repetition of initial elements of one vector to complete the other with larger number of lines.
You want to do
join
with what? Thejoin
is on the list or eachdata.frame
in the list? If only add the columns to the side (what is suggested by the use ofby = "rownames"
),cbind()
is not a more appropriate solution?– Tomás Barcellos
I edited the question. I beg your pardon if I was unclear.
– neves
For comparison purposes, could you share in the question the code you used to
Reduce()
andmerge()
?– Tomás Barcellos
I put the code in the question.
– neves