Skip to content

Commit

Permalink
simplify cleaning of limits
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Sep 11, 2024
1 parent 753bef4 commit 6ad0b93
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions R/clean.r
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,11 @@ clean.survey <- function(x, country.column = "country", participant.age.column =
]
seconds_in_year <- period_to_seconds(years(1))
for (limit in limits) {
x$participants <- x$participants[,
paste(limit) := fifelse(!is.na(get(limit)), as.numeric(get(limit)), NA_real_)
]
x$participants <- x$participants[,
paste(limit) := fifelse(
!is.na(get(limit)),
period_to_seconds(period(get(limit), ..age.unit)) /
seconds_in_year,
NA_real_
),
by = seq_len(nrow(x$participants))
x$participants <- x$participants[, paste(limit) := as.numeric(get(limit))]
x$participants <-
x$participants[..age.unit != "years" & !is.na(get(limit)),
paste(limit) := period_to_seconds(period(get(limit), ..age.unit)) /
seconds_in_year,
]
}

Expand Down

0 comments on commit 6ad0b93

Please sign in to comment.