I'm trying to convert data.frame to matrix. I calculated some statistics for iris dataset and want every statistics to be placed in seperate row. Code below shows all statistics (avg and median) in one single row and that's not a desired output. I want sth like this:
stat Sepal.Lenght Sepal.Width ....
avg 10.5 .....
med ...... .....
Code below:
data_iris <- iris
avg <- data_iris %>%
summarise_at(vars(Sepal.Length:Petal.Width),mean,na.rm=TRUE)
med <- data_iris %>%
summarise_at(vars(Sepal.Length:Petal.Width),median,na.rm=TRUE)
column <- colnames(data_iris[1:4])
rown <- c("avg","median")
df <- data.frame(avg=avg,med=med)
m <- data.matrix(df)
And additional question: I'd like to calculate quantiles but error comes up:
qrtl <- data_iris %>%
summarise_at(vars(Sepal.Length:Petal.Width),quantile,na.rm=TRUE)
error: Column Sepal.Length
must be length 1 (a summary value), not 5
What's wrong?