0

My sheet 3 (s3) has 25 columns and my sheet 4 (s4) has two columns. I would like to merge my 2 columns from sheet 4 on the right side of the 25 columns in sheet 3 so that I end up with 27 columns on sheet 3. I need to do this in r. Also, my sheet 4 has 58 rows while my sheet 3 has 163 rows. When I run s3, the error I get is: "Error in [<-.data.frame(tmp, , 26, value = c("AUD/CZK", "AUD/HUF", : replacement has 57 rows, data has 162|". I tried something but it didn't work:

library(openxlsx)
s3 <- readWorkbook('I inserted file path here', sheet = 3)
s4 <- readWorkbook('I inserted file path here', sheet = 4)
s3[ ,26] <- s4[ ,1]
s3[ ,26]
s3[ ,27] <- s4[ ,2]
s3    
    
  • 2
    You are looking for either `dplyr::left_join` or `dplyr::full_join` – GuedesBF Nov 01 '21 at 16:06
  • Unfortunately, I still don't get it. When I try dplyr::full_join(s3,s4, by = character()), my result ends up having around 9200 rows. I don't have any common column between the two sheets and I only need 163 rows. –  Nov 01 '21 at 16:28
  • @GuedesBF and others, what should my "by" value be in the join function in dplyr if I don't have any common columns? –  Nov 01 '21 at 16:48
  • 1
    Ok, now i see you probably need to look into this: https://stackoverflow.com/questions/3699405/how-to-cbind-or-rbind-different-lengths-vectors-without-repeating-the-elements-o – GuedesBF Nov 01 '21 at 16:51
  • Thanks, it works now :) –  Nov 01 '21 at 17:29

0 Answers0