Lab 2 R PDF

.pdf

School

Drexel University *

*We aren’t endorsed by this school

Course

410

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

10

Uploaded by MegaOysterMaster676

Report
10/4/23, 5 : 41 PM Lab 2 R markdown Page 1 of 10 file:///Users/mathabib/Documents/R%20files/Lab-2-Markdown.html Lab 2 R markdown MH 2023-10-04 1: Overview myData = read.csv("/Users/mathabib/Downloads/list_1.csv") sample(1:50, 100, replace = T) ## [1] 42 17 30 13 18 33 17 17 24 23 34 40 14 7 13 1 28 12 12 46 46 29 27 40 47 ## [26] 14 28 12 18 48 1 43 23 12 31 4 22 20 7 39 49 11 15 8 7 3 10 45 46 10 ## [51] 50 7 47 16 4 5 33 6 49 38 15 5 3 9 27 45 47 12 12 12 44 42 48 45 26 ## [76] 45 37 16 7 46 34 35 22 43 36 44 21 42 30 26 21 33 13 7 42 3 13 29 11 31 2: Frequency Tables freq_data=read.csv("/Users/mathabib/Downloads/list_1.csv") table(freq_data) ## X1 ## 0 1 2 3 4 5 6 7 8 9 ## 4 4 6 8 4 7 3 4 6 3 transform(table(freq_data)) ## X1 Freq ## 1 0 4 ## 2 1 4 ## 3 2 6 ## 4 3 8 ## 5 4 4 ## 6 5 7 ## 7 6 3 ## 8 7 4 ## 9 8 6 ## 10 9 3
10/4/23, 5 : 41 PM Lab 2 R markdown Page 2 of 10 file:///Users/mathabib/Documents/R%20files/Lab-2-Markdown.html d=sample(1:100,1000,replace=T) bins=seq(0,100,by=10) cut_data=cut(d,bins) table(cut_data) ## cut_data ## (0,10] (10,20] (20,30] (30,40] (40,50] (50,60] (60,70] (70,80] ## 101 94 116 99 112 93 97 94 ## (80,90] (90,100] ## 89 105 Exercise 1: Var1=sample(1:10, 1000, replace=T) bins=seq(0,10,by=1) cut_data=cut(Var1,bins) table(cut_data) ## cut_data ## (0,1] (1,2] (2,3] (3,4] (4,5] (5,6] (6,7] (7,8] (8,9] (9,10] ## 114 100 85 117 98 79 105 98 110 94 Exercise 2: cumsum(table(cut_data)) ## (0,1] (1,2] (2,3] (3,4] (4,5] (5,6] (6,7] (7,8] (8,9] (9,10] ## 114 214 299 416 514 593 698 796 906 1000 The entries in this script di ff er from those in the previous script in that in each bin, the frequency value represents everything underneath the upper limit of said bin. Meaning if there is a frequency of 2 between 1 and 2 and a frequency of 2 between 2 and 3, the 2:3 bin will show a frequency of 4. 3: Bar Graphs: x=c(0,1,2,3,4,5,6,7,8,9) f=c(4,4,6,8,4,7,3,4,6,3) barplot(f,names.arg=x,ylim=c(0,10),col="blue",xlab="number",ylab="Frequency",main="Ti tle")
10/4/23, 5 : 41 PM Lab 2 R markdown Page 3 of 10 file:///Users/mathabib/Documents/R%20files/Lab-2-Markdown.html Exercise 1: cod_data=c(6,12,7,9,15,8,7,11,20,10,8,18,5,12,7,8,5,15,10,9,5,8,72,7,21,10,12,9,6,6,1 4,12,21,11,5,9,6,12,8,8,12,6,9,4,19,32,9,11,16,5) table(cod_data) ## cod_data ## 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 32 72 ## 1 5 5 4 6 6 3 3 6 1 2 1 1 1 1 2 1 1 cumsum(table(cod_data)) ## 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 32 72 ## 1 6 11 15 21 27 30 33 39 40 42 43 44 45 46 48 49 50
10/4/23, 5 : 41 PM Lab 2 R markdown Page 4 of 10 file:///Users/mathabib/Documents/R%20files/Lab-2-Markdown.html x=c(4,5,6,7,8,9,10,11,12,14,15,16,18,19,20,21,32,72) f=c(1,5,5,4,6,6,3,3,6,1,2,1,1,1,1,2,1,1) barplot(f,names.arg=x,ylim=c(0,10),col="pink",xlab="cod weight",ylab="Frequency",main ="Frequency of Cod Weights") Something wrong with this graph is that the spacing between the cod weights are not regular, so it is unclear what bars correspond to what weights. This could be solved by reducing text size so each label can be visible. Exercise 2: d=read.csv(("/Users/mathabib/Downloads/death_data.csv"),header=T) #Get data on number of deaths for top causes c=d$Cause #Stores the column labeled "Cause" into the vector c f=d$Deaths #Stores the column labeled "Deaths" into the vector f barplot(f/100000, names.arg=c, cex.names=.5, ylab="Hundred thousand deaths", col="bla ck")
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help