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

p .00 .01 .02 .03 .04 .05 .06 .07 .08 .09 .0 .5000 .5040 .5080 .5120...
p .00 .01 .02 .03 .04 .05 .06 .07 .08 .09 .0 .5000 .5040 .5080 .5120 .5160 .5199 .5239 .5279 .5319 .5359 .1 .5398 .5438 .5478 .5517 .5557 .5596 .5636 .5675 .5714 .5753 .2 .5793 .5832 .5871 .5910 .5948 .5987 .6026 .6064 .6103 .6141 .3 .6179 .6217 .6255 .6293 .6331 .6368 .6406 .6443 .6480 .6517 .4 .6554 .6591 .6628 .6664 .6700 .6736 .6772 .6808 .6844 .6879 .5 .6915 .6950 .6985 .7019 .7054 .7088 .7123 .7157 .7190 .7224 .6 .7257 .7291...
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...
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 =...
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.
Define a struct computerType to store the following data about a computer: Manufacturer (50 character string),...
Define a struct computerType to store the following data about a computer: Manufacturer (50 character string), model type (50 character string), processor type (10 character string), ram (int) in GB, hard drive size (int) in GB, year when the computer was built (int), and the price (double). Write a program that declares a variable of type computerType, prompts the user to the input data for the struct, and then outputs all the computer's data from the struct. For Example: Enter...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT