I've managed to make different combinations of 2 from a set of data so that I get the pairs of names within the data set. I would like to have a function when I use mapply
so that I can use each name in each pair to reference their corresponding datasets. Right now I have:
myPairs <- combn(names(iris[1:4]), 2)
f <- function(x,y)
{
#Want to make a lm(x ~ y) and other potential calculations
}
a <- myPairs[1,]
b <- myPairs[2,]
mapply(f, a, b)
In other words, I want to calculate it like so:
data <- iris
attach(data)
lm(Sepal.Length ~ Sepal.Width)
lm(Sepal.Length ~ Petal.Length)
lm(Sepal.Length ~ Petal.Width)
lm(Sepal.Width ~ Petal.Length)
lm(Petal.Length ~ Petal.Width)
but using the names from the combn as reference to the dataset