Within a dataframe, paired numeric fields that use a "_lo" and "_hi" suffix naming convention (e.g., "conc_lo" "conc_hi") are combined into a single Surv object (e.g., "conc") using the "interval2" option provided by through the survival::Surv(conc_lo, conc_hi, type = "interval2") syntax.

makeSurvDF(df, suf_lo = "_lo", suf_hi = "_hi")

Arguments

df

name of data frame

suf_lo

Column name suffix for "lo" values. Default = "_lo"

suf_hi

Column name suffix for "hi" values. Default = "_hi"

Value

dataframe with Surv fields

Details

Converting fields to Surv objects works with field pairs that have a "_lo" and "_hi" suffix naming convention. The numeric value for "_hi" must be greater than or equal to the "_lo" value. Source data that violate this requirement are set to NA with a summary report outputted to the console.

The user can specify their own values for the lo/hi suffixes or use the defaults.

Examples

df <- dataCensored[1:20,]
colnames(df)
#>  [1] "station"  "date"     "layer"    "secchi"   "salinity" "do"      
#>  [7] "wtemp"    "tss"      "chla"     "din"      "nh4"      "no23"    
#> [13] "po4"      "tdn"      "tdp"      "tn"       "tp"      
df1 <- unSurvDF(df)
colnames(df1)
#>  [1] "station"  "date"     "layer"    "secchi"   "salinity" "do"      
#>  [7] "wtemp"    "tss"      "chla_lo"  "chla_hi"  "din_lo"   "din_hi"  
#> [13] "nh4_lo"   "nh4_hi"   "no23_lo"  "no23_hi"  "po4_lo"   "po4_hi"  
#> [19] "tdn_lo"   "tdn_hi"   "tdp_lo"   "tdp_hi"   "tn_lo"    "tn_hi"   
#> [25] "tp_lo"    "tp_hi"   
# Default values
df2 <- makeSurvDF(df1)
colnames(df2)
#>  [1] "station"  "date"     "layer"    "secchi"   "salinity" "do"      
#>  [7] "wtemp"    "tss"      "chla"     "din"      "nh4"      "no23"    
#> [13] "po4"      "tdn"      "tdp"      "tn"       "tp"      
# User values
df3 <- unSurvDF(df, "_LOW", "_HIGH")
colnames(df3)
#>  [1] "station"   "date"      "layer"     "secchi"    "salinity"  "do"       
#>  [7] "wtemp"     "tss"       "chla_LOW"  "chla_HIGH" "din_LOW"   "din_HIGH" 
#> [13] "nh4_LOW"   "nh4_HIGH"  "no23_LOW"  "no23_HIGH" "po4_LOW"   "po4_HIGH" 
#> [19] "tdn_LOW"   "tdn_HIGH"  "tdp_LOW"   "tdp_HIGH"  "tn_LOW"    "tn_HIGH"  
#> [25] "tp_LOW"    "tp_HIGH"  
df4 <- makeSurvDF(df3, "_LOW", "_HIGH")
colnames(df4)
#>  [1] "station"  "date"     "layer"    "secchi"   "salinity" "do"      
#>  [7] "wtemp"    "tss"      "chla"     "din"      "nh4"      "no23"    
#> [13] "po4"      "tdn"      "tdp"      "tn"       "tp"