Spaces:
Sleeping
Sleeping
Update process_data.R
Browse files- process_data.R +25 -3
process_data.R
CHANGED
|
@@ -234,13 +234,35 @@ clean_and_convert <- function(cell) {
|
|
| 234 |
})
|
| 235 |
}
|
| 236 |
# Load the trust driver dataset (CSV or Excel)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
data_driver <- NULL
|
| 238 |
if (grepl(".xlsx", input_file)) {
|
| 239 |
# Load the Excel file with the fourth row as the header
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
}
|
| 243 |
-
|
| 244 |
# Process the Trust model
|
| 245 |
trust_driver_analysis(
|
| 246 |
Trust ~ Stability + Development + Relationship + Benefit + Vision + Competence,
|
|
|
|
| 234 |
})
|
| 235 |
}
|
| 236 |
# Load the trust driver dataset (CSV or Excel)
|
| 237 |
+
|
| 238 |
+
clean_and_convert <- function(cell) {
|
| 239 |
+
if (is.character(cell)) {
|
| 240 |
+
cell <- gsub("\t", "", cell)
|
| 241 |
+
}
|
| 242 |
+
tryCatch({
|
| 243 |
+
as.numeric(cell)
|
| 244 |
+
}, warning = function(w) {
|
| 245 |
+
cell
|
| 246 |
+
}, error = function(e) {
|
| 247 |
+
cell
|
| 248 |
+
})
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
|
| 254 |
data_driver <- NULL
|
| 255 |
if (grepl(".xlsx", input_file)) {
|
| 256 |
# Load the Excel file with the fourth row as the header
|
| 257 |
+
data_driver <- read_excel(input_file, sheet = "Driver", skip = 3)
|
| 258 |
+
|
| 259 |
+
# Apply clean_and_convert to all columns
|
| 260 |
+
data_driver[] <- lapply(data_driver, function(col) sapply(col, clean_and_convert))
|
| 261 |
+
} else {
|
| 262 |
+
stop("Input file must be an Excel file (.xlsx)")
|
| 263 |
+
}
|
| 264 |
+
return(data_driver)
|
| 265 |
}
|
|
|
|
| 266 |
# Process the Trust model
|
| 267 |
trust_driver_analysis(
|
| 268 |
Trust ~ Stability + Development + Relationship + Benefit + Vision + Competence,
|