Question

In: Statistics and Probability

Q4. Suppose the character string “05/04/06” is assigned to an object, x. Which of the following...

Q4. Suppose the character string “05/04/06” is assigned to an object, x. Which of the following R commands would convert x to a date object that represents May 4, 2006? (Check all that apply)

A. lubridate::mdy(x)

B. lubridate::mdy(x, format = “m/d/y”)

C. as.Date(x, format = ‘%m/%d/%y’)

D. as.Date(x, format = “m/d/y”)

E. as.Date(x, format = ‘m/d/y’)

F. as.Date(x)

Q5. Suppose you have a dataframe, df, with two datetime columns in them: firstPurchaseTime and lastPurchaseTime. These columns are a time stamp that measures time to the second. What would be the outcome for the following line of code?

df$timePassed = as.numeric(df$lastPurchaseTime – df$firstPurchaseTime)

A new column of data the represents the amount of time that has passed in terms of:

A. seconds

B. minutes

C. hours

D. days

E. years

Q6. Suppose you have a dataframe, df, with two datetime columns in them: firstPurchaseTime and lastPurchaseTime. These columns are a time stamp that measures time to the second. What would be the outcome for the following line of code?

boxplot(df$lastPurchaseTime)

A. Nothing, because datetime objects can’t be summarized like numeric values.

B. A box plot that represents the distribution of time stamps.

C. A box plot that represents the distribution of days of the week.

D. A box plot that represents the distribution of months of the year.

E. A box plot that represents the distribution of years.

Q7. What is the result of the following lines of code:

x <- c(‘Product 1’, ‘Product 1’, ‘Product 2’, ‘Product 2’, ‘Product 3’) plot(x)

A. A boxplot that represents the distribution of products.

B. A lineplot that represents the frequency of each product.

C. An error message because R doesn’t know how to aggregate character strings.

D. A histogram that represents the frequency of each product.

E. An error message because R doesn’t know how to aggregate date types.

Q8. One vector, v1, contains the values of 5 and 15. Another vector, v2, contains the values of 6 and NA. What is the result of the following line of code?

v1 < v2

A. A vector that contains one value, NA.

B. A vector that contains two values, TRUE and NA

C. A vector that contains two values, TRUE and FALSE

D. A vector that contains two values, NA and NA

E. A vector that contains one value, TRUE

Q9. df1 is a datframe object that has ten rows and four columns. Df2 is a dataframe object that has eight rows and four columns. The column names in each dataframe are identical. Which line of code will stack the rows from df2 below the rows of df1 in a new dataframe object,

A. df3? df3 <- cbind(df2, df1)

B. df3 <- cbind(df1, df2)

C.df3 <- rbind(df2, df1)

D.df3 <- rbind(df1, df2)

Q 10. What will show up in the RStudio console as a result of running the following lines of code?

for(i in 1:5){ print(sum(i+10)) }

A. The numbers 11, 23, 36, 50, and 65, each on a separate line.

B. The numbers 11, 23, 36, 50, and 65, all on the same line.

C. The numbers 11, 12, 13, 14, and 15, each on a separate line.

D. The numbers 11, 12, 13, 14, and 15, all on the same line.

Solutions

Expert Solution

Please don't hesitate to give a "thumbs up" for the answer in case the answer has helped you

Answering first question, as we are allowed to answer 1 question per post. Please post the other questions separately.

4.

We run the following commands in R session to check if they give us the expected output. First we need to install the lubridate package as this is not included in the base package.

# install packages for lubridate for running functions
installed.packages("lubridate")

# running library for lubridate
library('lubridate')

x <- "05/04/06"

a <- lubridate::mdy(x)
# a : "2006-05-04"

b <- lubridate::mdy(x, format = "m/d/y")
# this errors out

c <- as.Date(x, format = "%m/%d/%y")
# this gives the expected output

d <- as.Date(x, format = "m/d/y")
# returns NA

e <- as.Date(x, format = "m/d/y")
# returns NA

f <- as.Date(x)
# this returns "0005-04-06" , not correct output

Answer: Only A and C are correct


