0

I have two vectors.

x <- c("a","b","c")
y <- c(NA, 1, NA)

I want to combine to get the following where x is the column heading:

  a  b   c
 NA  1  NA
phaser
  • 565
  • 1
  • 11
  • 28
  • Possible duplicate of [Creating a named list from two vectors (names, values)](https://stackoverflow.com/questions/17842705/creating-a-named-list-from-two-vectors-names-values) – Ronak Shah Nov 22 '17 at 06:21

1 Answers1

3

You can data frame the transpose of y and then use x to assign the column names.

df <- data.frame(t(y))
names(df) <- x

df
   a b  c
1 NA 1 NA

Demo

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360