Please answet this in R. I have posted the link to the data set below: link: htt
ID: 3887582 • Letter: P
Question
Please answet this in R. I have posted the link to the data set below:
link: http://people.stat.sc.edu/grego/courses/stat540/Fire_Response.txt
The Fire Response data on the website simulates the response time (in minutes) for tractor units to reach fires on non-federal lands in South Carolina. The districts are row names. The variables include the readiness level of each district (1=low, 2=medium, 3=high), the elapsed time to contact the dispatch office, the elapsed time for the dispatcher to contact a tractor unit, and the elapsed time for a tractor unit to reach the scene of a fire.
(a) Read in the data set as a data frame; you may need row.names=NULL to read it in.
(b) Change the name of the District column so that it reads correctly as “District”.
(c) Extract rows 4, 11, 12, and 15–the rows for the Midlands and save them in a data frame called Midlands (We’ll soon learn a more efficient way of doing this). Display the new data frame.
Explanation / Answer
Program
df <- read.table("http://people.stat.sc.edu/grego/courses/stat540/Fire_Response.txt",
header = TRUE, row.names=NULL)
df
names(df)[names(df)=="row.names"] <- "District"
df
Midlands <- df[c(4,11,12,15),c('District','Readiness','Dispatch','Contact','Enroute')]
Midlands
Output
> df <- read.table("http://people.stat.sc.edu/grego/courses/stat540/Fire_Response.txt",
header = TRUE, row.names=NULL)
> df
row.names Readiness Dispatch Contact Enroute
1 Upstate 1 3 9 24
2 Upstate 3 2 3 20
3 Upstate 2 1 5 21
4 Midlands 3 4 4 14
5 Lowcountry 1 4 10 35
6 Peedee 1 3 2 17
7 Peedee 2 2 5 23
8 Lowcountry 1 1 6 45
9 Lowcountry 1 1 4 18
10 Peedee 1 3 8 16
11 Midlands 1 5 9 10
12 Midlands 2 4 5 NA
13 Upstate 2 3 3 22
14 Upstate 1 2 13 9
15 Midlands 1 3 7 13
16 Lowcountry 3 1 2 33
17 Lowcountry 2 2 5 17
18 Peedee 3 1 4 16
> names(df)[names(df)=="row.names"] <- "District"
> df
District Readiness Dispatch Contact Enroute
1 Upstate 1 3 9 24
2 Upstate 3 2 3 20
3 Upstate 2 1 5 21
4 Midlands 3 4 4 14
5 Lowcountry 1 4 10 35
6 Peedee 1 3 2 17
7 Peedee 2 2 5 23
8 Lowcountry 1 1 6 45
9 Lowcountry 1 1 4 18
10 Peedee 1 3 8 16
11 Midlands 1 5 9 10
12 Midlands 2 4 5 NA
13 Upstate 2 3 3 22
14 Upstate 1 2 13 9
15 Midlands 1 3 7 13
16 Lowcountry 3 1 2 33
17 Lowcountry 2 2 5 17
18 Peedee 3 1 4 16
> Midlands <- df[c(4,11,12,15),c('District','Readiness','Dispatch','Contact','Enroute')]
> Midlands
District Readiness Dispatch Contact Enroute
4 Midlands 3 4 4 14
11 Midlands 1 5 9 10
12 Midlands 2 4 5 NA
15 Midlands 1 3 7 13
>