using this below code I am trying to weight each year in each iteration based on column "weight".
using wtd.table
I have the following code:
wtd.table(result$`it 1`$`year 5`$age,result$`it 1`$`year 5`$gender ,result$`it 1`$`year 5`$district, weights =result$`it 1`$`year 5`$weight )
This output only provides age and gender weighted. It does not also include district. based on some purposes I have used count(var1, var2, var3 , wt = wt)
like this:
count(result$`it 1`$`year 5`$age,result$`it 1`$`year 5`$gender,
result$`it 1`$`year 5`$age,
wt = result$`it 1`$`year 5`$weight)
but I got this error: Error in UseMethod("count") : no applicable method for 'count' applied to an object of class "c('double', 'numeric')". how can I fix that?
here is my code:
iter1 <- list(year1 =data.frame(age=c(10,11,12,13), district=c(1,2,3,4),gender=c(1,2,2,1)
,weight=c(12.2,11.3,11.2,10.1)),
year2 =data.frame(age=c(10,11,12,13), district=c(1,2,3,4),gender=c(1,2,2,1),weight=c(12.2,11.3,11.2,10.1)))
iter2 <- list(year1 =data.frame(age=c(10,11,12,13), district=c(1,2,3,4),gender=c(2,2,1,1)
,weight=c(12.2,11.3,11.2,10.1)),
year2 =data.frame(age=c(10,11,12,13), district=c(1,2,3,4),gender=c(2,2,1,1),weight=c(12.2,11.3,11.2,10.1)))
df <- list(iter1 = iter1, iter2 = iter2)
my expected output is like df1
df1<-
district age gender freq
1 10 1 12.2
1 11 1 0.0
1 12 1 0.0
1 13 1 10.1
1 10 2 0.0
1 11 2 11.3
1 12 2 11.2
1 13 2 0.0