Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8350359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:17:34+00:00 2026-06-09T08:17:34+00:00

I have this chunk of code in an R script, and what it does

  • 0

I have this chunk of code in an R script, and what it does is that from a data frame (that has say 4 columns) finds and counts for each row the column with the maximal value. But when in a row there are ties (say two or maybe three max values), the code below just considers the first one (does not count the other ones). Is there in R any way to count the columns with max value even when there are multiple max values (ties?) in rows.

m_0 <- read.csv(file="Tests/myResults", head=FALSE, sep=",")

varb_m0 <- c(m0$ V4)

#create dataframe

myDataFrame <- data.frame(mode_0=varb_m0)

#find max
result <- apply(myDataFrame,1,which.max)

#factor it
result <- factor(result)

#print result
names(myDataFrame)[result]

summary(result)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:17:37+00:00Added an answer on June 9, 2026 at 8:17 am

    A simple way to do it would be to make a function first:

    all_max <- function(x) {which(x == max(x))}  #Index of each value that is maximum.
    

    And then just apply that to your data frame:

    result <- apply(myDataFrame,1,all_max)
    

    I think the rest should be the same, though you didn’t provide any data to test it on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this chunk of javascript that's kind of hacked around from http://www.developphp.com/view.php?tid=1248 and
If I have a chunk of code like this: .hover( function () { hoverState($(#navbar
I have written a chunk of code that is aimed at reordering pages. <form
I have this chunk of code which I found and implemented according to http://www.activexperts.com/activmonitor/windowsmanagement/scripts/networking/windowsfirewall/
We have a chunk of code something like this // semi-pseudo code def result
I have a script that attaches actions to some objects in my HTML code.
I have this string containing a large chunk of html and am trying to
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I have this function // add history paths and save data function AddPath( strTag,
I have a Ruby script that I built in TextMate and can successfully run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.