Skip to content
Prev 174751 / 398506 Next

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: