1

I am on Mac OS 10.10 with R 3.1.1

I have the following dataframe x which I am trying to get its descriptive statistics using describe from psych package (note that I Hmisc package which has the same describe function is detached for now)

set.seed(10)
x<-data.frame(a=seq(1:10),b=rnorm(10), c=rnorm(10))
x_des<-psych::describe(x)
x_des<-x_des[,-c(3,4,5)]

this code gives me the object x_dex which has a data.frame class.

If I load Hmisc package, the class of the object x_dex changes to describe if I used the same code like above.

Since I want the object to have a data.frame class to be able to write it into excel file, I have tried to use:

data.frame(x_des)

but it give the following error:

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
  cannot coerce class ""describe"" to a data.frame

Need to know why this happen when loading Hmisc package and any proper solution.

mallet
  • 2,454
  • 3
  • 37
  • 64
  • should use `as.data.frame`. and I assumed that `x_des(, -c(3,4,5))` is a typo because that is a syntax error. since `class(x_des)` is data.frame and describe, `as.data.frame` looks for a method for "descibe", doesn't find it, and you get an error. You can force `as.data.frame` to use the data frame method on x_des by `as.data.frame.data.frame(x_des)` and I get the expected result – rawr Mar 11 '15 at 13:40
  • @rawr I fixed the error in `x_des(, -c(3,4,5))`. I did use `as.data.frame.data.frame(x_des)` and it gave me the following error `Error in if (i > 1L) class(x) <- cl[-(1L:(i - 1L))] : missing value where TRUE/FALSE needed` – mallet Mar 11 '15 at 18:58
  • the S3 methods for describe objects from the Hmisc and psych package are conflicting. you could strip the classes from `x_des` as in `class(x_des) <- 'data.frame'` I'm not sure what the psych authors intended for the describe class--there don't seem to be any S3 methods for it. Hmisc, on the other hand, has a few methods. I think you could get away with changing the class unless you are using it down the line for some reason – rawr Mar 11 '15 at 19:36
  • As the author of psych, I will add that the describe class is used in the print psych function. Perhaps mistakenly, but routinely, I class the output of most psych functions as class(result) <- c("psych", "funtionname"). I do this to simplify the appropriate print and summary functions. – William Revelle Mar 12 '15 at 14:29
  • @rawr I ended up striping the class like you mentioned. Still thinking to limit my usage of Hmisc as an alternative. – mallet Mar 13 '15 at 10:12

0 Answers0