I know the c function is a generic function which combines its arguments. The problem that I encountered is about the c function with more than 2 characters in r. The question and example as below:
Step 1: I create a data frame with 2 columns Region and Salary.
> x<-data.frame(Region=c("a","b","c","c","a","b"),Salary=c(11:16))
> x
Region Salary
1 a 11
2 b 12
3 c 13
4 c 14
5 a 15
6 b 16
Step 2: I can get the correct answer when I chose one region(EX:a or b or c).
> x[x$Region=="a",]
Region Salary
1 a 11
5 a 15
> x[x$Region=="c",]
Region Salary
3 c 13
4 c 14
Step 3: If I choose the multiple region (EX:(a,b),(a,c),(b,c),(a,b,c)), the result would be unpredictable.
x[x$Region==c("a","c"),]
Region Salary
1 a 11
4 c 14
5 a 15
Question: I thought the c function is "combine" its arguments. So the result of x[x$Region==c("a","c"),]
would be the same as the result of x[x$Region=="a" | x$Region=="c",]
. But it turns out only show the row 1,4,5...Where is row 3??
What does x[x$Region==c("a","c"),]
mean??
Thanks for your time