I have a dataset set called people which looks like this
Year Name Age Weight
1993 Dan 10 100
1994 Dan 11 120
1995 Dan 12 125
1993 Bob 10 96
1994 Bob 11 120
1995 Bob 12 113
I want to split this data set and then find corrlelations between age and weight using a function taking a persons name as the argument to the function. This code works...
splitpeople<- split(people, people$Name)
cor(splitpeople$Dan$Age,splitpeople$Dan$Weight)
But when I attempt to run a function like this...
peoplefunc <- function(names)
{
splitpeople <- split(people, people$Name)
cor(splitpeople$names$Age,splitpeople$names$Weight)
}
peoplefunc(Dan)
I get an error in the cor() line saying supply both x and y or a matrix
What is going wrong in this function?