From e0788ffb7c0e93a52f7b7b3d88101434db1fa225 Mon Sep 17 00:00:00 2001 From: Lan Li Date: Thu, 11 Nov 2021 09:20:47 -0500 Subject: [PATCH 1/3] Lan submission --- .DS_Store | Bin 0 -> 6148 bytes .RData | Bin 0 -> 3166 bytes .Rhistory | 512 +++++++++++++++++++++++++++++++++++++++++++++++ Lan-answercode.R | 32 +++ 4 files changed, 544 insertions(+) create mode 100644 .DS_Store create mode 100644 .RData create mode 100644 .Rhistory create mode 100644 Lan-answercode.R diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0+&eHo&e!Hj)u zA^XW#Dx_qKEX|41#MmiWN+cvD(jjEc7Wqe}j-1YQo&Uf7^Iq3I@AE#-{XWnAzTfkG z*BB$sl((>Xh|6UGG#0E~27LX3Ev0}kax&9#lXV*VBZfOQ%4n`{sb^ji~CcRRVDQ8fDc znAt*MK)Ya3c&fp<$*DpUgphIa!a8`mxM3xIr3kFT!c-qjR#6xsvu;s+2jr+u9Lm!R zhn3ujNwEg9ZYjaME&*$YL2aqBKE7_?XGsodJN$P^V49PSb`%FUcfY@$j+TOXZA*zC z*Y~{;u)4tntuw#Se7x&Lsn|xdAyg1(SIS0(;J2p^06esN6rng`qrV6|v z-*51rfq@1_8kjeMi3ZlcQNoGxb;qIbc~uZwj=`O-9P)dK!MfaOp8QVV3`RyOPS z>0O4%8rxwV-7vCv6v}Z!BNzt&lG#+siNd$tmC@*_!}DR~Z(ho3@pEWN5s(iu1z_&m z@}E^tpX&BEdT!mz6&CK`&OL$5&LIKYo%t}5m4iy{3dCokX+v71;Wto1Fs1N3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.Rhistory @@ -0,0 +1,512 @@ +if(i>10) break +} +##2. +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +}i = i+1 +if(i>10) break +} +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +}i = i+1 +if(i>10) break +} +##2. +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +}i = i+1 +if(i>10) { +break +} +} +##2. +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +}i = i+1 +if(i>10) stop +} +if(i>10) stop +if(i>10) stop +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +} +##2. +i=0 +i = i+1 +if(i>10) stop +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +} +##2. +i=0 +##2. +i <- 1 +if(i>10){ +break +} +##2. +i <- 1 +if(i>10){ +break +} +if(i>10){ +break +} +} +break} +break +break} +} +?range +range(5) +range(1) +guess$i <- readline(prompt="your guess: ") +number <- sample(c(1:100),1) +} +##2. +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +} +i = i+1 +} +guess <- readline(prompt="your guess: ") +if(number=guess){ +print("correct!") +break +}else{ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +} +i = i+1 +} +if(number=guess){ +print("correct!") +break +}else{ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +} +##2. +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +} +i = i+1 +} +}else{ +print("correct!") +break +} +i = i+1 +} +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +} +i = i+1 +} +}else{ +print("correct!") +break +} +i = i+1 +} +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +i = i+1 +if(number == guess){ +print("correct!") +break +}else{ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +} +i = i+1 +} +89 +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +break +} +i = i+1 +} +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +break +} +i = i+1 +} +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +i = i+1 +if(number == guess){ +print("correct!") +break +}else{ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +} +i = i+1 +} +print("lower") +} +} +i = i+1 +} +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +i = i + 1 +if(number == guess){ +print("correct!") +break +}else{ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +} +} +}else{ +for(i in 1:10){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +} +} +if(number == guess){ +print("correct!") +break +}else{ +for(i in 1:10){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +} i = i+1 +} +if(number == guess){ +print("correct!") +break +}else{ +for(i in 1:10){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +} i = i+1 +} +if(number == guess){ +print("correct!") +break +}else{ +for(i in 1:10){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +} +i = i+1 +} +} +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +} +for(i in 1:10){ +number <- sample(c(1:100),1) +guess <- readline(prompt="your guess: ") +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +break +} +i = i+1 +} +83 +for(i in 1:10){ +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +} +i = i+1 +} +##2. +number <- sample(c(1:100),1) +for(i in 1:10){ +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +} +i = i+1 +} +##2. +number <- sample(c(1:100),1) +number +for(i in 1:10){ +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +break +} +i = i+1 +} +##2. +number <- sample(c(1:100),1) +number +for(i in 1:10){ +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +break +} +i = i+1 +} +##2. +number <- sample(c(1:100),1) +number +for(i in 1:10){ +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +break +} +i = i+1 +} +##2. game “guess my number”. +number <- sample(c(1:100),1) +for(i in 1:10){ +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ +if(number>guess){ +print("higher") +}else{ +print("lower") +} +}else{ +print("correct!") +break +} +i = i+1 +} +1 +1 +myMean<-function(x){ +n=length(x) +total=sum(x) +average=total/n +return(average) +} +myMean() +myMean(c(1:10)) +myMean(c(1:3)) +?return +##write a custom function that takes a series of numbers and returns half of the minimum value in the series +halfmin<-function(x){ +n=c(x) +min0.5 <- min(n)/2 +return(min0.5) +} +halfmin(100) +halfmin +halfmin(100,20,30) +##write a custom function that takes a series of numbers and returns half of the minimum value in the series +halfmin<-function(x){ +min0.5 <- min(x)/2 +return(min0.5) +} +halfmin(10,20,30) +halfmin(x=c(10,20,30)) +##2. change the function you just created to take an argument that allows the user to specify what to divide the minimum value in the series by; set a default value of 2 for that argument +halfmin<-function(x,y){ +min0.5 <- min(x)/y +y <- default.stringsAsFactors(2) +return(min0.5) +} +halfmin(10,2) +##2. change the function you just created to take an argument that allows the user to specify what to divide the minimum value in the series by; set a default value of 2 for that argument +dividemin<-function(vector,dividedby=2){ +y <- min(vector)/dividedby +return(miny) +} +dividemin(c(1,2,3),3) +dividemin(c(1,2,3),3) +##2. change the function you just created to take an argument that allows the user to specify what to divide the minimum value in the series by; set a default value of 2 for that argument +dividemin<-function(vector,dividedby=2){ +y <- min(vector)/dividedby +return(y) +} +dividemin(c(1,2,3),3) +dividemin(c(1,2,3)) +rm(list = ls()) +###if sth is missing in your local enviroment, R will serach the thing in global environment +#e.g. +x <- c(1,2,3) +halfmin() +##1. write a custom function that takes a series of numbers and returns half of the minimum value in the series +halfmin<-function(x){ +min0.5 <- min(x)/2 +return(min0.5) +} +halfmin() +###if sth is missing in your local enviroment, R will serach the thing in global environment +#e.g. +x <- c(1,2,3) +halfmin() +?lines +?length diff --git a/Lan-answercode.R b/Lan-answercode.R new file mode 100644 index 0000000..c1435be --- /dev/null +++ b/Lan-answercode.R @@ -0,0 +1,32 @@ +##1. Plot the score UWvMSU +setwd("/Users/lillian/Desktop/Biocomp_tutorial10/") +score <- read.table("UWvMSU_1-22-13.txt", header = TRUE) +MUSscore <- score[score$team == "MSU",] +UWscore <- score[score$team == "UW",] +dfMUS <- data.frame(MUSscore$time, cumsum(MUSscore$score)) +dfUW <- data.frame(UWscore$time,cumsum(UWscore$score)) + +plot(dfMUS,type="l",frame = TRUE, + col = "red", xlab = "time", ylab = "cumulative score") +lines(dfUW, col = "blue", type = "l", lty = 2) +legend("topleft", legend=c("MUS", "UW"), + col=c("red", "blue"), lty = 1:2, cex=0.8) + + +##2. game “guess my number”. +number <- sample(c(1:100),1) +for(i in 1:10){ +guess <- readline(prompt="your guess: ") +i = i+1 +if(number!=guess){ + if(number>guess){ + print("higher") + }else{ + print("lower") + } +}else{ + print("correct!") + break +} +i = i+1 +} From f108859265ead5518d469c5678a4ebfba1a8f989 Mon Sep 17 00:00:00 2001 From: Lan Li Date: Thu, 11 Nov 2021 10:47:13 -0500 Subject: [PATCH 2/3] modified sumbmit --- Lan-answercode.R | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Lan-answercode.R b/Lan-answercode.R index c1435be..683b73c 100644 --- a/Lan-answercode.R +++ b/Lan-answercode.R @@ -14,19 +14,17 @@ legend("topleft", legend=c("MUS", "UW"), ##2. game “guess my number”. -number <- sample(c(1:100),1) +number <- sample.int(100,1) for(i in 1:10){ -guess <- readline(prompt="your guess: ") -i = i+1 -if(number!=guess){ - if(number>guess){ - print("higher") + guess <- as.numeric(readline(prompt="your guess: ")) + if(number == guess){ + print("correct") + break }else{ + if(number > guess){ + print("higher") + }else{ print("lower") + } } -}else{ - print("correct!") - break -} -i = i+1 } From f630465878cdacab7fb8ce99c9bbaac32a4018f5 Mon Sep 17 00:00:00 2001 From: Lan Li Date: Thu, 11 Nov 2021 10:49:05 -0500 Subject: [PATCH 3/3] modified --- Lan-answercode.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lan-answercode.R b/Lan-answercode.R index 683b73c..3fa36c1 100644 --- a/Lan-answercode.R +++ b/Lan-answercode.R @@ -13,7 +13,7 @@ legend("topleft", legend=c("MUS", "UW"), col=c("red", "blue"), lty = 1:2, cex=0.8) -##2. game “guess my number”. +##2. game “guess my number” number <- sample.int(100,1) for(i in 1:10){ guess <- as.numeric(readline(prompt="your guess: "))