Ver código fonte

Adding remove.NA to remove entries with missing data for a subset of variables

Andrej 2 meses atrás
pai
commit
459918b249
3 arquivos alterados com 41 adições e 4 exclusões
  1. 1 0
      NAMESPACE
  2. 21 4
      R/modifyData.R
  3. 19 0
      man/remove.NA.Rd

+ 1 - 0
NAMESPACE

@@ -7,6 +7,7 @@ export(kaplan.meier.plot.gg)
 export(kaplan.meier.stats)
 export(mapNA)
 export(remapVariable)
+export(remove.NA)
 export(selectValid)
 export(setEventTime)
 export(simple.compute_roc_metrics)

+ 21 - 4
R/modifyData.R

@@ -14,8 +14,8 @@
 sumWithNA<-function(df,var1='lesionmtv41',var2='metastasesmtv41',outVar='totalmtv41',valIfNA=0){
    v1=df[,var1]
    v2=df[,var2]
-   v1[is.na(v1)]=valIfNA
-   v2[is.na(v2)]=valIfNA
+   v1[base::is.na(v1)]=valIfNA
+   v2[base::is.na(v2)]=valIfNA
    df[,outVar]=v1+v2
    df
       
@@ -32,10 +32,27 @@ sumWithNA<-function(df,var1='lesionmtv41',var2='metastasesmtv41',outVar='totalmt
 #' @export
 
 mapNA<-function(df,var,valIfNA=0){
-   df[is.na(df[,var]),var]=valIfNA
+   df[base::is.na(df[,var]),var]=valIfNA
    df
 }
 
+#' Remove entries with missing variables for selected variables
+#'
+#' @param x data frame
+#' @param vars vector of variable names as strings
+#'
+#' @return data frame with entries where vars were NA removed
+#'
+#' @export
+
+remove.NA<-function(x,vars){
+   for (v in vars){
+      x<-x[!base::is.na(x[,v]),]
+   }
+   x
+}
+
+
 #' Map variable time OS status to status at cutoff
 #'
 #' @param df data frame
@@ -130,6 +147,6 @@ setEventTime<-function(df,duration='years_to_event',eventColumn='d_os',startColu
 #' @export 
 
 convert.to.date<-function(x,var,format="%Y-%m-%d"){
-   x[,var]<-as.Date(x[,var],format=format)
+   x[,var]<-base::as.Date(x[,var],format=format)
    x
 }

+ 19 - 0
man/remove.NA.Rd

@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/modifyData.R
+\name{remove.NA}
+\alias{remove.NA}
+\title{Remove entries with missing variables for selected variables}
+\usage{
+remove.NA(x, vars)
+}
+\arguments{
+\item{x}{data frame}
+
+\item{vars}{vector of variable names as strings}
+}
+\value{
+data frame with entries where vars were NA removed
+}
+\description{
+Remove entries with missing variables for selected variables
+}