-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadingFromExcel_Functions.R
More file actions
57 lines (37 loc) · 2.22 KB
/
ReadingFromExcel_Functions.R
File metadata and controls
57 lines (37 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
### removes in a dataframe columns that have complete NAs
removeAllNAColumns = function(x){
return ( x[sapply(x, function(x) !all(is.na(x)))] )
}
##' logic gets the first NA after the title
extractDFfromLineGuide = function(LineGuideDF_Copy,title,columnNameToFindIn = "Microstrategy"){
#TO DO getv only if the element exists
titleRowStart = which(LineGuideDF_Copy[[columnNameToFindIn]] == title)
if (length(titleRowStart)== 1){
firstNA = LineGuideDF_Copy[[columnNameToFindIn]] %>%
.[titleRowStart:length(.)] %>%
is.na() %>% which() %>% .[1]
return(
LineGuideDF_Copy[(titleRowStart + 1) :(titleRowStart + firstNA -2),]
)
}
else{return(NULL)}
}
##' corrects the column name as the first line of the passed dataframe
cleanUpExtractedDF <- function(x){
x = removeAllNAColumns(x)
colnames(x) = x[1,] # first line is transferred as column name
x = x[-1,]
return(x)
}
extractDFfromLineGuide_ForLayerName = function(LineGuideDF_Copy,title,columnNameToFindIn = "Microstrategy"){
titleRowStart = which(LineGuideDF_Copy[[columnNameToFindIn]] == title)
if (length(titleRowStart)== 1){
firstNA = LineGuideDF_Copy[[columnNameToFindIn]] %>%
.[titleRowStart:length(.)] %>%
is.na() %>% which() %>% .[1]
return(
LineGuideDF_Copy[titleRowStart:(titleRowStart + firstNA -2),]
)
}
else{return(NULL)}
}