-2

Im new to coding with R and especially in time series. My problem is that I'd like to include a "Beep" column in a dataset. More specifically, in the dataset, there are 3 columns, ID, date and time like this

img1.

It would be really useful, next to these columns, to add a corresponding beep, since the individuals got many beeps during the day for some days. I'd like my final result to be something like this

img2.

How could I do that?

camille
  • 16,432
  • 18
  • 38
  • 60
  • 1
    [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. That includes a sample of data (not pictures of tables), all necessary code, and a clear explanation of what you're trying to do and what hasn't worked. – camille Feb 08 '20 at 20:20
  • It is really not clear what you want exactly. Adding a new column seems just too easy data$newcolumn = "bleep". Maybe try reading some tutorials first. – vanao veneri Feb 08 '20 at 22:59

1 Answers1

0
library(dplyr) # Load package dplyr

mydata <- mydata %>% # Take the dataframe, then...
  group_by(Name, Dates) %>% # Group it by name and dates, then...
  mutate(beep = row_number()) %>% # Add a beep column with a sequential number by name & date
  ungroup() # Remove grouping
Phil
  • 7,287
  • 3
  • 36
  • 66