aboutsummaryrefslogtreecommitdiff
path: root/R/mkin_wide_to_long.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_wide_to_long.R
parent053bf27d3f265c7a7378e2df3e00cf891e0d1bb2 (diff)
Use roxygen for functions and methods
Diffstat (limited to 'R/mkin_wide_to_long.R')
-rw-r--r--R/mkin_wide_to_long.R68
1 files changed, 34 insertions, 34 deletions
diff --git a/R/mkin_wide_to_long.R b/R/mkin_wide_to_long.R
index 21a7cbe9..bef0e408 100644
--- a/R/mkin_wide_to_long.R
+++ b/R/mkin_wide_to_long.R
@@ -1,34 +1,34 @@
-# $Id$
-
-# Copyright (C) 2010-2013 Johannes Ranke
-# Contact: mkin-devel@lists.berlios.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/>
-if(getRversion() >= '2.15.1') utils::globalVariables(c("name", "time", "value"))
-
-mkin_wide_to_long <- function(wide_data, time = "t")
-{
- colnames <- names(wide_data)
- if (!(time %in% colnames)) stop("The data in wide format have to contain a variable named ", time, ".")
- vars <- subset(colnames, colnames != time)
- n <- length(colnames) - 1
- long_data <- data.frame(
- name = rep(vars, each = length(wide_data[[time]])),
- time = as.numeric(rep(wide_data[[time]], n)),
- value = as.numeric(unlist(wide_data[vars])),
- row.names = NULL)
- return(long_data)
-}
+if(getRversion() >= '2.15.1') utils::globalVariables(c("name", "time", "value"))
+
+#' Convert a dataframe with observations over time into long format
+#'
+#' This function simply takes a dataframe with one independent variable and
+#' several dependent variable and converts it into the long form as required by
+#' \code{\link{mkinfit}}.
+#'
+#' @param wide_data The dataframe must contain one variable with the time
+#' values specified by the \code{time} argument and usually more than one
+#' column of observed values.
+#' @param time The name of the time variable.
+#' @return Dataframe in long format as needed for \code{\link{mkinfit}}.
+#' @author Johannes Ranke
+#' @keywords manip
+#' @examples
+#'
+#' wide <- data.frame(t = c(1,2,3), x = c(1,4,7), y = c(3,4,5))
+#' mkin_wide_to_long(wide)
+#'
+#' @export
+mkin_wide_to_long <- function(wide_data, time = "t")
+{
+ colnames <- names(wide_data)
+ if (!(time %in% colnames)) stop("The data in wide format have to contain a variable named ", time, ".")
+ vars <- subset(colnames, colnames != time)
+ n <- length(colnames) - 1
+ long_data <- data.frame(
+ name = rep(vars, each = length(wide_data[[time]])),
+ time = as.numeric(rep(wide_data[[time]], n)),
+ value = as.numeric(unlist(wide_data[vars])),
+ row.names = NULL)
+ return(long_data)
+}

Contact - Imprint