I have some data, let's say the mtcars dataset in R , and I want to export the describe function output to a csv file in a good format.
For the describe function output , we can use:
install.packages(Hmisc)
library(Hmisc)
mt_data = mtcars
x = describe(mt_data)
Tried to write to CSV file1:
write.csv(x, file="names22.csv",row.names = F)
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ""describe"" to a data.frame
Attempt2
data = mtcars
x = describe(data)
write.csv(t(as.matrix(x)), file="name2.csv")
But the above command is giving the output in a very weird format.
Expected output
x1 x2 x3 x4
mpg 12 23 758 23
cyl 2 23 23 64
disp 2 31 32 53
xyz 4 21 32 23
skjf 8 21 23 23
The above format is what I'm trying to achieve to write in a csv file.