A data frame may contain variables that have different modes.
A data frame may contain variables of different lengths.
Q2. What value does this statement return?
unclass(as.Date("1971-01-01"))
1
365
4
12
Q3. What do you use to take an object such as a data frame out of the workspace?
remove()
erase()
detach()
delete()
Q4. Review the following code. What is the result of line 3?
xvect<-c(1,2,3)
xvect[2] <- "2"
xvect
[1] 1 2 3
[1] “1” 2 “3”
[1] “1” “2” “3”
[1] 7 9
Q5. The variable height is a numeric vector in the code below. Which statement returns the value 35?
height(length(height))
height[length(height)]
height[length[height]]
height(5)
Q6. In the image below, the data frame is named rates. The statement sd(rates[, 2]) returns 39. As what does R regard Ellen’s product ratings?
sample with replacement
population
trimmed sample
sample <-- not sure
Q7. Which choice does R regard as an acceptable name for a variable?
Var_A!
\_VarA
.2Var_A
Var2_A
Q8. What is the principal difference between an array and a matrix?
A matrix has two dimensions, while an array can have three or more dimensions.
An array is a subtype of the data frame, while a matrix is a separate type entirely.
A matrix can have columns of different lengths, but an array’s columns must all be the same length.
A matrix may contain numeric values only, while an array can mix different types of values.
Q9. Which is not a property of lists and vectors?
type
length
attributes
scalar
Q10. In the image below, the data frame on lines 1 through 4 is named StDf. State and Capital are both factors. Which statement returns the results shown on lines 6 and 7?
StDf[1:2,-3]
StDf[1:2,1]
StDf[1:2,]
StDf[1,2,]
Q11. Which function displays the first five rows of the data frame named pizza?
BOF(pizza, 5)
first(pizza, 5)
top(pizza, 5)
head(pizza, 5)
Q12. You accidentally display a large data frame on the R console, losing all the statements you entered during the current session. What is the best way to get the prior 25 statements back?
console(-25)
console(reverse=TRUE)
history()
history(max.show = 25)
Q13. d.pizza is a data frame. It’s a column named temperature contains only numbers. If you extract temperature using the [] accessors, its class defaults to numeric. How can you access temperature so that it retains the class of data.frame?
> class( d.pizza[ , "temperature" ] )
> "numeric"
class( d.pizza( , "temperature" ) )
class( d.pizza[ , "temperature" ] )
class( d.pizza$temperature )
class( d.pizza[ , "temperature", drop=F ] )
Q14. What does c contain?
a <- c(3,3,6.5,8)
b <- c(7,2,5.5,10)
c <- a < b
[1] NaN
[1] -4
[1] 4 -1 -1 2
[1] TRUE FALSE FALSE TRUE
Q15. Review the statements below. Does the use of the dim function change the class of y, and if so what is y’s new class?
Vectors are used only for numeric data, while lists are useful for both numeric and string data.
Vectors and lists are the same thing and can be used interchangeably.
A vector contains items of a single data type, while a list can contain items of different data types.
Vectors are like arrays, while lists are like data frames.
Q18. What statement shows the objects on your workspace?
list.objects()
print.objects()
getws()
ls()
Q19. What function joins two or more column vectors to form a data frame?
rbind()
cbind()
bind()
coerce()
Q20. Review line 1 below. What does the statement in line 2 return?
1 mylist <- list(1,2,"C",4,5)
2 unlist(mylist)
[1] 1 2 4 5
“C”
[1] “1” “2” “C” “4” “5”
[1] 1 2 C 4 5
Q21. What is the value of y in this code?
x <- NA
y <- x/1
Inf
Null
NaN
NA
Q22. Two variable in the mydata data frame are named Var1 and Var2. How do you tell a bivariate function, such as cor.test, which two variables you want to analyze?
cor.test(Var1 ~ Var2)
cor.test(mydata$(Var1,Var2))
cor.test(mydata$Var1,mydata$Var2)
cor.test(Var1,Var2, mydata)
Q23. A data frame named d.pizza is part of the DescTools package. A statement is missing from the following R code and an error is therefore likely to occur. Which statement is missing?
it premultiplies the current netwmat row by the newmat column.
it returns the results of a matrix multiplication
It squares each cell in mtrx
>newmat[,1][,2][1,]925[2,]6416# The `%*%` operator gives matrix multiplication>mtrx%*%mtrx[,1][,2][1,]4935[2,]5656
Q35. Which function in R combines different values into a single object?
connect()
concat()
contact()
c()
Q36. Which file contains settings that R uses for all users of a given installation of R?
Rdefaults.site
Renviron.site
Rprofile.site
Rstatus.site
Q37. If mdf is a data frame, which statement is true ?
ncol(mdf) equals length(mdf).
The number of rows must equals the number of columns.
The legnth of any column in mdf may differ from any other column in mdf
All columns must have the same data type.
Q38. A list can contain a list as an element. MyList has five columns, and the third column’s item is a list of three items. How do you put all seven values in MyList into a single vector?
vector(MyList, length = 7)
coerce(MyList, nrows = 1)
unlist(MyList)
coerce(MyList, nrows = 7)
Q39. Which strings could be returned by the function ls(path = “^V”)?
ANOVAData, anovadata
VisitPCA, VarX
VisitPCA, varx
Xvar, Yvar
Q40. StDf is a data frame. Based on this knowledge, what does this statement return?
StDf[,-1]
all but the first row and first column of StDf
all but the final column of StDf
all but the first column of StDf
only the first column of StDf
Q41. Which statement enables you to interactively open a single file?
file.list()
file.select()
file.choose()
file.open()
Q42. How are these data types alike: logical, integer, numeric, and character?
Each is a type of data frame.
Each is a type of atomic vector.
Each is a type of complex vector.
Each is a type of raw vector.
Q43. What does the MyMat[ ,3] subsetting operation return for this code?
It forces the intercepts of the individual regressions to zero.
It calls for the effect of the covariate within each level of the factor.
It calls for the effect of each variable from covariate to factor in testcoef.
It forces the covariate to enter the equation before the factor levels.
# Example call to demonstrate. `Species` is a Factor. Petal.Length, Petal.Width are numeric.# see `help(formula)` for more details on the formula specification. `:` is "effect modification" or "interaction">summary(lm(Petal.Length~Petal.Width+Species+Petal.Width:Species,data=iris))...Petal.Width:Speciesversicolor1.32280.55522.3820.0185*Petal.Width:Speciesvirginica0.10080.52480.1920.8480...
Q46. A variable whose type is numeric can contain which items?
integers and real values
integers, real, and raw values
real values only
integers, real, and logical values
Q47. What is the legitimate name of a data class in R?
property
integer
number
variant
Q48. How do you extract the values above the main diagonal from a square matrix named Rmat?
Rmat[upper.tri(Rmat)]
upper.triangular(Rmat)
upper.tri(Rmat)
upper.diag(Rmat)
Q49. x is a vector of type integer, as shown on line 1 below. What is the type of the result returned by the statement > median(x)?
Q58. A data frame contains two factor -fact1 and fact2- and a numerical outcome variable. Which statement returns results that do NOT include an interaction term?
Q59. Review line 1 below. What does the statement on line 2 return?
1myvect<-c(-2,-1,0)2as.logical(myvect)
[1]-2 -1 0
[1]TRUE TRUE FALSE
[1]FALSE FALSE TRUE
[1]NA NA NA
Q60. Which option setting can cause difficulty if you want to add to a variable’s possible values after you have designed an object’s initial data structure?
()OPTIONS(colnames(x)<-NULL)
()OPTIONS(max.print=5)
()OPTIONS(continue=”… “,
()OPTIONS(stringAsFactors=TRUE
Q61. In this image below, the data frame on lines 1 through 4 is named StDf. StDf contains no factors. Why does statement on line 6 return “character” while the statement on line 7 returns “data.frame”?
Each value in the first row is a character value, but the values in the third column include both character and numeric values.
By specifying the final row, 3, and no column specified, StDf[3, ] calls for the complete structure.
Columns in a data frame are vectors generally containing a single type of data. Rows in a data frame are lists, but they belong to a structure that has multiple rows: the data frame.
Each value in the first column is a character value, but the values in the third row include both character and numeric values.
Q62. Review line 1. What does the statement on line 3 return?
mtrx<-matrix(1:6,3,2)mtrx[,-1]
[1] 4 5 6
Q63. Why does sum(!is.na(pizza$week)) return the number of rows with valid, non-NA values in the column named week?
The exclamation point in !is.na(pizza$week) reverses the meaning of the test it precedes.
!is.na(pizza$week) counts the number of NA values in the column.
!is.na(pizza$week) returns a vector of TRUE/FALSE values, in which TRUE is treated as a 0 and FALSE as a 1.
!is.na(pizza$week) counts the number of non-missing values in the column.
Q64. How do you get documentation of an installed and loaded R package named dplyr and packages with dplyr as an alias?
help(dplyr)
? dplyr
?? dplyr
Press the F1 key.
Q65. In the image below, the data frame named iris includes a numeric vector named Petal.Length. Do the functions labeled Pair 1 and Pair 2 return the same information?
No, both the length and the class of the returned structures are different.
Yes, both pairs of statements return an object with the same length and class.
No, the length is the same but the class is different.
No, the class is the same but the length is different.
Q66. The _ for R are the main feature that make it different from the original S language.