Selection from matrix based on values ​​of two different variables

Suppose I have a matrix with the values ​​of the response variable as one column and 2 characteristics such as Gender and location, as the other two columns.

How to choose specific response values ​​based on specific values ​​of both gender and location?

For example, I know

dataset $ response [gender == "Male"]

will choose all the men. But I will say that I want to select response values ​​from males that are from location == 'SE'. I do not know how to do that.

Thank you so much!

ps (I tried looking for it on the Internet, but it’s hard to find help for the operator [])

+3
source share
2 answers

Logical 'and':

dataset$response[dataset$gender=="Male" & dataset$location=="SE"] 

R help("&").

+5

dataset - , subset:

subset( dataset, gender == 'Male' & location == 'SE' )$response
+3

Source: https://habr.com/ru/post/1789867/


All Articles