6

Unlike rowMeans() and rowMedians(), which give us the calculated figure, mode(x) gives the storage mode of the data.

My Question - For the following data frame, how can I calculate row wise Mode?

Data:

    Item       A    B   C
    Book001    56   32  56
    Book002    95   95  20
    Book003    50   89  50
    Book004    6    65  40

I am reading my worksheet like this:

wk= loadWorkbook (".....xls")
df = readWorksheet (wk, Sheet="Sheet1", header=TRUE)
4
  • @TimBiegeleisen : I have referred that page already! I am looking forward to finding Row wise mode when reading the input as data Frames from Excel. Commented May 19, 2015 at 14:23
  • The answer given by @dimitris_ps is correct and is also very slim and efficient. Commented May 19, 2015 at 14:33
  • @dimitris_ps 's answer is actually better than that given in the duplicate. I hope it will be marked correct so other developers can use this as a reference. Commented May 19, 2015 at 14:36
  • 1
    @TimBiegeleisen, right, but the other is base R so they can "cohabit" ;-) Commented May 19, 2015 at 14:38

1 Answer 1

9

Try this

install.packages("modeest")
library(modeest)

apply(df[ ,2:length(df)], 1, mfv)
Sign up to request clarification or add additional context in comments.

3 Comments

Very nice. I never heard of this package before.
If you are looking for a "Base R" solution, then have a look at this SO post which answers a similar question.
@dimitris_ps : However, this doesn't work incase my data doesn't have a "frequently occurring term" . How can i solve such a case?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.