# R-GUI How do i aggregate survey data collected for multiple years and see if they contain a variable?

I am new to R and usually rely on stata.

I have a considerably large data frame, it contains data from a broad range of surveys and years, each with their own types of classifications and answers. The variables have not been standardised. The data is at an Individual level.

Questions I have are the following:

How can I aggregate the surveys? How can Identify the number of surveys which have provided information on a particular variable i'm interested in like education?

Thank you very much,

raj

• (1) Too many ways to help without further guidance. (2) xtabs(~id_study+edu,data=df) might help. – r2evans May 9 '18 at 7:12

## 1 Answer

If I understand your question correctly you'd like to obtain the proportion of missing values of a specific column in your dataset. This can be obtained with the plyr library

For example:

library(plyr)
df <- data.frame(Study=c('Study_1', 'Study_1', 'Study_2', 'Study_3'), col1=c(NA,NA,5,8), col2=c(8, NA, NA, 7))

column <- 'col1'           # is the column your are interested in

ddply(df, .(Study), function(x){
length(which(is.na(x[column])))/nrow(x)*100
})

Study  V1
Study_1 100
Study_2   0
Study_3   0


Study_1 has 100% missing values and the other studies none, so except Study_1 all studies contains some information