Problems with merge function

1

I'm having trouble with the merge function of nothingness, it stopped merging the data.frames.

It seems like instead of using say cbind , it is using rbind and what is worse triple echo (each = 3). For two data.frames of 40 lines, they result in a data.frame of 134 lines. (I know I probably do not use these functions but only to elucidate the behavior)

I've renamed the columns of both data.frames leaving only the column that would be used to "identify" the data. but it was still in vain.

My goal is to group two factorial scheme splits to present meaningful interaction by grouping the test response of averages.

I use the code like this: tab.final<-merge(tab1, tab2, by=c("means","means"))

tab1<-structure(list(Talhão = c("Abacate", "Abacate", "Abacate", "Abacate", 
"Abacate", "Banana", "Banana", "Banana", "Banana", "Banana", 
"Cacau", "Cacau", "Cacau", "Cacau", "Cacau", "Gliricidia", "Gliricidia", 
"Gliricidia", "Gliricidia", "Gliricidia", "Inga", "Inga", "Inga", 
"Inga", "Inga", "Manga", "Manga", "Manga", "Manga", "Manga", 
"Pupunha", "Pupunha", "Pupunha", "Pupunha", "Pupunha", "Seringueira", 
"Seringueira", "Seringueira", "Seringueira", "Seringueira"), 
    means = c(3.375, 2.875, 3.875, 3.125, 2.875, 3.125, 3.25, 
    2.875, 3.75, 3.625, 3.375, 4, 4, 2.125, 2.125, 3.625, 3.625, 
    3.625, 3.375, 2.125, 3.125, 2, 2, 2.125, 2, 3.875, 3.25, 
    2.875, 2.5, 2, 3.375, 3.375, 2.25, 2.375, 2.625, 2.125, 3.5, 
    3, 4, 3.75), let1 = c("A", "B", "A", "BC", "BC", "A", "AB", 
    "BC", "AB", "AB", "A", "A", "A", "D", "CD", "A", "AB", "AB", 
    "AB", "CD", "A", "C", "D", "D", "D", "A", "AB", "BC", "CD", 
    "D", "A", "AB", "CD", "CD", "CD", "B", "AB", "BC", "A", "A"
    ), Doses = c("0.001", "0.25", "0.5", "0.75", "1", "0.001", 
    "0.25", "0.5", "0.75", "1", "0.001", "0.25", "0.5", "0.75", 
    "1", "0.001", "0.25", "0.5", "0.75", "1", "0.001", "0.25", 
    "0.5", "0.75", "1", "0.001", "0.25", "0.5", "0.75", "1", 
    "0.001", "0.25", "0.5", "0.75", "1", "0.001", "0.25", "0.5", 
    "0.75", "1")), .Names = c("Talhão", "means", "let1", "Doses"
), row.names = c(NA, -40L), class = "data.frame")



 tab2<-structure(list(Doses = c("0.001", "0.001", "0.001", "0.001", 
"0.001", "0.001", "0.001", "0.001", "0.25", "0.25", "0.25", "0.25", 
"0.25", "0.25", "0.25", "0.25", "0.5", "0.5", "0.5", "0.5", "0.5", 
"0.5", "0.5", "0.5", "0.75", "0.75", "0.75", "0.75", "0.75", 
"0.75", "0.75", "0.75", "1", "1", "1", "1", "1", "1", "1", "1"
), means = c(3.375, 3.125, 3.375, 3.625, 3.125, 3.875, 3.375, 
2.125, 2.875, 3.25, 4, 3.625, 2, 3.25, 3.375, 3.5, 3.875, 2.875, 
4, 3.625, 2, 2.875, 2.25, 3, 3.125, 3.75, 2.125, 3.375, 2.125, 
2.5, 2.375, 4, 2.875, 3.625, 2.125, 2.125, 2, 2, 2.625, 3.75), 
    let2 = structure(c(2L, 2L, 1L, 1L, 1L, 1L, 1L, 5L, 3L, 2L, 
    1L, 1L, 3L, 2L, 1L, 2L, 1L, 3L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 
    1L, 3L, 1L, 3L, 4L, 3L, 1L, 3L, 2L, 3L, 3L, 3L, 5L, 2L, 2L
    ), .Label = c("a", "ab", "b", "bc", "c"), class = "factor"), 
    Talhão = c("Abacate", "Banana", "Cacau", "Gliricidia", "Inga", 
    "Manga", "Pupunha", "Seringueira", "Abacate", "Banana", "Cacau", 
    "Gliricidia", "Inga", "Manga", "Pupunha", "Seringueira", 
    "Abacate", "Banana", "Cacau", "Gliricidia", "Inga", "Manga", 
    "Pupunha", "Seringueira", "Abacate", "Banana", "Cacau", "Gliricidia", 
    "Inga", "Manga", "Pupunha", "Seringueira", "Abacate", "Banana", 
    "Cacau", "Gliricidia", "Inga", "Manga", "Pupunha", "Seringueira"
    )), .Names = c("Doses", "means", "let2", "Talhão"), row.names = c(NA, 
-40L), class = "data.frame")
    
asked by anonymous 13.02.2018 / 02:29

2 answers

1

I was able to solve using the rbind and cbind functions combined with the eval(parse(text=paste functions:

eval(parse(text=paste(c('tabela<-rbind(',rep("",(nv1*nv2)-1)),'cbind(tab1[tab1$Talhão=="',rep(lf1,each=nv2),'" & tab1$Doses=="',lf2,'",],tab2[tab2$Doses=="',lf2,'" & tab2$Talhão=="',rep(lf1,each=nv2),'",])',c(rep(",",(nv2*nv1)-1),")"),sep="")))

where: lf1<-levels(tab1$Talhão) ; nv1<-length(summary(tab1$Talhão)) lf2<-levels(tab2$Doses) ; nv2<-length(summary(tab2$Doses))

But I would like a simpler command to style merge(tab1, tab2, by=c("means","means"))

    
13.02.2018 / 15:22
0

If you used bind_rows of dplyr would not it get what you want?

tab.final <- bind_rows(tab1, tab2)

In this case you would have a% w / o of 80 lines.

If not, could you better elucidate where exactly you want to go?

    
20.02.2018 / 18:09