When attempting to create a new column using a user created function, I receive an 'unsupported class error'. Goal is to create a new column using mutate, stored in a data.frame by using the created function applying to all rows (3 rows in this example...).
Testing the function itself, I can pass the 2 inputs with the correct output retrieved (example below. Note the function consumes 2 parameters and 'lookups' the value in a 3 column table 'LFPR', which is a 3 column table containing Sex, Age, and Labor Force participation rate. Interestingly, the output from the function example is a tibble - is mutate having issues with the output being a tibble?
M5_DCF_Setup_Test <- M5_DCF_Setup %>%
filter(M5_DCF_Setup$Person_Id_M5<=3) %>%
rowwise() %>%
mutate(lfpr = Lfpr_Lu(Person_Sex_M5, Person_Age_M5))
Error: Column `lfpr` is of unsupported class data.frame
#Function
Lfpr_Lu <- function (S,A){
LFPR_Percent <- LFPR %>%
filter(Sex==S & Age==A) %>%
select(LFPR_Percent)
return(LFPR_Percent)
}
#Test
Lfpr_Lu("M",24)
# A tibble: 1 x 1
LFPR_Percent
<dbl>
1 0.689