1

R newbie here. I have tried most solutions on SO but they haven't worked for me. This is a sample from my dataframe:

l   m    n                                    o     p    q             r m.mean
1  2011-04-11T07:08:39+00:00 229 NULL 64a1a092-7e85-4744-b266-4396aab12259 FALSE NULL Visa ****9999     NA
2  2005-11-02T11:32:56+00:00 351 NULL e6e7f646-685a-4385-8d9f-630f48166513 FALSE NULL Visa ****9999     NA
3  2010-10-10T07:12:25+00:00  28 NULL 6110c469-e49f-4c2a-8fca-acb03026adad FALSE NULL Visa ****9999     NA

I am trying to use colMeans(ts1[,"m"]) but it returns

Error in colMeans(ts1[, "m"]) : 
  'x' must be an array of at least two dimensions

How do I fetch the column mean in this case?

I have tried creating a list out of the column and then fetching its mean but that approach hasn't worked either.

Also, doing str(dataframe) reveals all values in the "m" column are num

UPDATE 1

  1. Doing colMeans(ts1[,"m"],drop=FALSE) results in error

    Error in colMeans(ts1[, "m"], drop = FALSE) : unused argument (drop = FALSE)

  2. Doing mean(ts[,"m"]) results in error

    Warning message: In mean.default(ts[, "m"]) : argument is not numeric or logical: returning NA

kurious
  • 1,024
  • 10
  • 29
  • 2
    The reason is that you are subsetting a single column into a `vector` and `colMeans` work on `data.frame/matrix` Try `colMeans(ts1[, "m", drop = FALSE])` BTW for single column, just do `mean(ts1[, "m"]`) – akrun Jun 19 '17 at 05:33
  • Tried those commands but see different errors. Wonder if my dataframe is not set up correctly. – kurious Jun 19 '17 at 11:36
  • See here for taking the average of a vector of dates: https://stackoverflow.com/questions/26587243/calculating-mean-date-by-row – Russ Hyde Jun 19 '17 at 11:44

0 Answers0