Skip to content

Geschlossenheit von Integerlisten grafisch darstellen

Hintergrund der folgenden in R geschriebenen Funktion war es  darzustellen wie Kohärent der index von Datenbanktabellen ist. Fehlende Datensätze sollen farblich hervorgehoben werden. 

tableCoherence < - function(x,main="", xlab="ID"){
   total <- length(min(x):max(x)) # Total amount of expected entries
   tmp <- rep(1,100) # Temporary table with 100 parts
   # Loop through each number from the lowest to the highest
   for(i in min(x):max(x)) {
     # Mark the i-th percent of this 100 parts as red (0)
     # if it doesn’t exist in the input integer vecotor
     if (!(i %in% x)) {
      tmp[round((i - min(x))/total * 100)]  = 0
     }
   }
 
   # Create a new plot
   plot.new()
   plot.window(xlim=c(0,100), ylim=c(0,100))
   # Set title and xlab
   title(main=main)
   title(xlab=xlab)
   # Loop trough the 100 parts and mark
   # 1 with green and 0 with red
   for(i in 1:100) {
     if (tmp[i] == 1){
       segments(i, 0, i, 80, col= ‘green’,lwd=2)
     }else{
       segments(i, 0, i, 100, col= ‘red’,lwd=2)
     }
   }
   # Label the x-axis
   axis(1, at=1:100, lab=round(seq(min(x), max(x), length.out= 100)))
 }

Nehmen wir an, wir hätten eine Tabelle “SampleTable” die einige Fehlende Daten hat (11,15-29,34-39). So kann dies mit der obigen Funktion dargestellt werden. Beachtet werden muss jedoch, dass diese Funktion momentan nur mit Integerlisten funktioniert, die mehr als 100 Einträge aufweisen.

tableCoherence(c(1:10,12:14,30:33,40:102),"Coherence of table 'SampleTable'")

Prognosen für die Miss Wahl 2011

Bürokratie 2.0

Optimized by SEO Ultimate