I am trying to create a column in a dataset that will indicate what week the data in a row was collected. I have come partway to a solution using the following code:
This produces the column I want, however, it numbers the weeks by the week of the year, starting at 49, rather than just a cumulative number of weeks starting at 1. I'm attempting to just subtract the week by the minimum value in the "week" column and adding 1, but it doesn't seem to work.
#Creates the Date_time column
target_detections_all_15E$Date_time <- as.POSIXct(paste(as.Date(as.character(target_detections_all_15E$Ping_date),"%Y-%m-%d"), target_detections_all_15E$Ping_time, sep=" "),format = "%Y-%m-%d %H:%M:%S", tz="Asia/Bangkok")
#eliminates zeroes in the data
target_detections_all_15E<- target_detections_all_15E[target_detections_all_15E$TS_comp !=-9.9e+37,]
#Formats the time to create the Week column and is supposed to change the week numbers to a sequence that starts at 1.
target_detections_all_15E$Week <- as.integer(format(target_detections_all_15E$Date_time, "%V"))
target_detections_all_15E<- transform(target_detections_all_15E, Week=Week-min(Week)+1)
The only 2 columns needed that are in the data frame to start is ping_date and ping_time. I hope this suffices, I'm sorry I'm very inexperienced with this forum, I usually don't have to post questions.