Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find Specific Dates Within a Data Set Where data is less than?

I have the following dataset in R.

> jan_weather
        X HighTemp WindSpeed Snowfall WindChill
1   1-Jan       19         8      0.0       9.0
2   2-Jan       23        11      0.2      12.0
3   3-Jan       25         9      0.0      15.7
4   4-Jan       33        14      7.6      23.2
5   5-Jan       38         7      0.0      32.7
6   6-Jan       34         6      2.1      28.6
7   7-Jan       35        12      0.0      26.6
8   8-Jan       27        15      0.0      15.2
9   9-Jan       28        11      3.3      18.2
10 10-Jan       30        17      1.4      18.3
11 11-Jan       36        13      0.0      27.4
12 12-Jan       44         9      0.0      39.0
13 13-Jan       41         8      0.0      35.8
14 14-Jan       34        14      0.0      24.5
15 15-Jan       31        15      0.0      20.3
16 16-Jan       32        12      2.8      22.8
17 17-Jan       35        18      0.0      24.5
18 18-Jan       20        22      0.0       3.6
19 19-Jan       17        24      0.0      -1.1
20 20-Jan       16        20      0.6      -1.0
21 21-Jan       19         8      0.0       9.0
22 22-Jan       25         9      0.0      15.7
23 23-Jan       28        13     14.9      17.3
24 24-Jan       23        11      0.0      12.0
25 25-Jan       28        32      0.0      11.7
26 26-Jan       33        13      0.0      23.6
27 27-Jan       31        15      3.7      20.3
28 28-Jan       39        10      0.0      32.4
29 29-Jan       36         4      0.0      32.7
30 30-Jan       33         8      0.9      26.1
31 31-Jan       37        10      0.0      29.9

I would like to find the dates where for which the wind chill value is no less than 22 degrees Fahrenheit, combined with for which the wind speed is also no greater than 13 miles per hour. I figure this is a simple if statement and storing the return in a variable, but I seem to be having problems on how to set it up. Any advice?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

We could use filter from dplyr:

library(dplyr)

df %>% 
  filter(WindChill > 22 & WindSpeed < 13)

or Base R:

subset(df, WindChill > 22 & WindSpeed < 13)
        X HighTemp WindSpeed Snowfall WindChill
5   5-Jan       38         7      0.0      32.7
6   6-Jan       34         6      2.1      28.6
7   7-Jan       35        12      0.0      26.6
12 12-Jan       44         9      0.0      39.0
13 13-Jan       41         8      0.0      35.8
16 16-Jan       32        12      2.8      22.8
28 28-Jan       39        10      0.0      32.4
29 29-Jan       36         4      0.0      32.7
30 30-Jan       33         8      0.9      26.1
31 31-Jan       37        10      0.0      29.9
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading