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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:11:39+00:00 2026-06-12T04:11:39+00:00

I have a problem with my loop. It just delete some rows that have

  • 0

I have a problem with my loop. It just delete some rows that have 0 or NA values in my desire column and I don’t know why:

for (i in 1:105) {
  for (j in 1:l[i+1]){
    if(m[[i]][j,12]==0 | is.na(m[[i]][j,12])) {
      m[[i]]=m[[i]][-j,]
    } 
  }
}

Searching on the web I saw that maybe I could use apply function… something like:

for( i in 1:105){m[[i]]<-m[[i]][!apply(is.na(m[[i]]), 1, any),]}

for( i in 1:105){
  as.null(0)
  m[[i]]<-m[[i]][!apply(is.null(m[[i]]), 1, any),] 
}

This throws me a dim(x) error… I want to set Zero number as NULL

I was thinking something as follows but clearly it isn’t good… it just the idea…. I really don’t know how to use apply function well

for( i in 1:105){as.null(0) m[[i]]<-!apply(m[[i]],1,is.null(m[[i]])) }

Thanks a lot for your useful help !

  • 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-12T04:11:40+00:00Added an answer on June 12, 2026 at 4:11 am

    You use apply to apply a function over a margin of an array, but I think is not the best idea here, since you only need to subset the matrix properly. Let’s focus in just one matrix m.

    ind = m[,12] == 0 | is.na(m[,12])
    

    ind will have TRUE where appropiate and the you can do

    m = m[!ind, ] # m is a matrix, not the list
    

    to remove the rows. You can put this inside the loop, or use lapply (to apply a function over a list), but first you need a function to be applied to every element in the list (all your 105 matrix), so

    removeRows = function(m) {
    ind = m[,12] == 0 | is.na(m[,12])
    m   = m[!ind, ]
    return(m)
    }
    
    m = lapply(m, FUN=removeRows)
    

    That should work.

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

Sidebar

Related Questions

I have a simple problem regarding a loop in a Rails controller. Here's the
I have a problem with a continue statement in my C# Foreach loop. I
I have an interesting problem. I wrote the following perl script to recursively loop
I have some problems with controlling a while loop inside an event structure. Say
Hi here is my problem. I have a program that calulcates the averages of
Can anyone please help. I have a problem where I need to loop through
I have a problem I cannot solve. Of course here I just expect to
I have a problem that seems like its a result of a deadlock-situation. Whe
I have a problem fetching values from a MySQL cursor. I create a temporary
I have some code for you guru's to check. I know this is probably

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.