vasili111
vasili111

Reputation: 6930

How to create a tibble with one column and column name from a vector?

I tried to do it but it creates a tibble with two columns.:

>vect<-c(1,2,3)
> enframe(vect1, name="var")
# A tibble: 3 x 2
    var value
  <int> <dbl>
1     1     1
2     2     2
3     3     3

I need to create tibble like this:

    var 
  <int> 
       1    
       2    
       3  

Upvotes: 1

Views: 510

Answers (1)

akrun
akrun

Reputation: 887108

We can use select after the enframe (if the enframe is already done)

library(tidyverse)
enframe(vect, name="var") %>%
       select(var)

Or just use tibble

tibble(var = vect)
# A tibble: 3 x 1
#    var
#  <dbl>
#1     1
#2     2
#3     3

Upvotes: 3

Related Questions