apply rbind for all column of a data frame in r -


i have data frame :

a <- 1:5 b <- c("a","b","c","d","e") c <- c(15,49,41,29,7)  df1 <- data.frame(a,b,c) 

i want make single column doing r bind. doing :

x <- as.data.frame(df1$a) y <- as.data.frame(df1$b) z <- as.data.frame(df1$c)  colnames(x)[1] <- "x" colnames(y)[1] <- "x" colnames(z)[1] <- "x"  e <- rbind(x,y,z) 

but problem if number of column huge 50-60 difficult same. need help...

you can use unlist coerce vector, i.e. unlist(df1) have make sure don't have factor columns , keep in mind doing coercing numeric columns characters.

for example above, not work df1$b factor. have convert character first.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -