I have a function that takes a column p of a data.frame dat and sums the similar values:
response <- function(dat, p){
y = dat[p]
sums = table(y)
sums_df = as.data.frame(sums)
#sums_df$rfreq = (sums_df$Freq/sum(sums_df$Freq))*100
#sums_df$rfreq = round(sums_df$rfreq, digits = 0)
#sums_df = sums_df[1:4, c(1,3)]
return(sums_df)
}
This works fine when run individually.
> response(SOM_C, "f76a")
f76a Freq
1 1 5
2 2 51
3 3 14
4 4 6
5 5 29
6 97 1
7 99 7
But when I try to run it with through a list of separate data.frames (which include 'SOM_C')
plist <- c(SOM_V, SOM_SD, SOM_C, SOM_L, SOM_M, SOM_KD, SOM_MP, SOM_SvD)
It throws the following error.
> output <- lapply(plist, response, p = "f76a")
Error in `vec_slice()`:
! Can't use character names to index an unnamed vector.
Run `rlang::last_error()` to see where the error occurred.