-1

I am trying to do some data analysis on a dataset which among other things has a column for month (recorded as "jan",..., "dec") and day of the week ("mon",...,"fri"). I have two questions. My first question is how can I get the mode of these variables using the mfv function in the modeest package. I have a feeling this has something to do with type of variable I need to make it (factor, character etc.). I would rather not recode the data into a numeric variable.

If I make the variables factors I can get a plot by going plot(data$month), but now my plot is in alphabetical order and not temporal order, how can I change this?

Thanks!

mnel
  • 113,303
  • 27
  • 265
  • 254
LoveMeow
  • 1,141
  • 2
  • 15
  • 26
  • To the person who silently downvoted: This is the [summer of love](http://blog.stackoverflow.com/2012/07/kicking-off-the-summer-of-love/), so I suggest you do one of a few things 1) Explain why the downvote, 2) Explain to the OP how to improve the question 3) Edit the question so it is a good question. – Andrie Jul 26 '12 at 07:01

1 Answers1

2

If I make the variables factors I can get a plot by going plot(data$month), but now my plot is in alphabetical order and not temporal order, how can I change this?

In regards to that one, the trick is to make a new factor which is the same as the old one, but with the levels in a different order:

data$month <- factor(data$month, levels=tolower(month.abb))

Regarding the use of mfv. ?mfv clearly states

This function returns the most frequent value(s) in a given numerical vector

However coerce a factor to numeric within the function call

mfv(as.numeric(data$month))
mnel
  • 113,303
  • 27
  • 265
  • 254
sebastian-c
  • 15,057
  • 3
  • 47
  • 93