rdataframe

How to prevent row names when creating a data frame from a vector


What I do is like this:

vec <- setNames(c(3,2,1), c("a", "b", "c"))
df <- data.frame(my_var = vec)

print(df)

#Output
my_var
a      3
b      2
c      1

Is there a way to prevent the newly created data frame from inheriting names from the vector?


Solution

  • In addition to Ada's `unname()` you can

    data.frame(my_var = vec, row.names = NULL)
    
    data.frame(my_var = as.vector(vec))