Related Solutions

Which of this method of class String is used to obtain a length of String object?...
Which of this method of class String is used to obtain a length of String object? What is the output of the below Java program with WHILE, BREAK and CONTINUE? int cnt=0; while(true) { if(cnt > 4)    break;    if(cnt==0) {     cnt++; continue; }   System.out.print(cnt + ",");   cnt++; } 1,2,3,4 Compiler error 0,1,2,3,4, 1,2,3,4,
Write a program whose input is a string which contains a character and a phrase, and...
Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. Ex: If the input is: n Nobody the output is: 0...
Using python: Given a string x, write a program to check if its first character is...
Using python: Given a string x, write a program to check if its first character is the same as its last character. If yes, the code should output "True"
An object on a single oscillating string may be modelled by differential equation x"(t)=-x(t) x(t) is...
An object on a single oscillating string may be modelled by differential equation x"(t)=-x(t) x(t) is the signed length of the string at time t. a) the trivial solution x(t) =0 satisfies the differential equation. describe what physical scenario this solution represents. b) find at least three other solutions to the differential equation c) describe what it means for this differential equation to have multiple solutions. what do the solutions represent. d) suppose a string is damped by friction. propose...
Write the following Python code: A string X is an anagram of string Y if X...
Write the following Python code: A string X is an anagram of string Y if X can be obtained by arranging all characters of Y in some order, without removing any characters and without adding new characters. For example, each of the strings "baba", "abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", "aab" and "aabc" are not anagrams of "aabb". A set of strings is anagram-free if it contains no pair of strings which are anagrams...
Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase.
# PYTHONWrite a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase.Ex: If the input is:n Mondaythe output is:1Ex: If the input is:z Today is Mondaythe output is:0Ex: If the input is:n It's a sunny daythe output is:2Case matters.Ex: If the input is:n Nobodythe output is:0n is different than N.
The position x of an object varies with time t. For which of the following equations...
The position x of an object varies with time t. For which of the following equations relating x and t is the motion of the object simple harmonic motion? (There may be more than one correct choice.) The position x of an object varies with time t. For which of the following equations relating x and t is the motion of the object simple harmonic motion? (There may be more than one correct choice.) x = 5 sin23t x =...
1.   What is the output of the following code: string s1 = “X”; string s2 =...
1.   What is the output of the following code: string s1 = “X”; string s2 = “A” + s1 + “BC” + s1 + “DEF” + s1 + “G”; cout << s2; 2.   What is the output of the following code: string s1 = “X”; string s2 = “A” + s1 + “BC” + s1 + “DEF” + s1 + “G”; cout << s[0] + s[3]; 3.   What is the output of the following code: string s1 = “X”; string...
Write the following Python script: Problem Statement A string X is an anagram of string Y...
Write the following Python script: Problem Statement A string X is an anagram of string Y if X can be obtained by arranging all characters of Y in some order, without removing any characters and without adding new characters. For example, each of the strings "baba", "abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", "aab" and "aabc" are not anagrams of "aabb". A set of strings is anagram-free if it contains no pair of strings which...
1.-Interpret the following regression model Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -7.819e+05 7.468e+04 -10.470...
1.-Interpret the following regression model Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -7.819e+05 7.468e+04 -10.470 < 2e-16 *** Lot.Size -5.359e-01 1.163e-01 -4.610 4.67e-06 *** Square.Feet 1.108e+02 1.109e+01 9.986 < 2e-16 *** Num.Baths 2.985e+04 9.650e+03 3.094 0.00204 ** API.2011 1.226e+03 9.034e+01 13.568 < 2e-16 *** dis_coast -7.706e+00 2.550e+00 -3.022 0.00259 ** dis_fwy 1.617e+01 1.232e+01 1.312 0.18995 dis_down 5.364e+00 3.299e+00 1.626 0.10429 I(dis_fwy * dis_down) -4.414e-04 5.143e-04 -0.858 0.39098 Pool 1.044e+05 2.010e+04 5.194 2.59e-07 *** --- Signif. codes: 0 ‘***’ 0.001...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT