From 044966d72fc58d8234d0a5837c6744cb48a136f5 Mon Sep 17 00:00:00 2001 From: Helen Laboe Date: Mon, 15 Nov 2021 18:26:56 -0500 Subject: [PATCH 1/5] Getting started on Exercise09 --- Exercise09.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Exercise09.R diff --git a/Exercise09.R b/Exercise09.R new file mode 100644 index 0000000..dae7c06 --- /dev/null +++ b/Exercise09.R @@ -0,0 +1,13 @@ +### Biocomputing Exercise09 - Pulling the R pieces together + +# Create the coefficient of variation vector +coefficientofvariationVector = vector(mode="numeric", 0) + +# Set a working directory +setwd(dir) +inputfiles<-list.files(dir) + +# Sets up a loop for the files in the directory to calculate the coefficient of variation +for (file in inputfiles){ + file<- read.table(file, header=TRUE, sep=",", stringsAsFactors = FALSE) +} \ No newline at end of file From a4f0944d9bf08155824a0bd050ad579b7e95fb5b Mon Sep 17 00:00:00 2001 From: Helen Laboe Date: Wed, 17 Nov 2021 22:41:36 -0500 Subject: [PATCH 2/5] Script for Exercise09 --- Exercise09.R | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/Exercise09.R b/Exercise09.R index dae7c06..2de94ea 100644 --- a/Exercise09.R +++ b/Exercise09.R @@ -1,13 +1,39 @@ ### Biocomputing Exercise09 - Pulling the R pieces together -# Create the coefficient of variation vector -coefficientofvariationVector = vector(mode="numeric", 0) +# Defining the function +CoefficientofVariation <- function(dir,col,nrow=50){ + + # Set a working directory and create the Coefficient of Variation vector + setwd(dir) + inputfiles<-list.files(dir) + coefficientofvariationVector <- numeric(0) + + # Sets up a loop for the files in the directory to calculate the coefficient of variation + for (i in inputfiles){ + i <- read.csv(i,header=TRUE,sep=",",stringsAsFactors=FALSE, fill=TRUE) + if(ncol(i)< col){ + print("Invalid column number.") + }else{ + if(nrow(i) <50){ + not50 <- print("Recommended that the file has at least 50 observations to calculate a coefficient of variation. Would you like to proceed? Type 'Y' for Yes and 'N' for No: ") + if(not50=="Y"){ + mean=mean(i[,col]) + standarddeviation=sd(i[,col]) + coefficientofvariation=standarddeviation/mean + coefficientofvariationVector=c(coefficientofvariationVector,coefficientofvariation) + }else{ + print("Function stopped.") + } + }else{ + mean=mean(i[,col]) + standardeviation=sd(i[,col]) + coefficientofvariation=standardeviation/mean + coefficientofvariationVector=c(coefficientofvariationVector,coefficientofvariation) + } + } + } + + return(coefficientofvariationVector) +} -# Set a working directory -setwd(dir) -inputfiles<-list.files(dir) -# Sets up a loop for the files in the directory to calculate the coefficient of variation -for (file in inputfiles){ - file<- read.table(file, header=TRUE, sep=",", stringsAsFactors = FALSE) -} \ No newline at end of file From 16d16603db332c1a09804e58e74a5b3ab19ea690 Mon Sep 17 00:00:00 2001 From: hlaboe <91484525+hlaboe@users.noreply.github.com> Date: Wed, 17 Nov 2021 22:46:28 -0500 Subject: [PATCH 3/5] Delete Exercise09.R --- Exercise09.R | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 Exercise09.R diff --git a/Exercise09.R b/Exercise09.R deleted file mode 100644 index 2de94ea..0000000 --- a/Exercise09.R +++ /dev/null @@ -1,39 +0,0 @@ -### Biocomputing Exercise09 - Pulling the R pieces together - -# Defining the function -CoefficientofVariation <- function(dir,col,nrow=50){ - - # Set a working directory and create the Coefficient of Variation vector - setwd(dir) - inputfiles<-list.files(dir) - coefficientofvariationVector <- numeric(0) - - # Sets up a loop for the files in the directory to calculate the coefficient of variation - for (i in inputfiles){ - i <- read.csv(i,header=TRUE,sep=",",stringsAsFactors=FALSE, fill=TRUE) - if(ncol(i)< col){ - print("Invalid column number.") - }else{ - if(nrow(i) <50){ - not50 <- print("Recommended that the file has at least 50 observations to calculate a coefficient of variation. Would you like to proceed? Type 'Y' for Yes and 'N' for No: ") - if(not50=="Y"){ - mean=mean(i[,col]) - standarddeviation=sd(i[,col]) - coefficientofvariation=standarddeviation/mean - coefficientofvariationVector=c(coefficientofvariationVector,coefficientofvariation) - }else{ - print("Function stopped.") - } - }else{ - mean=mean(i[,col]) - standardeviation=sd(i[,col]) - coefficientofvariation=standardeviation/mean - coefficientofvariationVector=c(coefficientofvariationVector,coefficientofvariation) - } - } - } - - return(coefficientofvariationVector) -} - - From e565db539b75e77c1f107917102c9d62f141a930 Mon Sep 17 00:00:00 2001 From: Helen Laboe Date: Wed, 17 Nov 2021 22:48:01 -0500 Subject: [PATCH 4/5] This is the script for Exercise09 --- Exercise09.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Exercise09.R b/Exercise09.R index 2de94ea..34e4686 100644 --- a/Exercise09.R +++ b/Exercise09.R @@ -2,8 +2,8 @@ # Defining the function CoefficientofVariation <- function(dir,col,nrow=50){ - - # Set a working directory and create the Coefficient of Variation vector + + # Set a working directory and create the Coefficient of Variation vector setwd(dir) inputfiles<-list.files(dir) coefficientofvariationVector <- numeric(0) @@ -35,5 +35,7 @@ CoefficientofVariation <- function(dir,col,nrow=50){ return(coefficientofvariationVector) } + + From f655427130b64dd910e088d40b4f75f149a5b6e2 Mon Sep 17 00:00:00 2001 From: Helen Laboe Date: Wed, 17 Nov 2021 22:57:24 -0500 Subject: [PATCH 5/5] Adding commentary --- Exercise09.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Exercise09.R b/Exercise09.R index 34e4686..51b638e 100644 --- a/Exercise09.R +++ b/Exercise09.R @@ -11,10 +11,13 @@ CoefficientofVariation <- function(dir,col,nrow=50){ # Sets up a loop for the files in the directory to calculate the coefficient of variation for (i in inputfiles){ i <- read.csv(i,header=TRUE,sep=",",stringsAsFactors=FALSE, fill=TRUE) + # Checking if the file has the correct number of columns if(ncol(i)< col){ print("Invalid column number.") }else{ + # Checking if the column has 50 observations if(nrow(i) <50){ + # Offers the override option if the column does not have 50 observations not50 <- print("Recommended that the file has at least 50 observations to calculate a coefficient of variation. Would you like to proceed? Type 'Y' for Yes and 'N' for No: ") if(not50=="Y"){ mean=mean(i[,col]) @@ -22,6 +25,7 @@ CoefficientofVariation <- function(dir,col,nrow=50){ coefficientofvariation=standarddeviation/mean coefficientofvariationVector=c(coefficientofvariationVector,coefficientofvariation) }else{ + # Output if the user chooses not to override print("Function stopped.") } }else{