Split a huge csv based on time intervals depending on inner text tags
What I did was to use the function
which(startsWith(df$treeID, "system sleep.")),
this retrieved me all the columns that started with this value.
Then using the function slice and the previous column I can cut the dataframe. However, I can only do it one by one (selecting with [1], [2], etc. the row and slicing the rest). So I am trying to build a loop now.
If you want more details send me a message.
Thank you.
I have a huge ".csv" file which corresponds to an one-day data file.
Every half-hour of the day, data was recorded during ten minutes. In the file, each half-hour is separated by a text tag, such as "zzzz" or "system sleep", depending on the .csv.
I would like to split the CSV breaking it into the 48 half-hour blocks, and save each half-hour .csv in a new foder that includes 48 smaller csv. files. I am sure there are ways to do this but I cannot find the way. Because each half-hour values do not have exactly the same number of rows, I cannot split this data according to row numbers.
The file will look something like the following (I made a shortened example):




ID
Day
Time
Rec
value




A1
2018/1/30
00:00
1
251


A1
2018/1/30
00:01
2
368


A1
2018/1/30
00:02
3
430


system sleep.






A1
2018/1/30
00:30
1
195


A1
2018/1/30
00:31
2
876


A1
2018/1/30
00:32
3
864


system sleep.






A1
2018/1/30
01:00
1
872


A1
2018/1/30
01:01
2
120


A1
2018/1/30
01:02
3
208


system sleep.






(...)
(...)
(...)
(...)
(...)


A1
2018/1/30
23:39
10
002




And so it goes for the whole day. Please note my actual data has up to 7000 values per half-hour*.
I would like to split it for each "system sleep" (or each time such text appears in the first column); and save the new .csv files in a new folder. Also, if possible, I would like to keep the header (first row) for all the half-hour blocks/new csv'. Ideally, I'd also like the file to be saved after the first time value/row of each block ("Time") -but I guess it would still work if it was saved as 1, 2, 3, 4.
Can anyone help me? I usually work with R language, but if it's easily done in another language such as python (I found many answers in python but not exaclty what I need), I wouldn't mind giving it a try eventhough I have no experience with it (but if I know R, it should be doable). Thank you very much..!