I have 10 large data files (CSV files) with the same format as given below. I want to write a for loop assign a value (1, 2, 3, 4, etc) for each row of each data file, store that in a separate column of each data file, and save each file as a CSV. Assuming the first file have 100 rows, when we read the second file it should start at 101 and so on. The format of all the files are same and looks like the below.
SessionEnd <- c("22/06/2022 0:01", "22/06/2022 0:09", "22/06/2022 0:09", "22/06/2022 0:10", "22/06/2022 0:14")
Animal_ID <- c("ID1", "ID2", "ID3", "ID8", "ID25")
df <- data.frame(SessionEnd, Animal_ID)
The output should look like this.
File 1
SessionEnd | Animal_ID | Session_No |
---|---|---|
22/06/2022 0:01 | ID1 | 01 |
22/06/2022 0:09 | ID2 | 02 |
22/06/2022 0:09 | ID3 | 03 |
22/06/2022 0:10 | ID8 | 04 |
22/06/2022 0:14 | ID25 | 05 |
File 2
SessionEnd | Animal_ID | Session_No |
---|---|---|
23/06/2022 0:12 | ID7 | 06 |
25/06/2022 0:09 | ID9 | 07 |
23/06/2022 0:18 | ID8 | 08 |
29/06/2022 0:25 | ID5 | 09 |
28/06/2022 0:40 | ID25 | 10 |
How I supposed to do this in R?