Calculating percentage Missing value for variables using one object
Read in the data, aggregate it by month and then turn it into a monthly zoo object and plot using a custom X axis: Lines <- 'dos,variable1,variable2 May-06,1,"" May-06,2,"" June-06,"",2 June-06,1,4 July-06,1,4 July-06,1,4 August-06,1,4 August-06,1,4' DF <- read.table(textConnection(Lines), header = TRUE, sep = ",") library(zoo) DF.na <- aggregate(DF[-1], DF["dos"], function(x) mean(is.na(x))) z <- zoo(as.matrix(DF.na[-1]), as.yearmon(DF.na$dos, "%B-%y")) i <- 1 plot(z[,i], xaxt = "n", ylab = "Fraction Missing", main = names(DF)[i+1]) axis(1, time(z), format(time(z), "%m/%y"), cex.axis = .7)
On Tue, Mar 24, 2009 at 2:58 AM, Shreyasee <shreyasee.pradhan at gmail.com> wrote:
Hi,
I have a dataset in which there are in all 250 variables and for each
variable the data is entered over the months.
I need to calculate the percentage of missing values for each variable over
each month and then plot a graph for that.
I am running the following code for doing the same
*ds <- read.csv(file="filepath", header=TRUE)
attach(ds)
may <- length(variable1[variable1==""]) / length(dos[dos=="May-06"]) * 100
jun <- length(variable1[variable1==""]) / length(dos[dos=="June-06"]) * 100
.
.
.
var1 <- c(may, jun, ...........)
x <- seq(as.Date("2006-01-01"), as.Date("2007-03-31"), by="months")
plot(var1~x)*
So likewise I am calculating the percentage of missing values for each
variable for each month using different variables and storing the values in
those variables and then combining those variables in one object for
plotting the graph.
I need to know, whether can I combine all the variables from that dataset in
one object and calculate the missing values percentage over months together,
instead of creating different variables for each month and then combining
them.
Also, after doing that, I need to plot the graph for each variable and
combine it in a single pdf file.
I highly appreciate all your help.
Thanks,
Shreyasee
? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.