aboutsummaryrefslogtreecommitdiff
path: root/R/mkin_long_to_wide.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2019-10-25 00:37:42 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2019-10-25 02:03:54 +0200
commit0a3eb0893cb4bd1b12f07a79069d1c7f5e991495 (patch)
tree1bf0ffeb710b3438fee224d0a657606b4c36b495 /R/mkin_long_to_wide.R
parent053bf27d3f265c7a7378e2df3e00cf891e0d1bb2 (diff)
Use roxygen for functions and methods
Diffstat (limited to 'R/mkin_long_to_wide.R')
-rw-r--r--R/mkin_long_to_wide.R57
1 files changed, 29 insertions, 28 deletions
diff --git a/R/mkin_long_to_wide.R b/R/mkin_long_to_wide.R
index 081262f8..0125f2da 100644
--- a/R/mkin_long_to_wide.R
+++ b/R/mkin_long_to_wide.R
@@ -1,28 +1,29 @@
-# Copyright (C) 2010-2011 Johannes Ranke
-# Contact: jranke@uni-bremen.de
-
-# This file is part of the R package mkin
-
-# mkin is free software: you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation, either version 3 of the License, or (at your option) any later
-# version.
-
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-# details.
-
-# You should have received a copy of the GNU General Public License along with
-# this program. If not, see <http://www.gnu.org/licenses/>
-
-mkin_long_to_wide <- function(long_data, time = "time", outtime = "time")
-{
- colnames <- unique(long_data$name)
- wide_data <- data.frame(time = subset(long_data, name == colnames[1], time))
- names(wide_data) <- outtime
- for (var in colnames) {
- wide_data[var] <- subset(long_data, name == var, value)
- }
- return(wide_data)
-}
+#' Convert a dataframe from long to wide format
+#'
+#' This function takes a dataframe in the long form, i.e. with a row for each
+#' observed value, and converts it into a dataframe with one independent
+#' variable and several dependent variables as columns.
+#'
+#' @param long_data The dataframe must contain one variable called "time" with
+#' the time values specified by the \code{time} argument, one column called
+#' "name" with the grouping of the observed values, and finally one column of
+#' observed values called "value".
+#' @param time The name of the time variable in the long input data.
+#' @param outtime The name of the time variable in the wide output data.
+#' @return Dataframe in wide format.
+#' @author Johannes Ranke
+#' @examples
+#'
+#' mkin_long_to_wide(FOCUS_2006_D)
+#'
+#' @export mkin_long_to_wide
+mkin_long_to_wide <- function(long_data, time = "time", outtime = "time")
+{
+ colnames <- unique(long_data$name)
+ wide_data <- data.frame(time = subset(long_data, name == colnames[1], time))
+ names(wide_data) <- outtime
+ for (var in colnames) {
+ wide_data[var] <- subset(long_data, name == var, value)
+ }
+ return(wide_data)
+}

Contact - Imprint