I implemented a function 'identify_case' i.e.:
## Function that identify the gaps of NAs according to their length
identify_case = function(df, variable, seuil) {
df$value = ifelse(is.na(df[,variable])==TRUE,1,0)
df$temp = rep.int(rle(df$value)$lengths, rle(df$value)$lengths)
df$gap = ifelse(df$value == 1, df$temp, 0)
df$temp = NULL
df$case.nb = ifelse((df$gap > 0 & df$gap <= seuil),"cas1",ifelse((df$gap >
seuil),"cas2","OK"))
return(df)
}
When I call the function using the code below:
temp.df = identify_case(df = temporary_df,variable = "energy_NA",seuil
= 3)
I get the error :
Error in identify_case(df = temporary_df, variable = "energy_NA", seuil = 3):
unused argument (seuil = 3)
What is weird is when I add the line
seuil = seuil
at the beginning of the function 'identify_case'.I do not get any error and the code is executed perfectly.
i.e.:
## Function that identify the gaps of NAs according to their length
identify_case = function(df, variable, seuil) {
seuil = seuil
df$value = ifelse(is.na(df[,variable])==TRUE,1,0)
df$temp = rep.int(rle(df$value)$lengths, rle(df$value)$lengths)
df$gap = ifelse(df$value == 1, df$temp, 0)
df$temp = NULL
df$case.nb = ifelse((df$gap > 0 & df$gap <= seuil),"cas1",ifelse((df$gap >
seuil),"cas2","OK"))
return(df)
}
Does anyone what is going on here?