r - Dataframe not being converted to a vector -


i'm trying convert dataframe vector. here's sample:

mydataframe <- data.frame(1:4,5:8,9:12)  #create data frame myvector <- as.vector(mydataframe) class(myvector)  #this not vector 

for type of dataframe, can use unlist creating vector includes names , unname(unlist()) remove names. such as:

mydataframe <- data.frame(1:4,5:8,9:12)  #create data frame myvector <- unname(unlist(mydataframe)) #create vector dataframe  myvector is.vector(myvector) 

unlist works in case because simplifies dataframe list structure while as.vector removes attributes. see andrew macdonald's data structure posts more information on why unlist preferred on as.vector


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -