-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleaning.R
50 lines (24 loc) · 1.1 KB
/
cleaning.R
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
## ---- cleaning.R
# library(tidyverse)
replace_global <- function(data_frame_list, dfs_affected_list){
# Function to replace data frames in global envritonment, which names are given in a list (second argument)
for (i in 1:length(data_frame_list)){
for (j in 1:length(dfs_affected_list)){
if (!is.null(dfs_affected_list[j]) == names(data_frame_list[i])){
assign(dfs_affected_list[j], data_frame_list[[i]], envir = .GlobalEnv)
}
}
}
}
dfs_affected <- c() # Vector with names of data frames that will be affected while removing "Pos" column
# Iterating through all data frames and removing "Pos" column where it is necessary
for (i in 1:length(data_frames)){
current_df <- data_frames[[i]]
if (grepl("Pos", colnames(current_df[1])) || colnames(current_df[1]) == ""){
current_df <- current_df[-1]
dfs_affected <- append(dfs_affected, names(data_frames[i]))
data_frames[[i]] <- current_df
}
}
# Replacing data frames in Global Environment, so we can use the clean ones
replace_global(data_frames, dfs_affected)