Is there a convenient way to create a data frame from a vector and using the values of the vector as column names? Result should only have 1 row with empty fields. Values in vector may vary.
Given:
x <- c("1","2","3")
Output:
# A tibble: 1 x 3
`1` `2` `3`
<chr> <chr> <chr>
1 "" "" ""
>Solution :
If you’re a tidyverse fan as I see by your using of tibble, you could use a combination of map_dfc and setNames:
library(tidyverse)
df <- x %>% map_dfc(setNames, object = list(character(1)))
df
# A tibble: 1 x 3 `1` `2` `3` <chr> <chr> <chr> 1 "" "" ""