I am trying with below line of codes :
library(dplyr)
library(zoo)
data.frame('col1' = c('C', 'A', 'B', 'A'), 'col2' = c(1,2,3,4)) %>%
apply(as.matrix(.),
1,
function(ii) {
merge(data.frame('xx' = sample(letters[1:10], 5, replace = T), 'val1' = 1:5),
data.frame('xx' = sample(letters[1:5], 5, replace = T), 'val2' = 21:25),
by = 'xx', all = T) %>%
mutate('Info' = ii['col1']) %>%
`colnames<-`(c('yy0', 'yy1', 'yy2', 'yy3'))
})
With this code, I am getting below error
Error in match.fun(FUN) : '1' is not a function, character or symbol
How above flow is working perfectly, if I use normal calculation without using pipe operator.
Can you please help me how to access information from parent dataframe object within apply function in above setup?
For example, I want to use below code within apply:
instead of
mutate('Info' = ii['col1'])
I want to use
mutate('Info' = <<min of the column 'col2' in parent dataframe>>)
Any pointer will be highly appreciated