@Gopalkrishna Palem
I like your decision! However, I think you should use combn (v, 2) instead of combn (length (v), 2). combn (length (v), 2) iterate over indices v only
> v <- c(3,4,6,7)
> combn(v, 2)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 3 3 3 4 4 6
[2,] 4 6 7 6 7 7
> combn(length(v), 2)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 1 1 2 2 3
[2,] 2 3 4 3 4 4
> a_ply(combn(v, 2), 2, function(x) print(paste(x[1],"--",x[2])) )
[1] "3 -- 4"
[1] "3 -- 6"
[1] "3 -- 7"
[1] "4 -- 6"
[1] "4 -- 7"
[1] "6 -- 7"
> a_ply(combn(length(v), 2), 2, function(x) print(paste(x[1],"--",x[2])) )
[1] "1 -- 2"
[1] "1 -- 3"
[1] "1 -- 4"
[1] "2 -- 3"
[1] "2 -- 4"
[1] "3 -- 4"
so the end result is true with combn (v, 2).
Then, if we have a data frame, we can use indexes to apply the function to pairwise strings:
> df
x y
1 4 8
2 5 9
3 6 10
4 7 11
a_ply(combn(nrow(df), 2), 2, function(x) print(df[x[1],] - df[x[2],]))
x y
1 -1 -1
x y
1 -2 -2
x y
1 -3 -3
x y
2 -1 -1
x y
2 -2 -2
x y
3 -1 -1
However, a_ply will cancel the result, so how can I save the output in a vector for further analysis? I don't want to just print the result