attach_PAia <- function(data,years,
activity=FALSE,
level=FALSE,
times=FALSE,
duration=FALSE,
mets=FALSE,
weight_type=FALSE,
PA_ia=FALSE,
Year=FALSE){
years <- data_years(data,years)
paq <- nhs_tsv('paqi',years=years,cat=FALSE)
if (length(paq)==0){
if (do::cnOS()) stop(tmcn::toUTF8("\u8FD9\u4E9B\u5E74\u4EFD\u6CA1\u6709Physical Activity - Individual Activities"))
if (!do::cnOS()) stop('no Physical Activity - Individual Activities in this year cycle')
}
d <- nhs_read(paq,
'padactiv:activity',
'padlevel:level',
'padtimes:times',
'paddurat:duration',
'padmets:mets',
'paaquex:weight_type',
lower_cd = TRUE,cat=FALSE)
d$PA_ia <- d$times*d$duration*d$mets
PA_total <- aggregate(d$PA_ia,list(seqn=d$seqn),FUN=sum)
colnames(PA_total)[2] <- 'PA_total'
d <- dplyr::left_join(d,PA_total,'seqn')
var <- c("Year","seqn")
if (activity) var <- c(var,'activity')
if(level) var <- c(var,'level')
if(times) var <- c(var,'times')
if(duration) var <- c(var,'duration')
if(mets) var <- c(var,'mets')
if(weight_type) var <- c(var,'weight_type')
if(PA_ia) var <- c(var,'PA_ia')
var <- c(var,"PA_total")
d <- unique(d[,var])
attach_return_data(data,d,Year,join='seqn')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.