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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:11:08+00:00 2026-05-31T05:11:08+00:00

So I have a list, each element of which is a numeric vector. Each

  • 0

So I have a list, each element of which is a numeric vector. Each number ranges from 0 to 1, and I am interested only in those which are greater than .95, but I must keep their position on the vector, and all the other numbers as I need to plot their positions relative to each other.

l1 = list(c(runif(20)),c(runif(21)),c(runif(22)),c(runif(19)))

so I tried to set all number below 0.95 equal to 0, using lapply like so:

l1 = lapply(l1, function(x){x[x<.95]=0})

but this just returns a list of an equal number of elements as the input list (as one would expect), but each element is simply zero.

so I tried it with a for loop like so:

for(i in 1:length(l1))
{
  l1[[i]][l1[[i]]<.95]=0
}

and that worked. Each element is the same length as the input vector, and contains only 0s and numbers greater that .95

Could someone explain why the lapply didn’t work. I’d prefer not to have to use a for loop, as I am led to believe they are slower, and the real data set I am working on is much larger.
As always,
all help is appreciated,
Cheers,
Davy

  • 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-31T05:11:08+00:00Added an answer on May 31, 2026 at 5:11 am

    Use lapply and ifelse:

    lapply(l1,function(x) ifelse(x<0.95,0,x))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of type A, in which each element contains another list
I have a List which I create from a DataTabe which only has one
I have a list of lists that looks like this: x[[state]][[year]] . Each element
OK, I have a list ( <ul> ) then inside each <li> element I
i have a list 1 column and 100 rows each with a number the
I have a list, each item of which has several things in it, including
I have a List of beans, each of which has a property which itself
I have got this problem: Find the first element in a list, for which
I have a list of elements around 1000. Each element (objects that i read
I have an android app, where in a list view for each element in

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.