Reputation: 3
Hi this is probably very simple but I am new to R and would really appreciate some help. Basically I have this command:
length(days_to_death[which(days_to_death<100)])
I would like to make a list of each of the results when each time its run I add 100 to the <100 up until it is <1000. Basically I would like to simplify this:
c(length(days_to_death[which(days_to_death<100)]),length(days_to_death[which(days_to_death<200)])...<1000)
Thank you so much for your help!
Upvotes: 0
Views: 46
Reputation: 1716
You want an sapply
to loop over these values and seq
to create that list of values. Then we can simplify your length call as well, since it is actually just a sum.
sapply(seq(100,1000,by=100), function(i) sum(days_to_death < i))
Upvotes: 3