'Print variable names in csv using psych::describe()

I'm using R's psych package. When I use describe() as below to get descriptive statistics of variables, their names appeared in the console but do not appear in the exported csv file.
How can I get this column printed, so that I know which results belong to which variable.

library(psych)
descriptive2 <- describe(mtcars)
write.csv(descriptive2, "temp.csv")
r


Solution 1:[1]

Don't see any issue with your code other than the misspelling of write.csv. The variables are in the row names which are by default printed in the csv file.

library(psych)
write.csv(data.frame(describe(mtcars)),"temp.csv")

Alternative will be:

descriptive2 <- data.frame(describe(mtcars))
descriptive2$vars <- row.names(descriptive2)

Solution 2:[2]

Add the argument row.names = TRUE when exporting your csv file. As mentioned @Adam Quek, make sure to correct the function write.csv().

library(psych)
descriptive2<-describe(mtcars)
write.csv(descriptive2,"temp.csv", row.names = TRUE)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 benson23