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] 10 11 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","Jeffry","Jocelyn","Julian","Kefas","Nikita","Angel","Sherly","Vanessa","Siana","Lala","Fallen")
B## [1] "Ardifo" "Jeffry" "Jocelyn" "Julian" "Kefas" "Nikita" "Angel"
## [8] "Sherly" "Vanessa" "Siana" "Lala" "Fallen"
Create a vector C containing 12 numeric values, random number between 60 and 100.
## [1] 62.38875 64.26517 81.30428 70.84725 81.99653 80.16449 76.58322 80.84223
## [9] 97.96702 86.07844 99.16742 91.17518
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] [,2] [,3] [,4]
## [1,] 93.52714 71.81038 70.84353 87.24286
## [2,] 87.16793 84.71045 94.39375 76.84868
## [3,] 78.24054 82.37344 97.57714 99.01813
## [4,] 94.29389 81.54247 72.91681 63.04105
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] [,2] [,3] [,4]
## [1,] 55.97764 59.69429 30.35259 49.86018
## [2,] 58.27770 36.36451 52.19269 55.57889
## [3,] 35.56016 31.37194 49.52012 32.48177
## [4,] 41.50107 37.62186 51.02336 45.54659
## [,1] [,2] [,3] [,4]
## [1,] 280.5814 215.4311 212.5306 261.7286
## [2,] 261.5038 254.1313 283.1813 230.5460
## [3,] 234.7216 247.1203 292.7314 297.0544
## [4,] 282.8817 244.6274 218.7504 189.1231
## [,1] [,2] [,3] [,4]
## [1,] 149.5048 131.5047 101.1961 137.1030
## [2,] 145.4456 121.0750 146.5864 132.4276
## [3,] 113.8007 113.7454 147.0973 131.4999
## [4,] 135.7950 119.1643 123.9402 108.5876
## [,1] [,2] [,3] [,4]
## [1,] 37.54949 12.11609 40.49095 37.38268
## [2,] 28.89024 48.34594 42.20106 21.26979
## [3,] 42.68038 51.00150 48.05702 66.53636
## [4,] 52.79282 43.92060 21.89344 17.49446
## [,1] [,2] [,3] [,4]
## [1,] 5235.429 4286.669 2150.284 4349.944
## [2,] 5079.946 3080.454 4926.663 4271.164
## [3,] 2782.246 2584.215 4832.032 3216.284
## [4,] 3913.297 3067.780 3720.461 2871.305
## [,1] [,2] [,3] [,4]
## [1,] 1.670794 1.202969 2.334020 1.749750
## [2,] 1.495734 2.329481 1.808563 1.382695
## [3,] 2.200230 2.625704 1.970454 3.048422
## [4,] 2.272083 2.167422 1.429087 1.384100
## [1] 585721.4
## [,1] [,2] [,3] [,4]
## [1,] 0.05389362 0.07302603 -0.07186368 -0.05072854
## [2,] -0.09209114 -0.15863981 0.11180118 0.14522617
## [3,] 0.02617028 0.12673674 -0.06423735 -0.08981543
## [4,] 0.00823665 -0.05062202 0.03717806 0.00777819
Create a matrix data by column, 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.## names scores
## [1,] "Ardifo" "62.3887493740767"
## [2,] "Jeffry" "64.2651687655598"
## [3,] "Jocelyn" "81.3042829371989"
## [4,] "Julian" "70.8472461160272"
## [5,] "Kefas" "81.996531393379"
## [6,] "Nikita" "80.1644925959408"
## [7,] "Angel" "76.5832183323801"
## [8,] "Sherly" "80.8422308415174"
## [9,] "Vanessa" "97.9670208506286"
## [10,] "Siana" "86.0784370265901"
## [11,] "Lala" "99.1674230620265"
## [12,] "Fallen" "91.1751762218773"
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","Jeffry","Jocelyn","Julian","Kefas","Nikita","Angel","Sherly","Vanessa","Siana","Lala","Fallen")
age <- c(19,19,19,19,19,19,19,19,18,19,19,20)
gender <- c("male","male","female","male","male","female","female","female","female","female","female","male")
"List" <- list(name,age,gender)
List## [[1]]
## [1] "Ardifo" "Jeffry" "Jocelyn" "Julian" "Kefas" "Nikita" "Angel"
## [8] "Sherly" "Vanessa" "Siana" "Lala" "Fallen"
##
## [[2]]
## [1] 19 19 19 19 19 19 19 19 18 19 19 20
##
## [[3]]
## [1] "male" "male" "female" "male" "male" "female" "female" "female"
## [9] "female" "female" "female" "male"
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" <- List
Factor[[4]] <- martial_status
Factor## [[1]]
## [1] "Ardifo" "Jeffry" "Jocelyn" "Julian" "Kefas" "Nikita" "Angel"
## [8] "Sherly" "Vanessa" "Siana" "Lala" "Fallen"
##
## [[2]]
## [1] 19 19 19 19 19 19 19 19 18 19 19 20
##
## [[3]]
## [1] "male" "male" "female" "male" "male" "female" "female" "female"
## [9] "female" "female" "female" "male"
##
## [[4]]
## [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("Ardifo","Jeffry","Jocelyn","Julian","Kefas","Nikita"),
gender = c("male","male","female","male","male","female"),
age = c(19,19,19,19,19,19),
martial_status = c("yes","no","yes","no","yes","no"),
address_by_city = c("Kalimantan","Tangerang","Tangerang","Tangerang","Tangerang","Tangerang"),
stringsAsFactors = F)
print(DF1)## id name gender age martial_status address_by_city
## 1 1 Ardifo male 19 yes Kalimantan
## 2 2 Jeffry male 19 no Tangerang
## 3 3 Jocelyn female 19 yes Tangerang
## 4 4 Julian male 19 no Tangerang
## 5 5 Kefas male 19 yes Tangerang
## 6 6 Nikita female 19 no Tangerang
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("Angel","Sherly","Vanessa","Siana","Lala","Fallen"),
gender = c("female","female","female","female","female","male"),
age = c(19,19,18,19,19,20),
martial_status = c("yes","no","yes","no","yes","no"),
address_by_city = c("Tangerang","Jakarta","Maluku","Tangerang","Tangerang","Tangerang"),
stringsAsFactors = F)
print(DF2)## id name gender age martial_status address_by_city
## 1 7 Angel female 19 yes Tangerang
## 2 8 Sherly female 19 no Jakarta
## 3 9 Vanessa female 18 yes Maluku
## 4 10 Siana female 19 no Tangerang
## 5 11 Lala female 19 yes Tangerang
## 6 12 Fallen male 20 no 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!## id name gender age martial_status address_by_city
## 1 1 Ardifo male 19 yes Kalimantan
## 2 2 Jeffry male 19 no Tangerang
## 3 3 Jocelyn female 19 yes Tangerang
## 4 4 Julian male 19 no Tangerang
## 5 5 Kefas male 19 yes Tangerang
## 6 6 Nikita female 19 no Tangerang
## 7 7 Angel female 19 yes Tangerang
## 8 8 Sherly female 19 no Jakarta
## 9 9 Vanessa female 18 yes Maluku
## 10 10 Siana female 19 no Tangerang
## 11 11 Lala female 19 yes Tangerang
## 12 12 Fallen male 20 no Tangerang
## id name gender age martial_status address_by_city
## 1 1 Ardifo male 19 yes Kalimantan
## 2 2 Jeffry male 19 no Tangerang
## 3 3 Jocelyn female 19 yes Tangerang
## 'data.frame': 12 obs. of 6 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ name : chr "Ardifo" "Jeffry" "Jocelyn" "Julian" ...
## $ gender : chr "male" "male" "female" "male" ...
## $ age : num 19 19 19 19 19 19 19 19 18 19 ...
## $ martial_status : chr "yes" "no" "yes" "no" ...
## $ address_by_city: chr "Kalimantan" "Tangerang" "Tangerang" "Tangerang" ...
## [1] 12 6
SB19, filter it by their gender accordingly! (as you have learn last week)##
## 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 address_by_city
## 1 1 Ardifo male 19 yes Kalimantan
## 2 2 Jeffry male 19 no Tangerang
## 3 4 Julian male 19 no Tangerang
## 4 5 Kefas male 19 yes Tangerang
## 5 12 Fallen male 20 no Tangerang
## id name gender age martial_status address_by_city
## 1 3 Jocelyn female 19 yes Tangerang
## 2 6 Nikita female 19 no Tangerang
## 3 7 Angel female 19 yes Tangerang
## 4 8 Sherly female 19 no Jakarta
## 5 9 Vanessa female 18 yes Maluku
## 6 10 Siana female 19 no Tangerang
## 7 11 Lala female 19 yes Tangerang