Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Apply With Multiple Arguments
- append_week_counts_to_entries <- function(entries) {
- entries$week1 <- apply(entries,1,helpfunc,row=row,week=count_week1)
- entries$week2 <- apply(entries,1,helpfunc,row=row,week=count_week2)
- # ... to all N weeks
- return(entries)
- }
- helpfunc <- function(entries,row,week) {
- if(as.character(row[1]) %in% week$id) {
- return(week[which(as.character(week$id) == as.character(row[1])),2])
- }
- else {
- return(0)
- }
- }
- entries: structure(list(`entries$id` = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- )), .Names = "entries$id", row.names = c(NA, -10L), class = "data.frame")
- count_week_i: structure(list(Var1 = structure(1:3, .Label = c("1", "2", "3"
- ), class = "factor"), Freq = c(1L, 2L, 4L)), .Names = c("Var1",
- "Freq"), row.names = c(NA, -3L), class = "data.frame")
Add Comment
Please, Sign In to add comment