Mercurial > repos > yguitton > withinvariation
comparison withinvariation-26603602a823/transformation_script.R @ 0:5086ad0c0992 draft default tip
Uploaded v0.4
author | yguitton |
---|---|
date | Fri, 05 May 2017 05:04:36 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5086ad0c0992 |
---|---|
1 ## Etienne Thevenot | |
2 ## W4M Core Development Team | |
3 ## etienne.thevenot@cea.fr | |
4 ## 2015-04-25 | |
5 | |
6 transformF <- function(datMN, | |
7 metC) { | |
8 | |
9 ## options | |
10 | |
11 optStrAsFacL <- options()[["stringsAsFactors"]] | |
12 options(stringsAsFactors = FALSE) | |
13 | |
14 ## checking | |
15 | |
16 if(length(which(datMN < 0))) { | |
17 cat("\nThe 'dataMatrix' contains negative values\n") | |
18 sink() | |
19 stop("The 'dataMatrix' contains negative values", call. = FALSE) | |
20 } | |
21 | |
22 ## Number of missing values | |
23 nasN <- length(which(is.na(datMN))) | |
24 cat("\nMissing values in the 'dataMatrix': ", | |
25 nasN, | |
26 " (", | |
27 round(nasN / cumprod(dim(datMN))[2] * 100), | |
28 "%)\n", | |
29 sep="") | |
30 | |
31 ## Number of zero values | |
32 zerN <- length(which(datMN == 0)) | |
33 cat("\nZero values in the 'dataMatrix': ", | |
34 zerN, | |
35 " (", | |
36 round(zerN / cumprod(dim(datMN))[2] * 100), | |
37 "%)\n", | |
38 sep="") | |
39 | |
40 ## transformation | |
41 | |
42 switch(metC, | |
43 log2 = { | |
44 | |
45 cat("\n'log2' transformation\n", sep="") | |
46 | |
47 trfMN <- log2(1 + datMN) | |
48 | |
49 }, | |
50 log10 = { | |
51 | |
52 cat("\n'log10' transformation\n", sep="") | |
53 | |
54 trfMN <- log10(1 + datMN) | |
55 | |
56 }, | |
57 sqrt = { | |
58 | |
59 cat("\n'Square root' transformation\n", sep="") | |
60 | |
61 trfMN <- sqrt(datMN) | |
62 | |
63 | |
64 }) ## end of method | |
65 | |
66 | |
67 ## returning | |
68 | |
69 options(stringsAsFactors=optStrAsFacL) | |
70 | |
71 return(trfMN) | |
72 | |
73 } ## end of transformF |