From 16f5b1d3c0136413e92b2be0f20d365e92e9cd1c Mon Sep 17 00:00:00 2001 From: jranke Date: Tue, 18 May 2010 12:58:38 +0000 Subject: Much more complete version that was just submitted to CRAN. git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/kinfit/pkg/mkin@9 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- R/mkin_wide_to_long.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 R/mkin_wide_to_long.R (limited to 'R/mkin_wide_to_long.R') diff --git a/R/mkin_wide_to_long.R b/R/mkin_wide_to_long.R new file mode 100644 index 00000000..6db2f337 --- /dev/null +++ b/R/mkin_wide_to_long.R @@ -0,0 +1,13 @@ +mkin_wide_to_long <- function(wide_data, time = "t") +{ + colnames <- names(wide_data) + vars <- subset(colnames, colnames != time) + n <- length(colnames) - 1 + if (!(time %in% colnames)) stop("The data in wide format have to contain a variable named ", time, ".") + long_data <- data.frame( + name = rep(vars, each = length(wide_data[[time]])), + time = rep(wide_data[[time]], n), + value = unlist(wide_data[vars]), + row.names = NULL) + return(long_data) +} -- cgit v1.2.1