OpasnetUtils/Interpret
From Testiwiki
This page is a method.
The page identifier is Op_en5724 |
---|
Moderator:Nobody (see all) Click here to sign up. |
This page is a stub. You may improve it into a full page, and then a rating bar will appear here. |
Upload data
|
Description
interpret takes a vector and makes a data.frame out of it (to be used in e.g. make.ovariable).
It also changes abbreviations into probability samples.
Code
# INTERPRET ################### interpret takes a vector and makes a data.frame out of it (to be used in e.g. make.ovariable). ### It also changes abbreviations into probability samples. interpret <- function(data) { sample <- NULL if(is.vector(data)) {data <- data.frame(Result = data)} if("Iter" %in% colnames(data)) { out <- data} else { if(!"Result" %in% colnames(data)) {cat("There MUST be an observation column named 'Result'.\n")} test <- !is.na(as.numeric(as.character(data$Result))) for(i in 1:nrow(data)) { if(test[i]) { sample <- c(sample, rep(as.numeric(as.character(data[i, "Result"])), n)) } else { samplingguide <- as.numeric(strsplit(gsub(" ", "", data[i, "Result"]), "-")[[1]]) if(is.na(samplingguide[1]) | is.na(samplingguide[2])) { sample <- c(sample, rep(data[i, "Result"], n)) } else { sample <- c(sample, runif(n, samplingguide[1], samplingguide[2])) } } } out <- as.data.frame(array(1:(n*nrow(data)*(ncol(data)+1)), dim = c(n*nrow(data), ncol(data) + 1))) colnames(out) <- c("Iter", colnames(data)) for(i in colnames(data)) { out[i] <- rep(data[, i], each = n) } out$Iter <- 1:n out$Result <- sample } return(out) } |