I’m trying to use the following code in R:
ID=seq(1,11)
g=c(1,2,3,1,1,2,3,4,4,1,3)
x <- sample(11)
d <- data.frame(ID,g, x)
Ranking_Categoria<-function(d,var,category)
{
d$rank<-ave(d$var,d$category,FUN=rank)
return(d)
}
and I get the following error message:
Error in split.default(x, g) : first argument must be a vector.
Variables var and category (character) are columns of the dataframe d that user needs to specify in order to get the desired result. I need to refer to this names when I use the function ave() as you can see.
You need to use
[[to get thevarandcategorycolumns by name:… because
d$vartries to get the column called “var”, and there is none.UPDATE