2

I have this sequence of data and I want to create an ID every 3 rows:

x <- c ("info","x1","y1","z1","x2","y2","z2")
df  <- read.csv(text = x , strip.white = TRUE)

The actual strings doesn't have any logical information that I could create an ID column using mutate + ifelse + grepl . I want to create a new column with a sequential number every 3 rows:

id  info
 1    x1
 1    y1
 1    z1
 2    x2
 2    y2
 2    z2
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
jvqp
  • 239
  • 3
  • 14

0 Answers0