#' Substitutes qualitative data
#'
#' @param data data frame
#' @param name name to be saved
#' @param ... keys and values in alternating sequence
#'
#' @return
#' @export
#'
#'
processQualitativeData <- function(data, name, ...) {
if(!hasArg(data)) {
data <- getData()
}
if(hasArg(...)) {
v <- c(...)
keys <- vector[seq(1, length(v), 2)]
values <- vector[seq(2, length(v), 2)]
}
else {
ok <- F
while(!ok) {
message("Please provide a value for each key: ")
if(is.matrix(data)) {
keys <- unique(c(data))
}
else {
keys <- unique(unlist(data))
}
print(keys)
values <- c()
#collect values
output <- whatToDo("What type of output?", "numeric", "logical", "character")
#numeric
if(output == "numeric") {
for(i in 1:length(keys)) {
values <- c(values, getNumber(paste0("Substitute <", keys[i], "> with: ")))
}
}
#logical
if(output == "logical") {
for(i in 1:length(keys)) {
values <- c(values, ok(paste0("Substitute <", keys[i], "> with:")))
}
}
#character
if(output == "character") {
for(i in 1:length(keys)) {
values <- c(values, readline(paste0("Substitute <", keys[i], "> with: ")))
}
}
names(values) <- keys
print(values)
message("")
ok <- ok("Ok?")
}
}
for(i in 1:length(keys)) {
data[data == keys[i]] <- values[i]
}
if(!hasArg(name)) {
name <- readline("Name of data: ")
}
#numeric
if(output == "numeric") {
data2 <- apply(data, 2, as.numeric)
rownames(data2) <- rownames(data)
}
#logical
if(output == "logical") {
data2 <- apply(data, 2, as.logical)
rownames(data2) <- rownames(data)
}
#character
if(output == "character") {
data2 <- apply(data, 2, as.character)
rownames(data2) <- rownames(data)
}
saveThis(data2,
name,
"dat")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.