, поэтому я запустил свой код для данных, используя имя другого дождемера (CS700Rain_in_TOT и Rain_TE525_mm_Tot), и он сработал. Теперь, когда я изменил имя, я продолжаю получать это сообщение об ошибке, в котором говорится, что мое заданное начальное число не является допустимым целым числом ... возможно ли это из-за того, что что-то не так с моим файлом Excel? Я не уверен, что еще может быть причиной этой проблемы. Вот функция, которую я вызываю, и мой код завершается с ошибкой в последней строке.
assign.event.ids <- function(rainfall)
{
has.rainfall = rainfall!=0
rainfall.moving.avg = movavg(rainfall, 72, "s")
event.start = logical(length = length(rainfall))
event.end = logical(length = length(rainfall))
ID.list = vector(length = length(rainfall))
# iterate over rainfall vector to populate event.start and event.end logical vectors
for (n in seq_along(rainfall[-length(rainfall)])) {
# if current timestep has rainfall and there has not been rain in the last 6 hours (moving average is 0), this is the start of an event
if(has.rainfall[n] && rainfall.moving.avg[n-1]==0)
{
event.start[n]=TRUE
}
else
{
event.start[n]=FALSE
}
# if moving average reaches 0 in the next timestep, current timestep is the end of an event
if(rainfall.moving.avg[n]!=0 && rainfall.moving.avg[n+1]==0)
{
event.end[n]=TRUE
}
else
{
event.end[n]=FALSE
}
}
# initial random event ID
event.ID = random_id(bytes = 4)
fill = FALSE
for(n in seq_along(rainfall)) {
#generate new ID when new event starts and start filling it in
if(event.start[n] == TRUE) {
set.seed(as.numeric(dat$TIMESTAMP[n])) # set seed as timestamp of beginning of event to get consistent STORMID results
event.ID = random_id(bytes = 4, use_openssl = FALSE) # random string 8 characters long based on set.seed value. use_openssl = FALSE forces use of internal R randomizer
fill = TRUE
}
# determine if event ID gets filled
if(fill) { ID.list[n] = event.ID }
else { ID.list[n] = NA }
# stop filling event ID when event stops
if(event.end[n] == TRUE) { fill = FALSE }
}
as.factor(ID.list)
}
# end functions
############# CONSTANTS #############
# read in data and treat listed values as NA/NULL/missing. Deal with them later, as necessary. MUST DECLARE COLUMNS TYPES. R is bad at guessing...
IJ_WS<-read_excel("X:/1-PennDOT/H&H/Analysis/IJ/Compiled Data/IJ_WS_All.xlsx", # File Location
na = c(".", "NA", "", "?","-9999","-999900","NaN","7999","-8888","#VALUE!","-8898","NAN","-393.6614173"), # values to ignore
col_types = c("date","numeric","numeric","numeric","numeric"))
dat<-IJ_WS
str(dat)
summary((dat$Rain_TE525_mm_Tot))
dat$Rain_TE525_mm_Tot[is.na(dat$Rain_TE525_mm_Tot)] = 0 # assume no rainfall when rain gage has NA value
# end constants
############# ANALYSIS ##############
# create unique ID's for each storm event based on time-series rainfall.
# See "assign.event.ids" function defined above for specifics.
dat$stormID = assign.event.ids(dat$Rain_TE525_mm_Tot)