Commit 274ef06d96e9235374c7338a7552305f6388c029
1 parent
a35b1822
Changed [Hackmaggedon_Parser.R], added [ProccessHMRaw] to remove NAs and changed…
… [PArseHMFolder] because of problems with lapply
Showing
1 changed file
with
17 additions
and
22 deletions
ISO27001effectiveness/R/Hackmageddon_Parser.R
... | ... | @@ -4,38 +4,33 @@ |
4 | 4 | |
5 | 5 | |
6 | 6 | |
7 | -#-----------------------------Library tests / install-------------------------------------------------- | |
8 | - | |
9 | - | |
10 | -#' Install and load required libraries | |
11 | -#' | |
12 | -#' This function checks if every required library is installed to be loaded, if not they will be installed and then loaded. | |
13 | -#' Libraries installed: | |
14 | -#' xlsx to parse excel files like ISO survey source format | |
15 | -LoadParserLibraries <- function(){ | |
16 | - if (!require("xlsx")) | |
17 | - { | |
18 | - install.packages("xlsx") | |
19 | - if (!require("xlsx")) stop("Error while loading package [xlsx]") | |
20 | - } | |
21 | -} | |
22 | - | |
23 | -#----------------------------- | |
24 | - | |
25 | 7 | ParseHMExcel <- function(file){ |
26 | 8 | print(file) |
27 | 9 | if (!file.exists(file)) { |
28 | 10 | stop(paste("Error, file [", file, "] not found")) |
29 | 11 | } |
30 | - dataset <- read.xlsx2(file, 1, header = TRUE,colIndex = 2:10) | |
12 | + dataset <- read.xlsx2(file, 1, header = TRUE,colIndex = 2:10, colClasses = c("Date", "character", "character", "character", "character", "character", "character", "character")) | |
13 | + dataset | |
14 | +} | |
15 | + | |
16 | +ProccesHMRaw <- function(dataset.raw){ | |
17 | + | |
18 | + #Remove rows with Date NA | |
19 | + dataset <- dataset.raw[!is.na(dataset.raw$Date),] | |
20 | + | |
31 | 21 | dataset |
32 | 22 | } |
33 | 23 | |
34 | 24 | ParseHMFolder <- function(folder){ |
35 | 25 | filelist <- list.files(folder) |
36 | - frames <- lapply(paste(folder,filelist,sep=""),ParseHMExcel) | |
37 | - merged_frame = merge(frames) | |
38 | - merged_frame | |
26 | + #frames <- lapply(paste(folder,filelist,sep = ""),ParseHMExcel) | |
27 | + dataset <- ProccesHMRaw(ParseHMExcel(paste(folder,filelist[1],sep = "/"))) | |
28 | + | |
29 | + for (i in 2:length(filelist)) { | |
30 | + dataset <- rbind(dataset, ProccesHMRaw(ParseHMExcel(paste(folder,filelist[i],sep = "/")))) | |
31 | + } | |
32 | + | |
33 | + dataset | |
39 | 34 | } |
40 | 35 | |
41 | 36 | ... | ... |