Data content - R [duplicate]

1

no R (rstudio)

I have a vector v1 <- c(543, 543, 543, 675, 675, 675, 675, 22, 22, 22, 90, 90, 87, 876, 867) .

I would like to get a vr vector that represents the count of v1 (increasing 1:n ) of the numbers that repeat.

In relation to the previous vector ( v1 ) for example: vr <- c(1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 1, 2, 1, 1, 2) .

Thanks in advance!

    
asked by anonymous 02.01.2018 / 17:05

1 answer

1

Just for registration, it's pretty easy to do this with the dplyr package (I know it's a date frame, since it does not work with vector).

library(dplyr)

v1 <- data.frame(num=c(543, 543, 543, 675, 675, 675, 675, 22, 22, 22, 90, 90, 87, 876, 867))
vr <- v1 %>%
  group_by(num) %>%
  summarise(repetido = n()) %>%
  arrange(repetido)
    
04.01.2018 / 17:05