diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 0000000..43b8734 --- /dev/null +++ b/.Rhistory @@ -0,0 +1,512 @@ +# model for simulating muscle oxygen content depending on activity level (exercise) and heart rate +# model parameters; https://data-flair.training/blogs/r-vector/ +# 1 ml O2 is 1.43 mg O2 at Standard Temperature and Pressure +Oblood = 0.2*1.43 # mg O2 (ml blood)-1 +f = 0.7 # maximum fraction of oxygen transfered from blood to tissue +b = 0.0357 # ml blood /(beat 100 ml muscle)-1 +Odemand = 0.11*1.43 # mg O2 (100 ml muscle minute)-1 +Omax = 10 # max oxygen content in mg O2/100ml +timesteps = 120 # run each simulation for 120 timesteps (minutes) +O = numeric(timesteps) # vector for the results of the simulations of muscle oxygen content +O[1] = 5 # initial oxygen content for the models is 5 mg O2/100ml +# multiple model simulations follow to calculate muscle oxygen content +# with different input heart rates and activity levels for 120 minutes each; https://campus.datacamp.com/courses/intermediate-r-for-finance/loops-3?ex=9 +# and an initial muscle oxygen content of 5 mg O2 +# muscle oxygen content is updated each minute based on previous muscle oxygen content +# first simulation model inputs +Hrate = 68 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 1 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O[i-1]/Omax) +Demand = Odemand*Alevel +O[i] = O[i-1]+Supply-Demand +} +# second simulation model inputs +O2 = O #results of the second simulation of muscle oxygen content +Hrate = 56 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 2.5 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O2[i-1]/Omax) +Demand = Odemand*Alevel +O2[i] = O2[i-1]+Supply-Demand +} +# plot the results of each simulation to compare the change in muscle oxygen content over time +# depending on the input heart rate and activity level +# https://www.datacamp.com/community/tutorials/15-questions-about-r-plots +plot(O, type='l', xlab="Timestep (minute)", ylab="Oxygen Content (mg O2/100ml)", ylim=c(0, 10)) # first simulation results, line colored black +lines(O2, col='red') # second simulation results, line colored red +abline(h=1.2, lty=3) # draw a horizontal line at 1.2 = 1/(273*8.3e3)*1000*100*32; this assumes 100 ml skeletal muscle +legend("top", bty="n", inset=0, legend=c("Resting", "Active"), col=c("black", "red"), lty=1:1, cex=0.8, horiz = TRUE) +# model for simulating muscle oxygen content depending on activity level (exercise) and heart rate +# model parameters; https://data-flair.training/blogs/r-vector/ +# 1 ml O2 is 1.43 mg O2 at Standard Temperature and Pressure +Oblood = 0.2*1.43 # mg O2 (ml blood)-1 +f = 0.7 # maximum fraction of oxygen transfered from blood to tissue +b = 0.0357 # ml blood /(beat 100 ml muscle)-1 +Odemand = 0.11*1.43 # mg O2 (100 ml muscle minute)-1 +Omax = 10 # max oxygen content in mg O2/100ml +timesteps = 120 # run each simulation for 120 timesteps (minutes) +O = numeric(timesteps) # vector for the results of the simulations of muscle oxygen content +O[1] = 5 # initial oxygen content for the models is 5 mg O2/100ml +# multiple model simulations follow to calculate muscle oxygen content +# with different input heart rates and activity levels for 120 minutes each; https://campus.datacamp.com/courses/intermediate-r-for-finance/loops-3?ex=9 +# and an initial muscle oxygen content of 5 mg O2 +# muscle oxygen content is updated each minute based on previous muscle oxygen content +# first simulation model inputs +Hrate = 68 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 1 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O[i-1]/Omax) +Demand = Odemand*Alevel +O[i] = O[i-1]+Supply-Demand +} +# second simulation model inputs +O2 = O #results of the second simulation of muscle oxygen content +Hrate = 132 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 2.5 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O2[i-1]/Omax) +Demand = Odemand*Alevel +O2[i] = O2[i-1]+Supply-Demand +} +# plot the results of each simulation to compare the change in muscle oxygen content over time +# depending on the input heart rate and activity level +# https://www.datacamp.com/community/tutorials/15-questions-about-r-plots +plot(O, type='l', xlab="Timestep (minute)", ylab="Oxygen Content (mg O2/100ml)", ylim=c(0, 10)) # first simulation results, line colored black +lines(O2, col='red') # second simulation results, line colored red +abline(h=1.2, lty=3) # draw a horizontal line at 1.2 = 1/(273*8.3e3)*1000*100*32; this assumes 100 ml skeletal muscle +legend("top", bty="n", inset=0, legend=c("Resting", "Active"), col=c("black", "red"), lty=1:1, cex=0.8, horiz = TRUE) +# model for simulating muscle oxygen content depending on activity level (exercise) and heart rate +# model parameters; https://data-flair.training/blogs/r-vector/ +# 1 ml O2 is 1.43 mg O2 at Standard Temperature and Pressure +Oblood = 0.2*1.43 # mg O2 (ml blood)-1 +f = 0.7 # maximum fraction of oxygen transfered from blood to tissue +b = 0.0357 # ml blood /(beat 100 ml muscle)-1 +Odemand = 0.11*1.43 # mg O2 (100 ml muscle minute)-1 +Omax = 10 # max oxygen content in mg O2/100ml +timesteps = 120 # run each simulation for 120 timesteps (minutes) +O = numeric(timesteps) # vector for the results of the simulations of muscle oxygen content +O[1] = 5 # initial oxygen content for the models is 5 mg O2/100ml +# multiple model simulations follow to calculate muscle oxygen content +# with different input heart rates and activity levels for 120 minutes each; https://campus.datacamp.com/courses/intermediate-r-for-finance/loops-3?ex=9 +# and an initial muscle oxygen content of 5 mg O2 +# muscle oxygen content is updated each minute based on previous muscle oxygen content +# first simulation model inputs +Hrate = 68 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 1 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O[i-1]/Omax) +Demand = Odemand*Alevel +O[i] = O[i-1]+Supply-Demand +} +# second simulation model inputs +O2 = O #results of the second simulation of muscle oxygen content +Hrate = 135 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 2.5 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O2[i-1]/Omax) +Demand = Odemand*Alevel +O2[i] = O2[i-1]+Supply-Demand +} +# plot the results of each simulation to compare the change in muscle oxygen content over time +# depending on the input heart rate and activity level +# https://www.datacamp.com/community/tutorials/15-questions-about-r-plots +plot(O, type='l', xlab="Timestep (minute)", ylab="Oxygen Content (mg O2/100ml)", ylim=c(0, 10)) # first simulation results, line colored black +lines(O2, col='red') # second simulation results, line colored red +abline(h=1.2, lty=3) # draw a horizontal line at 1.2 = 1/(273*8.3e3)*1000*100*32; this assumes 100 ml skeletal muscle +legend("top", bty="n", inset=0, legend=c("Resting", "Active"), col=c("black", "red"), lty=1:1, cex=0.8, horiz = TRUE) +# model for simulating muscle oxygen content depending on activity level (exercise) and heart rate +# model parameters; https://data-flair.training/blogs/r-vector/ +# 1 ml O2 is 1.43 mg O2 at Standard Temperature and Pressure +Oblood = 0.2*1.43 # mg O2 (ml blood)-1 +f = 0.7 # maximum fraction of oxygen transfered from blood to tissue +b = 0.0357 # ml blood /(beat 100 ml muscle)-1 +Odemand = 0.11*1.43 # mg O2 (100 ml muscle minute)-1 +Omax = 10 # max oxygen content in mg O2/100ml +timesteps = 120 # run each simulation for 120 timesteps (minutes) +O = numeric(timesteps) # vector for the results of the simulations of muscle oxygen content +O[1] = 5 # initial oxygen content for the models is 5 mg O2/100ml +# multiple model simulations follow to calculate muscle oxygen content +# with different input heart rates and activity levels for 120 minutes each; https://campus.datacamp.com/courses/intermediate-r-for-finance/loops-3?ex=9 +# and an initial muscle oxygen content of 5 mg O2 +# muscle oxygen content is updated each minute based on previous muscle oxygen content +# first simulation model inputs +Hrate = 68 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 1 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O[i-1]/Omax) +Demand = Odemand*Alevel +O[i] = O[i-1]+Supply-Demand +} +# second simulation model inputs +O2 = O #results of the second simulation of muscle oxygen content +Hrate = 145 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 2.5 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O2[i-1]/Omax) +Demand = Odemand*Alevel +O2[i] = O2[i-1]+Supply-Demand +} +# plot the results of each simulation to compare the change in muscle oxygen content over time +# depending on the input heart rate and activity level +# https://www.datacamp.com/community/tutorials/15-questions-about-r-plots +plot(O, type='l', xlab="Timestep (minute)", ylab="Oxygen Content (mg O2/100ml)", ylim=c(0, 10)) # first simulation results, line colored black +lines(O2, col='red') # second simulation results, line colored red +abline(h=1.2, lty=3) # draw a horizontal line at 1.2 = 1/(273*8.3e3)*1000*100*32; this assumes 100 ml skeletal muscle +legend("top", bty="n", inset=0, legend=c("Resting", "Active"), col=c("black", "red"), lty=1:1, cex=0.8, horiz = TRUE) +# model for simulating muscle oxygen content depending on activity level (exercise) and heart rate +# model parameters; https://data-flair.training/blogs/r-vector/ +# 1 ml O2 is 1.43 mg O2 at Standard Temperature and Pressure +Oblood = 0.2*1.43 # mg O2 (ml blood)-1 +f = 0.7 # maximum fraction of oxygen transfered from blood to tissue +b = 0.0357 # ml blood /(beat 100 ml muscle)-1 +Odemand = 0.11*1.43 # mg O2 (100 ml muscle minute)-1 +Omax = 10 # max oxygen content in mg O2/100ml +timesteps = 120 # run each simulation for 120 timesteps (minutes) +O = numeric(timesteps) # vector for the results of the simulations of muscle oxygen content +O[1] = 5 # initial oxygen content for the models is 5 mg O2/100ml +# multiple model simulations follow to calculate muscle oxygen content +# with different input heart rates and activity levels for 120 minutes each; https://campus.datacamp.com/courses/intermediate-r-for-finance/loops-3?ex=9 +# and an initial muscle oxygen content of 5 mg O2 +# muscle oxygen content is updated each minute based on previous muscle oxygen content +# first simulation model inputs +Hrate = 68 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 1 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O[i-1]/Omax) +Demand = Odemand*Alevel +O[i] = O[i-1]+Supply-Demand +} +# second simulation model inputs +O2 = O #results of the second simulation of muscle oxygen content +Hrate = 150 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 2.5 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O2[i-1]/Omax) +Demand = Odemand*Alevel +O2[i] = O2[i-1]+Supply-Demand +} +# plot the results of each simulation to compare the change in muscle oxygen content over time +# depending on the input heart rate and activity level +# https://www.datacamp.com/community/tutorials/15-questions-about-r-plots +plot(O, type='l', xlab="Timestep (minute)", ylab="Oxygen Content (mg O2/100ml)", ylim=c(0, 10)) # first simulation results, line colored black +lines(O2, col='red') # second simulation results, line colored red +abline(h=1.2, lty=3) # draw a horizontal line at 1.2 = 1/(273*8.3e3)*1000*100*32; this assumes 100 ml skeletal muscle +legend("top", bty="n", inset=0, legend=c("Resting", "Active"), col=c("black", "red"), lty=1:1, cex=0.8, horiz = TRUE) +# model for simulating muscle oxygen content depending on activity level (exercise) and heart rate +# model parameters; https://data-flair.training/blogs/r-vector/ +# 1 ml O2 is 1.43 mg O2 at Standard Temperature and Pressure +Oblood = 0.2*1.43 # mg O2 (ml blood)-1 +f = 0.7 # maximum fraction of oxygen transfered from blood to tissue +b = 0.0357 # ml blood /(beat 100 ml muscle)-1 +Odemand = 0.11*1.43 # mg O2 (100 ml muscle minute)-1 +Omax = 10 # max oxygen content in mg O2/100ml +timesteps = 120 # run each simulation for 120 timesteps (minutes) +O = numeric(timesteps) # vector for the results of the simulations of muscle oxygen content +O[1] = 5 # initial oxygen content for the models is 5 mg O2/100ml +# multiple model simulations follow to calculate muscle oxygen content +# with different input heart rates and activity levels for 120 minutes each; https://campus.datacamp.com/courses/intermediate-r-for-finance/loops-3?ex=9 +# and an initial muscle oxygen content of 5 mg O2 +# muscle oxygen content is updated each minute based on previous muscle oxygen content +# first simulation model inputs +Hrate = 68 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 1 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O[i-1]/Omax) +Demand = Odemand*Alevel +O[i] = O[i-1]+Supply-Demand +} +# second simulation model inputs +O2 = O #results of the second simulation of muscle oxygen content +Hrate = 155 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 2.5 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O2[i-1]/Omax) +Demand = Odemand*Alevel +O2[i] = O2[i-1]+Supply-Demand +} +# plot the results of each simulation to compare the change in muscle oxygen content over time +# depending on the input heart rate and activity level +# https://www.datacamp.com/community/tutorials/15-questions-about-r-plots +plot(O, type='l', xlab="Timestep (minute)", ylab="Oxygen Content (mg O2/100ml)", ylim=c(0, 10)) # first simulation results, line colored black +lines(O2, col='red') # second simulation results, line colored red +abline(h=1.2, lty=3) # draw a horizontal line at 1.2 = 1/(273*8.3e3)*1000*100*32; this assumes 100 ml skeletal muscle +legend("top", bty="n", inset=0, legend=c("Resting", "Active"), col=c("black", "red"), lty=1:1, cex=0.8, horiz = TRUE) +# model for simulating muscle oxygen content depending on activity level (exercise) and heart rate +# model parameters; https://data-flair.training/blogs/r-vector/ +# 1 ml O2 is 1.43 mg O2 at Standard Temperature and Pressure +Oblood = 0.2*1.43 # mg O2 (ml blood)-1 +f = 0.7 # maximum fraction of oxygen transfered from blood to tissue +b = 0.0357 # ml blood /(beat 100 ml muscle)-1 +Odemand = 0.11*1.43 # mg O2 (100 ml muscle minute)-1 +Omax = 10 # max oxygen content in mg O2/100ml +timesteps = 120 # run each simulation for 120 timesteps (minutes) +O = numeric(timesteps) # vector for the results of the simulations of muscle oxygen content +O[1] = 5 # initial oxygen content for the models is 5 mg O2/100ml +# multiple model simulations follow to calculate muscle oxygen content +# with different input heart rates and activity levels for 120 minutes each; https://campus.datacamp.com/courses/intermediate-r-for-finance/loops-3?ex=9 +# and an initial muscle oxygen content of 5 mg O2 +# muscle oxygen content is updated each minute based on previous muscle oxygen content +# first simulation model inputs +Hrate = 68 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 1 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O[i-1]/Omax) +Demand = Odemand*Alevel +O[i] = O[i-1]+Supply-Demand +} +# second simulation model inputs +O2 = O #results of the second simulation of muscle oxygen content +Hrate = 160 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 2.5 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O2[i-1]/Omax) +Demand = Odemand*Alevel +O2[i] = O2[i-1]+Supply-Demand +} +# plot the results of each simulation to compare the change in muscle oxygen content over time +# depending on the input heart rate and activity level +# https://www.datacamp.com/community/tutorials/15-questions-about-r-plots +plot(O, type='l', xlab="Timestep (minute)", ylab="Oxygen Content (mg O2/100ml)", ylim=c(0, 10)) # first simulation results, line colored black +lines(O2, col='red') # second simulation results, line colored red +abline(h=1.2, lty=3) # draw a horizontal line at 1.2 = 1/(273*8.3e3)*1000*100*32; this assumes 100 ml skeletal muscle +legend("top", bty="n", inset=0, legend=c("Resting", "Active"), col=c("black", "red"), lty=1:1, cex=0.8, horiz = TRUE) +# model for simulating muscle oxygen content depending on activity level (exercise) and heart rate +# model parameters; https://data-flair.training/blogs/r-vector/ +# 1 ml O2 is 1.43 mg O2 at Standard Temperature and Pressure +Oblood = 0.2*1.43 # mg O2 (ml blood)-1 +f = 0.7 # maximum fraction of oxygen transfered from blood to tissue +b = 0.0357 # ml blood /(beat 100 ml muscle)-1 +Odemand = 0.11*1.43 # mg O2 (100 ml muscle minute)-1 +Omax = 10 # max oxygen content in mg O2/100ml +timesteps = 120 # run each simulation for 120 timesteps (minutes) +O = numeric(timesteps) # vector for the results of the simulations of muscle oxygen content +O[1] = 5 # initial oxygen content for the models is 5 mg O2/100ml +# multiple model simulations follow to calculate muscle oxygen content +# with different input heart rates and activity levels for 120 minutes each; https://campus.datacamp.com/courses/intermediate-r-for-finance/loops-3?ex=9 +# and an initial muscle oxygen content of 5 mg O2 +# muscle oxygen content is updated each minute based on previous muscle oxygen content +# first simulation model inputs +Hrate = 68 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 1 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O[i-1]/Omax) +Demand = Odemand*Alevel +O[i] = O[i-1]+Supply-Demand +} +# second simulation model inputs +O2 = O #results of the second simulation of muscle oxygen content +Hrate = 162 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 2.5 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O2[i-1]/Omax) +Demand = Odemand*Alevel +O2[i] = O2[i-1]+Supply-Demand +} +# plot the results of each simulation to compare the change in muscle oxygen content over time +# depending on the input heart rate and activity level +# https://www.datacamp.com/community/tutorials/15-questions-about-r-plots +plot(O, type='l', xlab="Timestep (minute)", ylab="Oxygen Content (mg O2/100ml)", ylim=c(0, 10)) # first simulation results, line colored black +lines(O2, col='red') # second simulation results, line colored red +abline(h=1.2, lty=3) # draw a horizontal line at 1.2 = 1/(273*8.3e3)*1000*100*32; this assumes 100 ml skeletal muscle +legend("top", bty="n", inset=0, legend=c("Resting", "Active"), col=c("black", "red"), lty=1:1, cex=0.8, horiz = TRUE) +# model for simulating muscle oxygen content depending on activity level (exercise) and heart rate +# model parameters; https://data-flair.training/blogs/r-vector/ +# 1 ml O2 is 1.43 mg O2 at Standard Temperature and Pressure +Oblood = 0.2*1.43 # mg O2 (ml blood)-1 +f = 0.7 # maximum fraction of oxygen transfered from blood to tissue +b = 0.0357 # ml blood /(beat 100 ml muscle)-1 +Odemand = 0.11*1.43 # mg O2 (100 ml muscle minute)-1 +Omax = 10 # max oxygen content in mg O2/100ml +timesteps = 120 # run each simulation for 120 timesteps (minutes) +O = numeric(timesteps) # vector for the results of the simulations of muscle oxygen content +O[1] = 5 # initial oxygen content for the models is 5 mg O2/100ml +# multiple model simulations follow to calculate muscle oxygen content +# with different input heart rates and activity levels for 120 minutes each; https://campus.datacamp.com/courses/intermediate-r-for-finance/loops-3?ex=9 +# and an initial muscle oxygen content of 5 mg O2 +# muscle oxygen content is updated each minute based on previous muscle oxygen content +# first simulation model inputs +Hrate = 68 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 1 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O[i-1]/Omax) +Demand = Odemand*Alevel +O[i] = O[i-1]+Supply-Demand +} +# second simulation model inputs +O2 = O #results of the second simulation of muscle oxygen content +Hrate = 164 # 50-200; heart rate beats per minute UPDATE YOUR HEARTRATE HERE +Alevel = 2.5 # 1 for rest and >2 for exercise; activity level of skeletal muscle +for(i in 2:length(O)){ +Supply = Oblood*Hrate*f*b*(1-O2[i-1]/Omax) +Demand = Odemand*Alevel +O2[i] = O2[i-1]+Supply-Demand +} +# plot the results of each simulation to compare the change in muscle oxygen content over time +# depending on the input heart rate and activity level +# https://www.datacamp.com/community/tutorials/15-questions-about-r-plots +plot(O, type='l', xlab="Timestep (minute)", ylab="Oxygen Content (mg O2/100ml)", ylim=c(0, 10)) # first simulation results, line colored black +lines(O2, col='red') # second simulation results, line colored red +abline(h=1.2, lty=3) # draw a horizontal line at 1.2 = 1/(273*8.3e3)*1000*100*32; this assumes 100 ml skeletal muscle +legend("top", bty="n", inset=0, legend=c("Resting", "Active"), col=c("black", "red"), lty=1:1, cex=0.8, horiz = TRUE) +install.packages(c("swirl","swirlify")) +install.packages("swirl") +library("siwrl") +library("swirl") +swirl() +swirl() +swirl() +library(swirl) +swirl() +library() +swirl() +library("swirl") +swirl() +swirl() +5+7 +x <- 5 + 7 +x +y <- x - 3 +y +c(1.1, 9, 3.14) +z <- (1.1, 9, 3.14) +z <- c(1.1, 9, 3.14) +?c +z +c(z, 555, z) +z * 2 + 100 +my_sqrt <- sqrt(z-1) +swirl() +my_sqrt +my_div <- z/my_sqrt +my_div +c(1, 2, 3, 4) + c(0, 10) +c( 1, 2, 3, 4) + c(0, 10, 100) +c( 1, 2, 3, 4) + c(0, 10, 1000) +c( 1, 2, 3, 4) + c(0, 10, 1000) +info() +c( 1, 2, 3, 4) + c(0, 10, 1000) +c( 1, 2, 3, 4) + c(0, 10, 1000) +c( 1, 2, 3, 4) + c(0, 10, 1000) +c( 1, 2, 3, 4) + c(0, 10, 1000) +info() +nxt() +z * 2 + 1000 +my_div +getwd() +ls() +x <- 9 +ls() +list.files() +?list.files +args(list.files()) +args(list.files) +old.dir <- wkdir +old.dir <- list.files +old.dir <- getwd() +dir.create(testdir) +dir.create("testdir") +setwd("testdir") +file.create("mytest.R") +ls("wkdir") +ls() +list.files() +ls +file.exists("mytest.R") +file.info("mytest.R") +file.rename("mytest.R") +file.rename("mytest.R") to "mytest2.R" +file.rename("mytest.R" to "mytest2.R") +file.rename("mytest.R" "to" "mytest2.R") +file.rename(mytest.R) +?file.rename +file.rename("mytest.R", to "mytest2.R") +file.rename("mytest.R", "mytest2.R") +file.copy(mytest2.R, mytest3.R) +file.copy("mytest2.R", "mytest4.R") +file.copy("mytest2.R", "mytest3.R") +file.path("mytest3.R") +file.path("folder1") +file.path("folder1", "folder2") +?dir.create +dir.create("testdir2") file.path("testdir3") +?file.path() +dir.create("testdir2" file.path("testdir3")) +dir.create(file.path("testdir2", "testdir3") +dir.create(file.path("testdir2", "testdir3")) +dir.create(file.path("testdir2", "testdir3")) +dir.create(file.path("testdir2", "testdir3"), recursive = TRUE) +setwd() +setwd(old.dir) +1:20 +pi:10 +15:1 +':' +?':' +seq(1,20) +seq(0, 10, by=0.5) +seq(5, 10, length=30) +my_seq <- seq(5, 10, length=30) +length("my_seq") +length(my_seq) +1:length(my_seq) +seq(along.with = my_seq) +seq_along(my_seq) +rep(0, times = 40) +rep(c(0, 1, 2), times =10) +rep(c(0 , 1, 2), each = 10) +num_vect(0.5, 55, -10, 6) +num_vect("0.5, 55, -10, 6") +c(0.5, 55, -10, 6) +?c +c(0.5, 55, -10, 6, recursive = FALSE) +<- num_vect c(0.5, 55, -10, 6) +num_vect <- c(0.5, 55, -10, 6) +tf <- num_vect < 1 +swirl() +swirl() +swirl() +swirl() +tf +num_vect >=6 +swirl() +my_char <- c("My", "name", "is") +my_char +paste(my_char, collapse = " ") +my_name <- c(my_char, "Emily") +my_name +paste(my_name, collapse = " ") +paste("Hello", "world!", sep = " ") +paste("1:3", c("X", "Y", "Z"), sep = "") +paste(1:3, c("X", "Y", "Z"), sep = "") +paste(LETTERS, 1:4, sep = "-") +dt=data.frame(a=c)1:4), +b=c(5:8), +c=c(9:12)) +dt=data.frame(a= c)1:4), +b = c(5:8), +c = c(9:12)) +dt=data.frame(a = c)1:4), +b = c(5:8), +c = c(9:12)) +dt = data.frame(a = c)1:4), +b = c(5:8), +c = c(9:12)) +dt=data.frame(a=c(1:4),) +dt=data.frame(a=c)1:4), +b=c(5:8), +c=c(9:12)) +dt=data.frame(a=c(1:4), +b=c(5:8), +c=c(9:12)) +sumMale +for(wages ) +source("~/.active-rstudio-document", echo=TRUE) +library(ggplot2) +library("ggplot2") +source("~/.active-rstudio-document", echo=TRUE) +install.packages("ggplot2") +install.packages(‘lifecycle’) +install.packages("lifecycle") +setwd("~/Downloads/Notre Dame/Biocomputing/Biocomp_tutorial11") +?function() diff --git a/dirfunction.R b/dirfunction.R new file mode 100644 index 0000000..ebd1c84 --- /dev/null +++ b/dirfunction.R @@ -0,0 +1,40 @@ + +# define the function +coefficient_of_var<-function(dir,column_num,nrow=50){ + +# set working directory and create CoV vector + setwd(dir) + dataset <- list.files(dir) + CoV_vector <- vector() + +# calculate reliable coefficient of variation + for(i in dataset){ + i <- read.csv(dataset[i]) + if (column_num > ncol(i)){ + print("not valid -- choose lower column_num") + } + else { + # Report error for file with less than 50 observations + if(nrow(i) < 50){ + print("error") + # Give option to override and continue with calculation + x <- readline("Would you like to override? Please enter 'yes' or 'no': ") + if (x == "yes"){ + print("Warning! Your file has less than 50 observations.") + # Calculate the coefficient of variation with an override + standard_dev<-sd(i[,column_num]) + average<-mean(i[,col]) + coeff_variation<-standard_dev/average + } else { + break + } + } else { + # Calculate the coefficient of variation for file with more than 50 obs + standard_dev<-sd(i[,column_num]) + average<-mean(i[,column_num]) + coeff_variation<-standard_dev/average + Cov_vector[i]<-coeff_variation + } + } + } return(CoV_vector) + } \ No newline at end of file