GenGeno Ex.8
For the following code, what would the output be? a <- c() vector1 <- c(1,2,3,4,5) for (i in vector1){ a <- append(a, i) } print(a)
1 2 3 4 5
What is the output of the following code? vct1 <- c(1,2,3,4) vct2 <- c() for (i in vct1){ if (i*i > 4 & 2*i < 8){ vct2 <- append(vct2, i) } }
3
For the following code, what would the output be? a <- 0 vector1 <- c(1,2,3,4,5) for (i in vector1){ if(i>1 & i<5){ a <- a + i} } print(a)
9
What is the missing piece of code, herein marked as "xxxxx"? vct1 <- c("dog", "cat", "mouse") for (xxxxx){ if (i == "cat"){ print("meow") } else{ print("cat is away") } }
i in vct1
How would save the output when calling the function Functy below, using 8 as the supplied argument? Functy <- function(arg1) { product <- (arg1*100) return (product) }
savedOutput <- Functy(8)
Why doesn't the following code work? vct1 <- c(1,2,3) for [i in vct1]{ print(i*2) } first line of expected output: 2
used square brackets instead of parentheses in the for statement
Export a data frame as a .csv file given that the data frame is named RNAcol and the output file should be named RNAcol.csv and you don't want spurious numbers in your first row.
write.csv(RNAcol, file = "RNAcol.csv", row.names = FALSE)
What is the output of the following code? vct1 <- c(1,2,3,4) Functy1 <- function(x){ return(x + 100) } sapply(vct1, Functy1)*vct1
101 204 309 416
For the following code, what would the second line of output be? vector1 <- c(1,2,3,4,5) for (i in vector1){ a <- 10*i + 100 print(a) }
120
What is the output of the following code? Functy <- function(vct1) { var1 <- 0 for (i in vct1){ var1 <- var1 + i } return (var1) } Functy(c(2,4,6,8))
20
What is the output of this code? Functy <- function(arg1, arg2) { print(arg1*2 + arg2*3) } Functy(4,10)
38
What is the output of this code? Functy <- function(arg1=10) { print(arg1*100) } Functy(4)
400
BactCount <- c() Sample <- 35 if (Sample > 50){ BactCount <- append(BactCount, Sample) What is the output of running the code if the second line reads: Sample <- 75
75
What does the last line do? BactCount <- append(BactCount, 0) } BactCount
It causes the values contained within the variable BactCount to be displayed
What does the first line do? if (Sample > 50){ BactCount <- append(BactCount, Sample)
Sets the condition that the value in Sample must be greater than 50 for the action in next line to be executed
What is the purpose of the top line? BactCount <- c() Sample <- 35
Sets up a vector to which you'll later add elements
What does the second line do? if (Sample > 50){ BactCount <- append(BactCount, Sample)
The value contained in Sample will be added to the vector BactCount
What do the parentheses () following the "if" command enclose?
conditions
What is the output of this code? Functy <- function(arg1) { return (arg1*100) } Functy()
error message