Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- participant <- rep(1:10, each=100)
- stimuli <- rep(1:100, 10)
- judgment <- rnorm(1000)
- df1 <- data.frame(participant, stimuli, judgment)
- df2 <- data.frame(stimuli=1:100, criterion=rnorm(100))
- df <- merge(df1, df2, by='stimuli') %>% arrange(participant, stimuli)
- participants_id = unique (df$participant)
- MyFun = function(Data) {
- HelpFun = function(x, Data) {
- # x is the index for the number of participants.
- # It Will be used in the lapply call bellow
- participants_x = sample(participants_id, x)
- filter(Data, participant %in% participants_x) %>%
- group_by(stimuli) %>%
- summarise( mean_x = mean(judgment),
- criterion = unique(criterion) ) %>%
- summarise(cor = cor(.$mean_x, .$criterion))
- }
- N <- length(unique(Data$participant))
- lapply(1:N, HelpFun, Data) %>% bind_rows()
- }
- MyFun(df)
Add Comment
Please, Sign In to add comment