This is a similiar question to this but my output results are different.
Take the data:
example <- data.frame(var1 = c(2,3,3,2,4,5),
var2 = c(2,3,5,4,2,5),
var3 = c(3,3,4,3,4,5))
Now I want to create example$Identity which take a value from 1:x for each unique var1 value
I have used
example$Identity <- apply(example[,1], 2, function(x)(unique(x)))
But I am not familiar with correct formatting function()
The output of example$Identity should be 1,2,2,1,3,4