Reputation: 609
I have a question about the extraction of multiple values from a data.frame in R.
I have a data.frame that looks like this:
language ID value
1 Dutch A1 6
2 Dutch A2 6
3 Dutch A3 6
4 Dutch A4 6
5 Dutch A5 6
6 Portuguese A1 6
7 Portuguese A2 1
8 Portuguese A3 6
9 Portuguese A4 10
10 Portuguese A5 6
11 Irish A4 6
12 Irish A1 1
13 Irish A2 6
14 Irish A3 6
15 Irish A5 6
I want to be able to select any set of columns which have a certain ID. For instance, I want to be able to select the columns which have ‘Dutch’ as their language, and ‘A1’, ‘A2’, and ‘A3’ and place them in a new data.frame. How can I do that?
Many thanks!
Upvotes: 1
Views: 4260
Reputation: 66834
Use subset
to subset your data:
subset(dfr, language=="Dutch" & ID %in% c("A1","A2","A3"))
Upvotes: 3