Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you bind uneven columns?

I am trying to make a table containing the binded columns of two other tables. These two tables are of an uneven length. I would like to be able to bind them regardless and "fill" the length of the shorter column(s) with NAs, so these are effectively full joined on the row number.

When attempting to bind , I am receiving an error. For example:

a <- c("a", "b", "c")
b <- c(1, 2)

bind_cols(a, b)

"Error: Can't recycle `..1` (size 3) to match `..2` (size 2)."

My desired output is something like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  a  b
1 a  1
2 b  2
3 c NA

>Solution :

data.frame(lapply(m<-list(a = a, b = b), `length<-`, max(lengths(m))))
  a  b
1 a  1
2 b  2
3 c NA
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading