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 6626743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:55:48+00:00 2026-05-25T21:55:48+00:00

I am sure I have a very basic question but I am frustrated after

  • 0

I am sure I have a very basic question but I am frustrated after searching for the idea on how to accomplish subsetting (getting row numbers) of some data frame/matrix which can have any number of columns and column names change all the time. I would like to find only rows (indexes) of the data frame for which any of the columns is greater than 0. Since column names and number of columns is unknown I do not know how to do this…

An example:

# these are the terms I am looking in
terms <- c("beats", "revs", "revenue", "earnings")
# dict <- Dictionary(terms)
# dictStudy <- inspect(DocumentTermMatrix(mydata.corpus.tmp, list(dictionary = dict)))

dictStudy <- data.frame(beats=c(0, 0, 0, 1, 0, 2), revs=c(0, 0, 0, 1, 0, 1), revenue=c(0, 0, 0, 0, 0, 0), earnings=c(1, 0, 0, 1, 0, 1)) 
ss <- expression(terms > 0)
dictStudy.matching <- subset(dictStudy, eval(ss))

I was hoping that expression and eval would save me, but I can not figure this out.

How to find only rows in a data frame that have any of the columns > 0?

  • 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-05-25T21:55:49+00:00Added an answer on May 25, 2026 at 9:55 pm

    I’m assuming you mean you want the rows where at least one element of that row is greater than zero (i.e. any of the columns are greater than zero).

    > which(apply(dictStudy,1,function(x) any(x > 0)))
    [1] 1 4 6
    

    As Tommy points out below, this assumes that all your columns are in fact numeric. You could sidestep this by subseting your data frame to pull out only those columns that are numeric:

    > which(apply(dictStudy[,sapply(dictStudy,is.numeric)],1,function(x) any(x > 0)))
    [1] 1 4 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize that this is probably a very basic question, but I have spent
Really basic question I'm sure for the normal Mac user but; I'm a very
I'm not sure if the title is very clear, but basically what I have
I'm sure this has been answered somewhere, because it's a very basic question -
here's a very basic question, that I'm sure you will be able to answer
I think this is almost certainly a very basic question but I'm struggling with
I'm a little new to asp.net mvc and I have a question (very basic).
This could be a very basic question but i want to confirm here. Im
I know this is a very basic question, but forgive me if I did
Am not sure if this question makes sense. But I know all the basic

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.