【R语言】基础知识点 Pop quiz
前言
在这里会有10道题,每一道都是对R语言的基础了解。
有单选题和填空题,答案在最下面。
填空题可以放到Rstudio里运行得出答案。
Question 1
Which one of these is a logical value in R?
其中哪一个是 R 中的逻辑值?(单选题)
- TRUE
- True
- true
Question 2
What does
2:4
do?
程序中2:4
是干什么的?(单选题)
- generates a vector with all integer values from 2 up to 4
- generates a function with all integer values from 2 up to 4
- generates a vector with all integer values from 2 up to 3
Question 3
Complete the code to return the output
完成代码以返回输出(填空题)
my_list <- list(5:6, c("A", "B"), 10:12)
【这里输入code】<- c("p", "q", "r")
my_list
=======输出========
$p
[1] 5 6
$q
[1] "A" "B"
$r
[1] 10 11 12
Question 4
Complete the code to return the output
完成代码以返回输出(单选题)
num_matrix <- matrix(1:9, byrow = TRUE, nrow = 3)
big_matrix <-【这里选择code】(num_matrix, rowSums(num_matrix))
big_matrix
=======输出==========
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
[4,] 6 15 24
- cbind
- rbind
- matrix
Question 5
Complete the code to return the output
完成代码以返回输出(单选题)
a <- c(1, 2, 3)
b <- c(4, 5, 6)
c <- a 【这里选择code】b
c
========输出=========
[1] 5 7 9
- ++
- +
- *
Question 6
what is an ordered factor vector helpful for?
什么是有序因子向量有助于?(单选题)
- Ordered factors have equal values attached to theme
- It enables us to compare different elements
- R throws a warning message when comparison is made.
Question 7
Which of the following selects the first element of the vector
y
?
以下哪个选择了向量y
的第一个元素(单选题)
- y[1]
- y[1 , 1]
- y[0]
- y[“1”]
Question 8
When selecting items from a matrix, what is used to separate the rows you want to select from the columns?
从矩阵中选择项目时,用什么将要选择的行与列分开?(单选题)
- ,
- .
- :
Question 9
Select those element of a vector
a
that have the namesMonday
andTuesday
选择向量“a”中名称为“Monday”和“Tuesday”的元素
- a[c(Monday , Tuesday)]
- a["Monday , “Tuesday”]
- a[c(“Monday” , “Tuesday”)]
Question 10
Complete the code to return the output
完成代码以返回输出(填空题)
x <- c(1 , 1 , 1)
# 将 x 中的所有元素相加
【选择下列code】(x)
- add
- mean
- sum
- total
是兄弟就砍一刀!
温故而知新
答案
Q1:TRUE
Q2:generates a vector with all integer values from 2 up to 4
Q3:names(my_list)
Q4:rbind
Q5:+
Q6:It enables us to compare different elements
Q7:y[1]
Q8:,
Q9:a[c("Monday" , "Tuesday")]
Q10:sum