Click here to Skip to main content
15,891,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dataframe (df) with 4 columns: Start date, Stop date, Launch date, and NMBR (Usage amount - numerical value). I have another dataframe (usage) with two columns: time1 and usage. I am trying to check if each date in the time1 column in the usage dataframe falls between any of the start and end dates in the df dataframe. If it does fall in between the start and end date then capture the NMBR, store, and increment in the usage column in the usage dataframe. I am getting the error

"Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format".

I am new to r programming but would like help figuring out how to resolve.

What I have tried:

Here is sample code to help understand the logic I am going after:

time1 = seq(ISOdate(2018,09,17),ISOdate(2019,09,17), by = "hour")
usage = matrix(0,length(time1),1)

usage <- data.frame(time1,usage)

for (row in 1:nrow(df)) {
starttime <- df[row, "STRT"]
stoptime <- df[row, "STOP"]
launchtime <- df[row,"LNCHD"]
ncpu <- df[row,"NMBR"]

usage = apply(usage,1,add_ncpu)
add_ncpu = function(x){ if(x > starttime && x < stoptime){x = x + ncpu}}
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900