forked from ashtonbieri/Biocomp-Exercise09
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex9Script.R
More file actions
30 lines (28 loc) · 834 Bytes
/
Copy pathex9Script.R
File metadata and controls
30 lines (28 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Exercise 9
#Loan Duong
#Write a function that reads data from each file in a directory and gives the coefficient
#of variation for a user specified column as a vector.
#Report error if less than 50 obs, but allow override.
Dir_CoVs<-function(directory, column_name, nrow=50){
for (i in files){
read.csv(file, header=TRUE, sep=",", stringsAsFactors = FALSE)
if(nrow<50){
print("Not enough observations.")
override<-readline(prompt="Continue anyways? Y/N")
if(override=Y){
stdev<-sd(i[,column_name])
mean<-mean(i[,column_name])
CoV=stdev/mean
CoVvector<-c(CoV)
}else{
print("Terminating program")
}
}else{
stdev<-sd(i[,column_name])
mean<-mean(i[,column_name])
CoV=stdev/mean
vector<-c(CoV)
}
print(CoVvector)
}
}