Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Considering a Character vector called statusDesc =c(senior,sophomore,junior,freshman). Write R code(s) to create a factor called statusFac that will take statusDesc as an argument and has

Considering a Character vector called statusDesc=c(senior,sophomore,junior,freshman).

Write R code(s) to create a factor called statusFac that will take statusDescas an argument and has four levels in the order of freshman, sophomore, junior, and senior.

Use the following codes to generate 10 random numbers to represent 10 random ages. set.seed(1) ages=rnorm(10,24,24)

Based on the variable ages, use cut() to create a factor called ageFac that has 4 levels child,teen,adult, and senior.

The corresponding age ranges are (3,13],(13,18],(18,60],and (60,120]. For example, one must be older than 3 and not older than 13 to be called a child. The contents of ageFac should be as follows: [1] child adult child senior adult child adult [8] adult adult teen Levels: child teen adult senior

Assuming a variable called num contains an integer,

write an if-else statement to display the message it is an even number if num is even, or it is an odd number if num is odd. (Hint: use %% 2 to check the remainder of num divided by 2).

Consider two variables, score and grade. The variable score contains a numeric value.Write an if-else if statement to:

assign A to grade if score is greater than or equal to 90;

assign B to grade if score is greater than or equal to 80 but less than 90; or

assign C to grade if score is greater than or equal to 70 but less than 80.

Considering the following R codes a=c(2,-4,-3,7,6) b=1:5 c=6:10 There is a numeric vector d.

Assign the item in b to d if the corresponding item in a is greater than 0, otherwise, assign the item in c to d. For instance, the first item in a is 2, which is greater than 0, therefore the first item of d should be 1, which comes from b. (Hint: use if-else statement).

Write a repeat loop to print out the message Hello World! 10 times.

Write a while loop to calculate 9! (factorial).

Considering a vector data=seq(0,100,2), which represents all the even numbers from 0 through 100,

write a for loop to sum up all the items in data.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

1. Television more Over watching faceing of many problems ?

Answered: 1 week ago

Question

Is there a link between chronic stress and memory function?

Answered: 1 week ago