You are on page 1of 6

assignment 1

rajwinder kaur

2022-10-23

R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring
HTML, PDF, and MS Word documents. For more details on using R Markdown see
http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as
well as the output of any embedded R code chunks within the document. You can embed an
R code chunk like this:
summary(cars)

## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00

Including Plots
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of
the R code that generated the plot.
#part 1
Which of the following is a logical operator?
/|-^
Answer | is logical operator
b. What value does R return in the statement below?
3 >= 4
Answer FALSE
c. What is the result of this calculation?
(45 + 3) * 43 + 3^2
Answer 2073
d. How would R evaluate the following?
carspeed = 70
speedlimit = 65 carspeed
> speedlimit

Answer TRUE
e. How would R evaluate the following?
(2+2 == 4) | (2+2 == 5)
Answer TRUE
f.How would R evaluate the following?
!FALSE
Answer TRUE
g. What is the result of this function?
round(33.2321435452, 2)
Answer 33.23
h. What is the result of this function?
sqrt (64)
Answer 8
i. What is the result of these statements? Sqrt
(64) == 64 ^.5
Answer TRUE
abs(-32)
Answer 32
j. Which of the following is an arithmetic operator?
*, |, &, !
Answer *
k. What is wrong with this code?
2 + 3 *4 + sqrt[100]
Answer Error in sqrt[100]
#part2
a. Create a vector called unemploy_rate with 12 values, one for each month in 2013.
The values for each month are listed below (beginning with January’s rate of 7.9)
unemploy_rate = c (7.9,7.7,7.5,7.5,7.5,7.5,7.3,7.2,7.2,7.2,7.0,6.7)
Answer 7.9 7.7 7.5 7.5 7.5 7.5 7.3 7.2 7.2 7.2 7 6.7

b. Create a vector called month and add 12 values, one for the name of each month in a
year.

month= c(“jan”,“feb”,“Mar”,“Apr”,“May”,“Jun”,“July”,“August”,“Sep”,“Oct”,“Nov”,“Dec”)
cat(month)
Answer Jan Feb Mar Apr May Jun July August Sep Oct Nov Dec

c. Convert month to a factor variable?


month =
c("jan","feb","Mar","Apr","May","Jun","July","August","Sep","Oct","Nov","Dec"
)

as.factor(month) cat(month)
ANSWER
as. factor(month)
[1] jan feb Mar Apr May Jun July August Sep Oct Nov
[12] Dec
Levels: Apr August Dec feb jan July Jun Mar May Nov Oct Sep > cat(month) jan feb Mar Apr
May Jun July August Sep Oct Nov Dec
d.) Create a data frame called monthly_rate that is comprised of unemploy_rate and month.
unemploy_rate = c (7.9,7.7,7.5,7.5,7.5,7.5,7.3,7.2,7.2,7.2,7.0,6.7) month =
c(“jan”,“feb”,“Mar”,“Apr”,“May”,“Jun”,“July”,“August”,“Sep”,“Oct”,“Nov”,“Dec”)
monthly_rate=data.frame(month=month,unemploy_rate) print(monthly_rate) answer
month unemploy_rate 1 Jan 7.9 2 feb 7.7 3 Mar 7.5 4 Apr 7.5 5 May 7.5 6 Jun 7.5 7 July 7.3 8
August 7.2 9 Sep 7.2 10 Oct 7.2 11 Nov 7.0 12 Dec 6.7

e. How would you extract the unemployment rate for March?


Answer unemploy_rate = c (7.9,7.7,7.5,7.5,7.5,7.5,7.3,7.2,7.2,7.2,7.0,6.7) month =
c(“jan”,“feb”,“Mar”,“Apr”,“May”,“Jun”,“July”,“August”,“Sep”,“Oct”,“Nov”,“Dec”)
monthly_rate=data.frame(month=month,unemploy_rate)
march=monthly_rate[monthly_rate$month==“Mar”,][“unemploy_rate”] print(march)
unemploy_rate 7.5

f. Extract only those months where unemployment was below 7.5%.


Answer
unemploy_rate = c (7.9,7.7,7.5,7.5,7.5,7.5,7.3,7.2,7.2,7.2,7.0,6.7)
month = c(“jan”,“feb”,“Mar”,“Apr”,“May”,“Jun”,“July”,“August”,“Sep”,“Oct”,“Nov”,“Dec”)
monthly_rate = [.data.frame(month = month,unemploy_rate = unemploy_rate)
h = monthly_rate[monthly_rate$unemploy_rate < 7.5][“month”]
print(h)
Answer
7 July 7.3 8 August 7.2 9 Sep 7.2 10 Oct 7.2 11 Nov 7.0
Part 3
R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML,
PDF, and MS Word documents. For more details on using R Markdown see
http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as
well as the output of any embedded R code chunks within the document. You can embed an R
code chunk like this:
summary(cars)

## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00

Including Plots
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of
the R code that generated the plot.
BUSI4063_ rajwinder_fed_stimulus.R
name: Rajwinder
date: october18,2022
data. Frame (Use_of_ARRA_Stimulus_Funds)
Use_of_ARRA_Stimulus_Funds.(1) <-
read.csv(“C:/Users/Lenovo/Downloads/Use_of_ARRA_Stimulus_Funds (1).csv”)
sum(DF_rajwinder_fed_stimulus𝑃𝑎𝑦𝑚𝑒𝑛𝑡. 𝑉𝑎𝑙𝑢𝑒, 𝑛𝑎. 𝑟𝑚 = 𝑇𝑅𝑈𝐸)
3180464994
𝑚𝑒𝑎𝑛(𝐷𝐹_𝑟𝑎𝑗𝑤𝑖𝑛𝑑𝑒𝑟_𝑓𝑒𝑑_𝑠𝑡𝑖𝑚𝑢𝑙𝑢𝑠Payment.Value, na.rm=TRUE)
[1] 242044.5
Project_Status<-subset(DF_rajwinder_fed_stimulus,Project.Status, select= (“Completed 50% or
more”)

You might also like