## Not run:
# data(NordklimData)
# str(NordklimData)
# # get all the country codes
# countries <- unique(NordklimData$CountryCode)
# # earliest and latest year of data collection
# minFirstYear<- min(NordklimData$FirstYear)
# maxFirstYear<- max(NordklimData$FirstYear)
# allyears <- min(NordklimData$FirstYear):max(NordklimData$FirstYear)
# # get the yearly average of all records
# avgNordk <- cbind(NordklimData[,c('CountryCode','ClimateElement','FirstYear',
# 'NordklimNumber')],
# YrAvg=apply(NordklimData[,c('January','February','March','April','May','June',
# 'July','August','September', 'October','November','December')],1,function(x)
# {x[x==-9999]<-NA;mean(x,na.rm = TRUE)}))
# str(avgNordk)
# # plot the Danish mean temperatures for its 5 stations (for a quick visual
# # inspection, no need for labels or legends)
# DanavgNordk <- avgNordk[which(avgNordk$CountryCode=='DK' &
# avgNordk$ClimateElement==101),c('FirstYear','YrAvg','NordklimNumber')]
# p <- unique(DanavgNordk$NordklimNumber)
# for (Dp in p) { plot(DanavgNordk[which(DanavgNordk$NordklimNumber==Dp),
# c('FirstYear','YrAvg')],type='l',col=( which(Dp==p)),
# xlim=c(min(DanavgNordk$FirstYear), max(DanavgNordk$FirstYear)),
# ylim=c(60,120)); if (Dp != p[length(p)]) par(new=T)}
# # average each country
# avgNordkCountry=aggregate(YrAvg ~ CountryCode+ClimateElement+FirstYear ,
# data = avgNordk, function(x) {x[x==-9999]<-NA;mean(x,na.rm = TRUE)})
# str(avgNordkCountry)
# # plot the temperatures (mean of all stations) for each country
# for (country in countries) { plot(avgNordkCountry[
# which(avgNordkCountry$CountryCode==country & avgNordkCountry$ClimateElement==101),
# c('FirstYear','YrAvg')],type='l',col=( which(country==countries)),
# xlim=c(minFirstYear, maxFirstYear),ylim=c(0,120),
# main='Mean of yearly means of all stations for each country',
# xlab='Years',ylab='Mean temperature');
# if (country != countries[length(countries)]) par(new=T)}
# legend('topleft', legend = countries, col=1:5, pch=1, lty=1, merge=TRUE)
# ## End(Not run)
Run the code above in your browser using DataLab