Professional Documents
Culture Documents
Email deneme@ufuk.com
StudentID 2099111000
Email deneme@ufuk.com
21
Which of the following can be used to print only 3 to the console? my.list[[3]][[1]][[1]][[1]][[1]]
my.list <- list(vec1 = c(1,2), vec2 = c(3,4),list(list(list(list(3),
c(1:2))))) my.list[[3]][[1]][[1]]
my.list[[2]]
my.list[[1]][[3]][[1]][[1]]
I have a numeric vector. Which one of the following functions can be used to obtain the ii
average of the numbers in the vector?
i. str i,ii
ii. summary
i
iii. factor
i, ii, iii
Which of the following does the increment (by 10) and also ensures that nobody will have a
final score higher than 100? finals[finals > midterms] <-
The instructor of cmpe 140 course is impressed by the performance of students such that finals[finals > midterms] + 10
he/she wants to add extra 10 points to the final scores of everyone whose final score is finals[finals > 100] <- 100
higher than his/her midterm score. Final and midterm scores are stored in the vectors named
“finals” and “midterms”.
finals[finals > midterms,] <-
ifelse(finals - midterms < 0, +10, 0)
finals[finals > 100,] <- 100
Which one of the codes below would be the best choice? hist(random1000,breaks=seq(-4,4,0.25))
The code above is executed in R. I want this data to look more accurate, in the sense that I
want to observe more data points in the histogram. Which one of the codes below would be hist(random1000,breaks=seq(-4,4,1))
the best choice?
hist(random1000,breaks=c(-4,4,0.25))
random1000 <- rnorm(1000)
hist(random1000) hist(random1000,breaks=c(-4,4,1))
Which of the following is false?
The ages of 13 children in a neighborhood are assigned to a vector named “ages”:
ages <- c(7,8,8,9,10,12,13,14,15,15,16,16,17)
Here is the boxplot that summarizes the data: The bold line segment corresponds to 12.3
since it is the mean of the data set.
[1] 2,3,4,5,6
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
Which of the following data sets would yield the box plot below?
c(2,2,4,6,6,6,8,8)
c(2,3,4,6,6,6,7,8)
c(2,2,4,5,6,7,8,8)
c(2,3,6,6,6,6,7,8)
III.
x <- x[2]<x[5]
x <- x[5]<-x[2]
II, IV
IV. x <- x[order(1,5,3,4,2)]
V. x <- x[c(1,5,3,4,2)]
mean(lapply(newlist,mean))
sapply(newlist,mean)
Which one(s) is/are true?
We have a list called mylist. I
mylist <- list(v1=c(1,2), v2=c(3,4), v3=c(5,6))
I.
mylist[[3]]
[1] 5 6 I-II-III-IV
II.
mylist[[“3”]]
Error
III. II-III
mylist[“v1”]
[1] 1 2
IV.
mylist[1][1] I-II
[1] 1
Which of the followings are FALSE for lists? cbind can be used to add a new column.
plot(person.data[,2:5],col=ifelse(person.data$BMI
>22.5,"green","red"))
plot(person.data[1,4],col=ifelse(person.data$abov
e22.5,"red","green"))
Which graph is obtained by the following code?
y <- c(1:100)
x <- c(1:100)
for(i in 1:100){
y[i] <- x[i]*x[i]-100*x[i]+2500}
plot(y,x)
The plot below is obtained by the code below. What should be A and B values based on your
linear regression knowledge? A=-1.5, B=0.5
y <- c(1:100)
x <- c(1:100)
x <- c(1:100)
for(i in 1:100){
y[i] <- 2*x[i]+3} A=3, B=2
model <- lm(x~y)
model
A=0, B=2
A=0, B=0.5
lines(myModel,col="red")
plot(myModel,col="red")
lines(x,y,col="red")
We want to explain y values by using x and z values. Which of the code scripts generates myModel <- lm(y~x+z, data=df)
right model?
x <- sample(1:20,20)+rnorm(10,sd=2) myModel <- lm(y~x~z, data=df)
y <- x+rnorm(10,sd=3)
myModel <- lm(y,x,z, data=df)
z <- (sample(1:20,20)/2)+rnorm(20,sd=5)
df <- data.frame(z,y,x) myModel <- lm(y+x+z, data=df)
When the code below is executed we obtain the graph below. What is x equal to?
par(mfrow=c(1,3))
c(1,2,1,3)
pie(x)
barplot(x)
boxplot(x)
c(1,1,2,3)
c(3,2,1,1)
c(1,2,2,3,4,4,4)
Which statement is false? scan() can read any text file that contain
letters and numbers
Given the information below, Which one is the correct coding to get this output? scan("mytext.txt", what="", sep="\n")
Say we have the following text file, mytext.txt: scan("mytext.txt", sep="", what="\n")
1 2 3
a b 36 read.table("mytext.txt", header=FALSE,what="",
6.6 xyz sep="\n")
You have information about bank accounts of 20 people as vector "first_bank" and One of the vectors is recycled. So you should
"great_bank". When you sum them and assign the value to the vector "net", you received the check the lengths of your data.
warning message below, though the vector "net" has been created with 20 numerical
values.Which of the following is a reasonable explanation for the warning message? "net" is too short to be a vector name. Besides, it
is not descriptive enough. You should rename it
Warning message: according to the name conventions.
In first_bank + great_bank : You tried to execute a "multiple summation"
longer object length is not a multiple of shorter object length operation with two vectors which are not multiple
of each other. You should use ordinary summation
to get the values.
1,2,6,15,8
Which of the following codes gives me only "Adam" column? hint: "&" indicate the logical i,iii
operations AND
Given: person.vector <- c(George=40,Judy=35,Jane=25,Adam=30) i,ii,iii
i) person.vector[person.vector>25 & person.vector<35]
i,ii
ii) person.vector[-c(-1,-2,-3)]
iii) person.vector[c(FALSE,FALSE,FALSE,TRUE)] ii,iii
Which of the following codes can create matrix below?
i,ii
[,1] [,2] [,3]
[1,] 1 7 13
[2,] 3 9 15 i,iii
[3,] 5 11 17
i)matrix(c(seq(1,11,2),13,15,17),nrow=3,byrow=F) ii,iv
ii)cbind(c(1,3,5),c(7,9,11),c(13,15,17))
iii)rbind(c(1,3,5),c(7,9,11),c(13,15,17))
iii,iv
iv)matrix(seq(1,17,2),nrow=3,byrow=T)
In order to update their new scores in the scores matrix, which of the following codes is
correct? scores[c(1,2,4),"GRE"] <- c(335,338,333)
scores matrix is defined as follows: scores["Tirole",3] <- 790
4 students' SAT, GRE and GMAT scores are given in the matrix above. scores[c(Nash,Shapiro,Tirole),2] <-c(335,338,333)
Nash was not satisfied with his GRE score, and talked to Shapiro who scores["Tirole",3] <- 790
is also not satisfied with his GRE scores.
They decided to take these exams again.And also Tirole decided to take
both GRE and GMAT exam.
A couple of weeks later their new scores announced. Nash got 335, scores[c(1,2,4),c("GRE","GMAT")] <-
Shapiro raised his score to 338, Tirole got 333 from GRE and 790 from c(335,338,333,790)
GMAT
We would like to add a row to the matrix (given below) which contains sum of each fruit. rbind(mymatrix,"Total"=apply(mymatrix,2,su
Which of the following code can add a new row we want? m))
Apple Orange Mango
Einstein 10 2 12 cbind(mymatrix,"Total"=apply(mymatrix,2,sum))
Newton 20 4 45
rbind(mymatrix,"Total"=apply(mymatrix,1,add))
Descartes 30 6 21
rbind(mymatrix,"Total"=apply(mymatrix,1,add))