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
Post a Comment