I have a df with 3 columns:

* column\_1: numeric
* column\_2: numeric
* column\_3: factor variable with two groups, A and B

I want to compute a Spearman's correlation test between columns 1 and 2, but only between groups (so the correlation is computed only between observations of columns 1 and 2 which match group A, the same applying to group B).
So I'm using these lines of code:

```
cor.test(df$column_1, df$column_2, alternative = ("two.sided"), 
     subset(df, column_3==c("group_A")),
     data = df, method = c("spearm"))
cor.test(df$column_1, df$column_2, alternative = ("two.sided"), 
         subset(df, column_3==c("group_B")),
         data = df, method = c("spearm"))

```

Thing is, I get the same result in both tests, so I guess the subset function is not working, because if I previously subset the groups, like this:

```
x <- subset(df, column_3==c("group_A"))
y <- subset(df, column_3==c("group_B"))

```

And then run `cor.test` on x and y separately, I get different results. Does anybody know what's going on?

PS: I get the following warning, but I don't think it has to do with the issue I'm asking about:

```
Warning message:
"In cor.test.default(cor_itir$Nart, cor_itir$Medida, alternative = "two.sided",  :cannot compute exact p-value with ties"

```