lundi 14 décembre 2015

Replace multiple "less than values" in different columns in R

I have a data frame for lab analysis of several parameters. Many values are below detection limit and are being reported as (< detection limit; e.g.<0.005)

The data frame looks like below

  varA     varB    varC     varD    varE    varF    varG
 0.024     0.69     .        .        .       .    <0.01 
 0.012     0.23                                     0.26  
<0.005     0.54                                     0.28                                   
 0.017     0.62                                     0.30
 0.016    <0.10                                     0.31
 0.018     0.34                                     0.24
 0.020     0.44                                    <0.01 
<0.005     0.52                                     0.24
 0.080    <0.10                                     0.25

I want to transform all values below detection limit using this formula

<detection limit  ====> detection limit/sqare root (2)

I did this for varA as below

df$varA1<-as.character(df$varA)
df$varA1<-ifelse(df$varA1=="<0.005", 0.005/sqrt(2), df$varA1)
df$varA2<-as.numeric(df$varA1)

I can do the same for other columns and other values below detection limits. However, it will be time taking given that my data is big.

Any suggestions how to change all values below detection limits in different columns in a fast way?

Aucun commentaire:

Enregistrer un commentaire