Hi, I have a problem in which i am having trouble vectorizing a snippet of my code to avoid a for loop. A basic example of what I'm trying to do is below. #simple example of problem x = c(1,1,3,3,6,7,8,8,9) # I create a vector that contains the unique values of x y = unique(x) y = c(1,3,6,7,8,9) #### Now I want to create a vector, say z, in which has the same length of y, but counts how many repetitions occurred for x. ## I want z = c(2,2,1,1,2,1) ## The only way I've been able to think about this problem is in terms of a for/while loop to generate z. I'm having trouble thinking on this one. If someone could help me out, I would greatly appreciate this. Carlos
trying to get rid of for loop in simple scenario
2 messages · Juancarlos Laguardia, Jorge Ivan Velez
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090302/bb424067/attachment-0002.pl>