0

I have similar dataset like this

structure(list(id = c(1, 1, 1, 1), time1 = c(1682, 1682, 1683, 
1683)), class = "data.frame", row.names = c(NA, -4L))

and I want to create an extra column (column 2) where the maximum value (taken from time1 column) is repeated for the id column

structure(list(id = c(1, 1, 1, 1), time1 = c(1682, 1682, 1683, 
1683), time2 = c(1683, 1683, 1683, 1683)), class = "data.frame", row.names = c(NA, -4L))
Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
kamran khan
  • 311
  • 1
  • 7
  • It worked on my dummy df but on my original data I am getting error "error in unique.default(x, max = max) unique()applies only to vectors. – kamran khan Jul 06 '21 at 12:16
  • You might have factor columns in your original data instead of numeric. Check `str(df)`. convert factor to numeric https://stackoverflow.com/questions/3418128/how-to-convert-a-factor-to-integer-numeric-without-loss-of-information and then use the answer. – Ronak Shah Jul 06 '21 at 12:30

0 Answers0