[R] number of count in function

shaaib @ho@|b@||gw|02 @end|ng |rom gm@||@com
Thu Jun 18 07:52:16 CEST 2020


Hi I have created function for a summary and i want "N" (number of
frequency) should come at the second row but its coming in between
variables, not coming at top and bottom. please help where i am missing or
where i need to change.

multi<-function(dataset,var_list,var_name){
data<-dataset[unlist(var_list)]

total_column<-NA^!rowSums(!is.na(data[,1:ncol(data)]))
lst1 <- lapply(names(data[,1:ncol(data)]), function(x) freq(data,x))
lst2 <- lst1[!sapply(lst1, is.null)]
tab<-Reduce(rbind,lst2)
tab<-tab%>%
mutate(Var1=as.character(Var1),
Freq=as.numeric(Freq),
N=sum(total_column,na.rm = TRUE))%>%
mutate(UQ(rlang::sym(var_name)) := Freq*100/N)%>%
select(Var1,!!var_name,N)%>%
dplyr::rename(" "=Var1)
tab[,2]<- mask_m(tab[,2],tab[,3])
tab[,2]<-ifelse(tab[,2]=="--","--", paste0(roundUp(tab[,2]),"%"))
tab<-rbind(c("N",sum(total_column,na.rm = TRUE)),tab[,1:2])
tab
}

	[[alternative HTML version deleted]]



More information about the R-help mailing list