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] 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
## [26] 29 30
Create a vector B containing 12 character values; all names of your classmate including yourself.
B<- c("Ardifo","Jocelyn","Julian","Kefas","Nikita","Sherly","Vanessa","Jeffry","Lala","Siana","Putri","Fallen")
B## [1] "Ardifo" "Jocelyn" "Julian" "Kefas" "Nikita" "Sherly" "Vanessa"
## [8] "Jeffry" "Lala" "Siana" "Putri" "Fallen"
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,] 70 74 78 82
## [2,] 71 75 79 83
## [3,] 72 76 80 84
## [4,] 73 77 81 85
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,] 40 44 48 52
## [2,] 41 45 49 53
## [3,] 42 46 50 54
## [4,] 43 47 51 55
## [,1] [,2] [,3] [,4]
## [1,] 210 222 234 246
## [2,] 213 225 237 249
## [3,] 216 228 240 252
## [4,] 219 231 243 255
## [,1] [,2] [,3] [,4]
## [1,] 110 118 126 134
## [2,] 112 120 128 136
## [3,] 114 122 130 138
## [4,] 116 124 132 140
## [,1] [,2] [,3] [,4]
## [1,] 30 30 30 30
## [2,] 30 30 30 30
## [3,] 30 30 30 30
## [4,] 30 30 30 30
## [,1] [,2] [,3] [,4]
## [1,] 2800 3256 3744 4264
## [2,] 2911 3375 3871 4399
## [3,] 3024 3496 4000 4536
## [4,] 3139 3619 4131 4675
## [,1] [,2] [,3] [,4]
## [1,] 1.750000 1.681818 1.625000 1.576923
## [2,] 1.731707 1.666667 1.612245 1.566038
## [3,] 1.714286 1.652174 1.600000 1.555556
## [4,] 1.697674 1.638298 1.588235 1.545455
## [1] -8.093713e-28
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.## names scores
## [1,] "Ardifo" "70"
## [2,] "Jocelyn" "71"
## [3,] "Julian" "71"
## [4,] "Kefas" "73"
## [5,] "Nikita" "74"
## [6,] "Sherly" "75"
## [7,] "Vanessa" "76"
## [8,] "Jeffry" "77"
## [9,] "Lala" "78"
## [10,] "Siana" "79"
## [11,] "Putri" "80"
## [12,] "Fallen" "81"
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<-B
age<-c(19, 19, 19, 19, 19, 19, 18, 19, 19, 19, 19, 20)
gender<-c("Male", "Female", "Male", "Male", "Female", "Female", "Female", "Male", "Female", "Female", "Female", "Male")
List<-list(name, age, gender)
List ## [[1]]
## [1] "Ardifo" "Jocelyn" "Julian" "Kefas" "Nikita" "Sherly" "Vanessa"
## [8] "Jeffry" "Lala" "Siana" "Putri" "Fallen"
##
## [[2]]
## [1] 19 19 19 19 19 19 18 19 19 19 19 20
##
## [[3]]
## [1] "Male" "Female" "Male" "Male" "Female" "Female" "Female" "Male"
## [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.
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","Julian","Vanessa","Kefas","Nikita","Jocelyn"),gender=c("Male","Male","Female","Male","Female","Female"),age=c(19,19,18,19,19,19),marital_status=c("single","single","single","single","single","single"),address_by_city=c("Kalimantan","Tangerang","Maluku","Tangerang","Tangerang","Tangerang"),stringsAsFactors = F)
DF1## id name gender age marital_status address_by_city
## 1 1 Ardifo Male 19 single Kalimantan
## 2 2 Julian Male 19 single Tangerang
## 3 3 Vanessa Female 18 single Maluku
## 4 4 Kefas Male 19 single Tangerang
## 5 5 Nikita Female 19 single Tangerang
## 6 6 Jocelyn Female 19 single 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(1:6),name=c("Sherly","Putri","Jeffry","Siana","Lala","Falen"),gender=c("Female","Female","Male","Female","Female","Male"),age=c(19,19,19,19,19,20),marital_status=c("single","single","single","single","single","single"),address_by_city=c("Tangerang","Tangerang","Tangerang","Tangerang","Tangerang","Tangerang"),stringsAsFactors = F)
DF2## id name gender age marital_status address_by_city
## 1 1 Sherly Female 19 single Tangerang
## 2 2 Putri Female 19 single Tangerang
## 3 3 Jeffry Male 19 single Tangerang
## 4 4 Siana Female 19 single Tangerang
## 5 5 Lala Female 19 single Tangerang
## 6 6 Falen Male 20 single 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 marital_status address_by_city
## 1 1 Ardifo Male 19 single Kalimantan
## 2 2 Julian Male 19 single Tangerang
## 3 3 Vanessa Female 18 single Maluku
## 4 4 Kefas Male 19 single Tangerang
## 5 5 Nikita Female 19 single Tangerang
## 6 6 Jocelyn Female 19 single Tangerang
## 7 1 Sherly Female 19 single Tangerang
## 8 2 Putri Female 19 single Tangerang
## 9 3 Jeffry Male 19 single Tangerang
## 10 4 Siana Female 19 single Tangerang
## 11 5 Lala Female 19 single Tangerang
## 12 6 Falen Male 20 single Tangerang
## id name gender age marital_status address_by_city
## 1 1 Ardifo Male 19 single Kalimantan
## 2 2 Julian Male 19 single Tangerang
## 3 3 Vanessa Female 18 single Maluku
## [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 marital_status address_by_city
## 1 1 Ardifo Male 19 single Kalimantan
## 2 2 Julian Male 19 single Tangerang
## 3 4 Kefas Male 19 single Tangerang
## 4 3 Jeffry Male 19 single Tangerang
## 5 6 Falen Male 20 single Tangerang
## id name gender age marital_status address_by_city
## 1 3 Vanessa Female 18 single Maluku
## 2 5 Nikita Female 19 single Tangerang
## 3 6 Jocelyn Female 19 single Tangerang
## 4 1 Sherly Female 19 single Tangerang
## 5 2 Putri Female 19 single Tangerang
## 6 4 Siana Female 19 single Tangerang
## 7 5 Lala Female 19 single Tangerang