Last active
May 24, 2016 18:13
-
-
Save nharrell04/41f8df7645d7647a9d651f5382e2f518 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oztemp <- hw1_data[,hw1_data$Ozone > 31 && hw1_data$Temp > 90] ## hw1_data is the full data fram I'm working with | |
## I'm trying to get all of the rows where the value in the Ozone column is above 32 and the values in the Temp column are above 90 | |
## instead oztemp is a data frame w/ 0 columns and 153 rows (there are 153 rows in the data frame) |
Also note that cars in the 1920s were hella unsafe.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really close. I'll use the
cars
data set here because it comes standard in R.cars
has two columns, 'speed' and 'dist'. It's some dataset related to the speed and stopping distance of cars in the 1920s.If you're in R Studio you should be able to just type
cars
and see the data.Let's grab all data for cars going faster than 20mph:
Which gives us:
and we can grab all of the data we want for cars with a stopping distance of greater than 90ft:
Giving us a different vector of:
So now we want to know which entries have a TRUE value in both of the above lists. In your sample you used the
&&
operator but that only works on single values (I don't know why). (e.g.TRUE && FALSE == FALSE
). ToAND
two lists together use the single&
:Giving:
So now we've got a list of TRUE/FALSE values and we know that if we use this list as an index into the data, we'll get back all of the rows that correspond to TRUE:
Which gives us an error:
We need to specify which columns we want. We want all of them so we'll just add a
,
after our row indices:Giving us:
And that's it. If you prefer the non-
$
syntax, you could similarly do:And get
as well.