In this section, you are expected to be able to shape data in vectors, perform basic mathematical operations, and also manipulate vectors.
Create a vector A containing numeric values, starting from the last 2 digits of your student id up to 30.
## [1] 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Create a vector B containing 12 character values; all names of your classmate including yourself.
B <- c("Ardifo","Angel","Kefas","Jeff","Julian","Jocelyn","Nikita","Sherly","Sofia","Vanessa","Lala","Siana")
B## [1] "Ardifo" "Angel" "Kefas" "Jeff" "Julian" "Jocelyn" "Nikita"
## [8] "Sherly" "Sofia" "Vanessa" "Lala" "Siana"
In this section, you are expected to be able to shape data in Matrices, perform basic mathematical operations, and also manipulate Matrices.
Create a matrices M1 order by \(rows \times columns \space (4 \times 4)\) containing 16 numeric values, random number between 60 and 100.
## [1] 73.22768 89.90501 87.37758 63.63238 90.54779 93.38068 99.59681 72.29616
## [9] 78.83465 71.08710 60.01049 65.27166 87.56298 93.47375 77.36047 76.96264
## [,1] [,2] [,3] [,4]
## [1,] 73.22768 90.54779 78.83465 87.56298
## [2,] 89.90501 93.38068 71.08710 93.47375
## [3,] 87.37758 99.59681 60.01049 77.36047
## [4,] 63.63238 72.29616 65.27166 76.96264
Create a matrices M2 order by \(rows \times columns \space (4 \times 4)\) containing 16 numeric values, random number between 30 and 60. Find out the following tasks:
3 * M1, give your opinion about the result.M1 + M2, give your opinion about the result.M1 - M2, give your opinion about the result.M1 * M2, give your opinion about the result.M1 / M2, give your opinion about the result.M1, give your opinion about the result.M1, give your opinion about the result.## [1] 47.35183 57.37912 55.19112 37.66094 49.97846 30.38580 30.25718 43.21047
## [9] 35.84144 39.95684 38.84405 50.12870 45.13034 57.45925 59.46796 58.21389
## [,1] [,2] [,3] [,4]
## [1,] 47.35183 49.97846 35.84144 45.13034
## [2,] 57.37912 30.38580 39.95684 57.45925
## [3,] 55.19112 30.25718 38.84405 59.46796
## [4,] 37.66094 43.21047 50.12870 58.21389
## [,1] [,2] [,3] [,4]
## [1,] 219.6830 271.6434 236.5039 262.6890
## [2,] 269.7150 280.1420 213.2613 280.4213
## [3,] 262.1328 298.7904 180.0315 232.0814
## [4,] 190.8972 216.8885 195.8150 230.8879
## [,1] [,2] [,3] [,4]
## [1,] 120.5795 140.5262 114.67609 132.6933
## [2,] 147.2841 123.7665 111.04394 150.9330
## [3,] 142.5687 129.8540 98.85455 136.8284
## [4,] 101.2933 115.5066 115.40036 135.1765
## [,1] [,2] [,3] [,4]
## [1,] 25.87585 40.56934 42.99321 42.43265
## [2,] 32.52589 62.99488 31.13025 36.01450
## [3,] 32.18646 69.33962 21.16644 17.89251
## [4,] 25.97144 29.08570 15.14295 18.74875
## [,1] [,2] [,3] [,4]
## [1,] 3467.465 4525.439 2825.547 3951.747
## [2,] 5158.670 2837.446 2840.416 5370.931
## [3,] 4822.467 3013.519 2331.051 4600.469
## [4,] 2396.455 3123.951 3271.984 4480.295
## [,1] [,2] [,3] [,4]
## [1,] 1.546459 1.811736 2.199539 1.940225
## [2,] 1.566859 3.073169 1.779097 1.626783
## [3,] 1.583182 3.291675 1.544908 1.300876
## [4,] 1.689612 1.673117 1.302081 1.322067
## [1] 8494.845
## Warning in rgl.init(initValue, onlyNULL): RGL: unable to open X11 display
## Warning: 'rgl.init' failed, running with 'rgl.useNULL = TRUE'.
## [,1] [,2] [,3] [,4]
## [1,] 1.714650 1.536276 -0.8461913 -2.966109
## [2,] -1.096803 -1.012285 0.5845415 1.889762
## [3,] 1.896410 1.556850 -0.9064361 -3.137335
## [4,] -1.995701 -1.639636 0.9192726 3.350939
Create a matrix data that is contain the following vectors:
B that you has been created in the exercise 2. Name it as a ‘names’ variableC that you has been created in the exercise 3. Name it as a ‘scores’ variable.## [,1]
## [1,] "Ardifo"
## [2,] "Angel"
## [3,] "Kefas"
## [4,] "Jeff"
## [5,] "Julian"
## [6,] "Jocelyn"
## [7,] "Nikita"
## [8,] "Sherly"
## [9,] "Sofia"
## [10,] "Vanessa"
## [11,] "Lala"
## [12,] "Siana"
## [,1]
## [1,] 64.31809
## [2,] 99.41352
## [3,] 97.16774
## [4,] 85.45021
## [5,] 69.19936
## [6,] 71.79157
## [7,] 62.15566
## [8,] 85.59065
## [9,] 76.46794
## [10,] 85.47215
## [11,] 70.28781
## [12,] 78.68802
## Names Scores
## [1,] "Ardifo" "64.3180898018181"
## [2,] "Angel" "99.4135153200477"
## [3,] "Kefas" "97.1677404735237"
## [4,] "Jeff" "85.4502072371542"
## [5,] "Julian" "69.1993619594723"
## [6,] "Jocelyn" "71.7915718350559"
## [7,] "Nikita" "62.1556605026126"
## [8,] "Sherly" "85.5906545929611"
## [9,] "Sofia" "76.4679422508925"
## [10,] "Vanessa" "85.4721510969102"
## [11,] "Lala" "70.2878140285611"
## [12,] "Siana" "78.6880231183022"
In this section, you are expected to be able to shape data by using the list() function, perform some basic manipulations.
Please create a data set as the List variable by using the list() function, contain the following vectors:
name, the values including your classmate and yourselfage, the values including your classmate and yourselfgender, the values including your classmate and yourselfName <- c("Ardifo","Angel","Kefas","Jeff","Julian","Jocelyn","Nikita","Sherly","Sofia","Vanessa","Lala","Siana")
list(Name)## [[1]]
## [1] "Ardifo" "Angel" "Kefas" "Jeff" "Julian" "Jocelyn" "Nikita"
## [8] "Sherly" "Sofia" "Vanessa" "Lala" "Siana"
## [[1]]
## [1] 19 19 19 19 19 19 19 19 19 18 18 19
Gender <- c("Male", "Female", "Male", "Male", "Male", "Female", "Female", "Female", "Female", "Female", "Female", "Female")
list(Gender)## [[1]]
## [1] "Male" "Female" "Male" "Male" "Male" "Female" "Female" "Female"
## [9] "Female" "Female" "Female" "Female"
## [[1]]
## [1] "Ardifo" "Angel" "Kefas" "Jeff" "Julian" "Jocelyn" "Nikita"
## [8] "Sherly" "Sofia" "Vanessa" "Lala" "Siana"
##
## [[2]]
## [1] 19 19 19 19 19 19 19 19 19 18 18 19
##
## [[3]]
## [1] "Male" "Female" "Male" "Male" "Male" "Female" "Female" "Female"
## [9] "Female" "Female" "Female" "Female"
In this section, you are expected to be able to shape data by using the factor() function, perform some basic manipulations.
Please create a data set as the Factor variable as you have done at Exercise 7. Here, you add one more variable called marital_status by using the factor() function, as the following code:
Martial_status <- factor(c("Yes", "No", "Yes", "No", "Yes", "No", "Yes", "No", "Yes", "No", "Yes", "No"))
factor(Martial_status)## [1] Yes No Yes No Yes No Yes No Yes No Yes No
## Levels: No Yes
In this section, you are expected to be able to shape data by using the data.frame() function, perform some basic manipulations.
Please create a data set as the DF1 variable, contain the following vectors:
id, assume 1 up to 6name the values according to your classmate and yourselfgender the values according to your classmate and yourselfage the values according to your classmate and yourselfmarital_status the values according to your classmate and yourselfaddress_by_city the values according to your classmate and yourselfDf1 <- data.frame(Id = c (1:6),
Name = c("Siana","Lala","Vanessa","Angel","Nikita","Sherly"),
Gender = c("Female","Female","Female","Female","Female","Female"),
Age = c(19, 18, 18, 19, 19, 19),
Martial_status = c("Yes","Yes","Yes","Yes","Yes","Yes"),
Addres_By_City = c("Tangerang","Tangerang","Manado","Tangerang","Tangerang Selatan","Jakarta"),
stringsAsFactors = F)
Df1## Id Name Gender Age Martial_status Addres_By_City
## 1 1 Siana Female 19 Yes Tangerang
## 2 2 Lala Female 18 Yes Tangerang
## 3 3 Vanessa Female 18 Yes Manado
## 4 4 Angel Female 19 Yes Tangerang
## 5 5 Nikita Female 19 Yes Tangerang Selatan
## 6 6 Sherly Female 19 Yes Jakarta
Please create a data set as the DF2 variable, contain the following vectors:
id, assume 7 up to 12name the values according to your classmate and yourselfgender the values according to your classmate and yourselfage the values according to your classmate and yourselfmarital_status the values according to your classmate and yourselfaddress_by_city the values according to your classmate and yourselfDf2 <- data.frame(Id = c (7:12),
Name = c("Ardifo","Julian","Irene","Jeff","Kefas","Sofia"),
Gender = c("Male","Male","Female","Male","Male","Female"),
Age = c(19, 19, 19, 19, 19, 19),
Martial_status = c("No","No","Yes","No","No","Yes"),
Addres_By_City = c("Tangerang","Tangerang","Tangerang","Tangerang","Tangerang","Tangerang"),
stringsAsFactors = F)
Df2## Id Name Gender Age Martial_status Addres_By_City
## 1 7 Ardifo Male 19 No Tangerang
## 2 8 Julian Male 19 No Tangerang
## 3 9 Irene Female 19 Yes Tangerang
## 4 10 Jeff Male 19 No Tangerang
## 5 11 Kefas Male 19 No Tangerang
## 6 12 Sofia Female 19 Yes Tangerang
In this final exercise, please consider the following tasks:
DF1 and DF2, assign it as SB19 variable!SB19!SB19 dataset!SB19 dataset like an Excel file on your Rstudio?SB19!SB19, filter it by their gender accordingly! (as you have learn last week)## Id Name Gender Age Martial_status Addres_By_City
## 1 1 Siana Female 19 Yes Tangerang
## 2 2 Lala Female 18 Yes Tangerang
## 3 3 Vanessa Female 18 Yes Manado
## 4 4 Angel Female 19 Yes Tangerang
## 5 5 Nikita Female 19 Yes Tangerang Selatan
## 6 6 Sherly Female 19 Yes Jakarta
## 7 7 Ardifo Male 19 No Tangerang
## 8 8 Julian Male 19 No Tangerang
## 9 9 Irene Female 19 Yes Tangerang
## 10 10 Jeff Male 19 No Tangerang
## 11 11 Kefas Male 19 No Tangerang
## 12 12 Sofia Female 19 Yes Tangerang
## Id Name Gender Age Martial_status Addres_By_City
## 1 1 Siana Female 19 Yes Tangerang
## 2 2 Lala Female 18 Yes Tangerang
## 3 3 Vanessa Female 18 Yes Manado
## 'data.frame': 12 obs. of 6 variables:
## $ Id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ Name : chr "Siana" "Lala" "Vanessa" "Angel" ...
## $ Gender : chr "Female" "Female" "Female" "Female" ...
## $ Age : num 19 18 18 19 19 19 19 19 19 19 ...
## $ Martial_status: chr "Yes" "Yes" "Yes" "Yes" ...
## $ Addres_By_City: chr "Tangerang" "Tangerang" "Manado" "Tangerang" ...
## [1] 12 6
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## Id Name Gender Age Martial_status Addres_By_City
## 1 1 Siana Female 19 Yes Tangerang
## 2 2 Lala Female 18 Yes Tangerang
## 3 3 Vanessa Female 18 Yes Manado
## 4 4 Angel Female 19 Yes Tangerang
## 5 5 Nikita Female 19 Yes Tangerang Selatan
## 6 6 Sherly Female 19 Yes Jakarta
## 7 9 Irene Female 19 Yes Tangerang
## 8 12 Sofia Female 19 Yes Tangerang
## Id Name Gender Age Martial_status Addres_By_City
## 1 7 Ardifo Male 19 No Tangerang
## 2 8 Julian Male 19 No Tangerang
## 3 10 Jeff Male 19 No Tangerang
## 4 11 Kefas Male 19 No Tangerang