Reputation: 49
How do you write an IF statement with two conditions that will retrieve the corresponding value such as the name of the person who meets these condition's?
Here is my statement:
if(any((Basketball$TwoPoint >= 45) && (Basketball$ThreePoint >= 45)))
{
print(Basketball$Person == (Basketball$TwoPoint >= 45) && (Basketball$ThreePoint >= 45))
}
I know that I have 2 people who shoot better than 45 [%] from Two AND Three Point because this data frame only has 7 rows and 7 columns so I was able to verify this to be true.
Upvotes: 1
Views: 73
Reputation: 2750
Data frames are nice in that you can do it within a data frame.
df <- df[which(df$col1 == 'val1' & df$col2 == 'val2'),]
Would be a quick and easy way of doing it.
(Also if you want something a bit more elegant look into dplyr)
Upvotes: 2