can you describe in words what you are trying to accomplish with the all(duplicated(AGE_YEARS)[-1L])(AGE_YEARS)
portion of your code?
Your error is coming from that portion of your code, where it appears you are trying to multiply an object of logical class (the result of all(duplicated(AGE_YEARS)[-1L])
) to a (presumably) numeric vector of AGE_YEARS
.
I'm not sure if that is what you are trying to accomplish, but if you did for whatever reason need to multiply a single logical value to a numeric vector, you would need to include a multiplication sign (*) between the elements.
e.g.
all(duplicated(iris$Sepal.Length)[-1L])
# [1] FALSE
all(duplicated(iris$Sepal.Length)[-1L])(iris$Sepal.Length)
# Error: attempt to apply non-function
all(duplicated(iris$Sepal.Length)[-1L])*(iris$Sepal.Length)
# [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# [40] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# [79] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# [118] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Good luck!
PS in the future it is helpful to include a reproducible example (How to make a great R reproducible example) of code in your questions!