Browse Source

Add convert to date

Andrej 1 month ago
parent
commit
55e3a34892
3 changed files with 35 additions and 0 deletions
  1. 1 0
      NAMESPACE
  2. 13 0
      R/modifyData.R
  3. 21 0
      man/convert.to.date.Rd

+ 1 - 0
NAMESPACE

@@ -1,5 +1,6 @@
 # Generated by roxygen2: do not edit by hand
 
+export(convert.to.date)
 export(convert.to.sul)
 export(kaplan.meier)
 export(kaplan.meier.plot.gg)

+ 13 - 0
R/modifyData.R

@@ -119,4 +119,17 @@ setEventTime<-function(df,duration='years_to_event',eventColumn='d_os',startColu
    df
 }
 
+#' Convert string variable to date using prescribed format
+#'
+#' @param x data frame
+#' @param var variable to be converted
+#' @param format format of data variable as set by as.Date R function
+#'
+#' @return data frame with selected variable set as date
+#'
+#' @export 
 
+convert.to.date<-function(x,var,format="%Y-%m-%d"){
+   x[,var]<-as.Date(x[,var],format=format)
+   x
+}

+ 21 - 0
man/convert.to.date.Rd

@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/modifyData.R
+\name{convert.to.date}
+\alias{convert.to.date}
+\title{Convert string variable to date using prescribed format}
+\usage{
+convert.to.date(x, var, format = "\%Y-\%m-\%d")
+}
+\arguments{
+\item{x}{data frame}
+
+\item{var}{variable to be converted}
+
+\item{format}{format of data variable as set by as.Date R function}
+}
+\value{
+data frame with selected variable set as date
+}
+\description{
+Convert string variable to date using prescribed format
+}