Skip to content
Snippets Groups Projects
Commit f6724455 authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Explicitly call reshape2.

parent ee1dece8
No related branches found
No related tags found
1 merge request!127WQP update.
...@@ -71,7 +71,8 @@ ...@@ -71,7 +71,8 @@
#' variableInfo \tab data frame \tab A data frame containing information on the requested parameters \cr #' variableInfo \tab data frame \tab A data frame containing information on the requested parameters \cr
#' } #' }
#' @export #' @export
#' @import reshape2 #' @importFrom reshape2 melt
#' @importFrom reshape2 dcast
#' @seealso \code{\link{readWQPdata}}, \code{\link{whatWQPsites}}, #' @seealso \code{\link{readWQPdata}}, \code{\link{whatWQPsites}},
#' \code{\link{readWQPqw}}, \code{\link{constructNWISURL}} #' \code{\link{readWQPqw}}, \code{\link{constructNWISURL}}
#' @examples #' @examples
...@@ -139,13 +140,15 @@ readNWISqw <- function (siteNumbers,parameterCd,startDate="",endDate="", ...@@ -139,13 +140,15 @@ readNWISqw <- function (siteNumbers,parameterCd,startDate="",endDate="",
"sample_end_dt","sample_end_tm","sample_start_time_datum_cd","tm_datum_rlbty_cd", "sample_end_dt","sample_end_tm","sample_start_time_datum_cd","tm_datum_rlbty_cd",
"parm_cd","startDateTime","endDateTime","coll_ent_cd", "medium_cd","project_cd", "parm_cd","startDateTime","endDateTime","coll_ent_cd", "medium_cd","project_cd",
"aqfr_cd","tu_id","body_part_id", "hyd_cond_cd", "samp_type_cd", "aqfr_cd","tu_id","body_part_id", "hyd_cond_cd", "samp_type_cd",
"hyd_event_cd","sample_lab_cm_tx") "hyd_event_cd","sample_lab_cm_tx","tz_cd")
columnsToMelt <- columnsToMelt[columnsToMelt %in% names(data)] columnsToMelt <- names(data)[!(names(data) %in% columnsToMelt)]
dataWithPcodes <- data[data$parm_cd != "",] dataWithPcodes <- data[data$parm_cd != "",]
if(sum(data$parm_cd == "") > 0){ if(sum(data$parm_cd == "") > 0){
warning("Some or all data returned without pCodes, those data will not be included in reshape") warning("Some or all data returned without pCodes, those data will not be included in reshape")
} }
longDF <- reshape2::melt(dataWithPcodes, columnsToMelt) # longDF <- reshape2::melt(dataWithPcodes, measure.vars = columnsToMelt)
longDF <- reshape2::melt(dataWithPcodes, measure.vars = columnsToMelt,
variable.name = "variable", value.name = "value", na.rm = FALSE)
wideDF <- reshape2::dcast(longDF, ... ~ variable + parm_cd ) wideDF <- reshape2::dcast(longDF, ... ~ variable + parm_cd )
wideDF[,grep("_va_",names(wideDF))] <- sapply(wideDF[,grep("_va_",names(wideDF))], function(x) as.numeric(x)) wideDF[,grep("_va_",names(wideDF))] <- sapply(wideDF[,grep("_va_",names(wideDF))], function(x) as.numeric(x))
pCodesReturned <- unique(dataWithPcodes$parm_cd) pCodesReturned <- unique(dataWithPcodes$parm_cd)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment