0

I have a list of 689 data.frame name DF. Each data.frame have a different name and many columns. For this question, just the columns $AGE is interesting.

The first thing a want to do is find the max of the $AGE columns for each data.frame. Whit this code it’s ok a can find the max for each data.frame

AV<- sapply(DF, function(x) max(x$AGE, na.rm=TRUE))

It’s after this code I don’t know what to do. So first, I have to scenario possible to TEST if the scenarios are true or false

  1. If the max is <150, 60% of my value (of the columns df$AGE) is in a interval of +or – 70 of the max (interval = max-70,max+70)

  2. If the max is >150, 60% of my value (of the columns df$AGE) is in a interval of +or – 40 of the max (interval = max-40,max+40)

For all data.frame that for one of the scenario the result is TRUE, I want to keep the result somewhere. If it’s FALSE,I want to go to scenario 3 and 4 that the same thing of 1 and 2 but with less value. I’m a little loss especially whit how to work whit a list of data.frame

Thank

  • You could explain the scenarios a little better with possibly an example? – Joseph Wood Dec 07 '17 at 16:36
  • i edit my my question but i can do example because i dont know how to do that –  Dec 07 '17 at 16:44
  • 1
    Don't worry about your list yet. Focus on a single data frame. Write a function that does your test performs the correct actions for a single data frame, returning the result you want to keep. Then, when that is done, you just run `lapply(DF, your_function)`. – Gregor Thomas Dec 07 '17 at 17:13
  • 1
    For an example, [here is a nice guide on how to make a reproducible example in R](https://stackoverflow.com/q/5963269/903061). Either simulate a *little bit* of data, or `dput()` a *little bit* of example data. In this case, I would say 2 example data frames, one that meets condition 1, and one that doesn't, would be appropriate. Maybe with 5-10 sample rows each. – Gregor Thomas Dec 07 '17 at 17:15
  • Thank but what a d'ont understand is how to do my condition. With if...else statement ? or something like that : if (max<150 & 60% og my value is in a interval of + or - 30 of the max) ? –  Dec 08 '17 at 13:06

0 Answers0