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] 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("Julian","Vanessa","Nikita","Jocelyn","Kefas","Ardifo","Sherly","Putri","Siana","Jeffry","Fallen","Lala")
B
## [1] "Julian" "Vanessa" "Nikita" "Jocelyn" "Kefas" "Ardifo" "Sherly"
## [8] "Putri" "Siana" "Jeffry" "Fallen" "Lala"
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,] 79.83350 86.89926 83.91380 98.74612
## [2,] 61.57536 66.26130 72.97581 89.35969
## [3,] 76.61996 81.82570 84.40950 83.98317
## [4,] 76.75686 74.27144 63.71366 68.24953
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,] 45.86164 37.83447 56.83944 58.47246
## [2,] 54.97339 55.93345 44.34845 37.92817
## [3,] 52.56777 40.47395 49.73782 38.57957
## [4,] 46.46820 56.94110 57.01691 54.73341
## [,1] [,2] [,3] [,4]
## [1,] 239.5005 260.6978 251.7414 296.2384
## [2,] 184.7261 198.7839 218.9274 268.0791
## [3,] 229.8599 245.4771 253.2285 251.9495
## [4,] 230.2706 222.8143 191.1410 204.7486
## [,1] [,2] [,3] [,4]
## [1,] 125.6951 124.7337 140.7532 157.2186
## [2,] 116.5487 122.1947 117.3243 127.2879
## [3,] 129.1877 122.2996 134.1473 122.5627
## [4,] 123.2251 131.2125 120.7306 122.9829
## [,1] [,2] [,3] [,4]
## [1,] 33.971860 49.06479 27.074363 40.27367
## [2,] 6.601971 10.32785 28.627357 51.43152
## [3,] 24.052197 41.35175 34.671682 45.40360
## [4,] 30.288659 17.33034 6.696746 13.51612
## [,1] [,2] [,3] [,4]
## [1,] 3661.295 3287.788 4769.613 5773.929
## [2,] 3385.006 3706.223 3236.364 3389.250
## [3,] 4027.741 3311.809 4198.345 3240.035
## [4,] 3566.753 4229.097 3632.756 3735.530
## [,1] [,2] [,3] [,4]
## [1,] 1.740747 2.296828 1.476331 1.688763
## [2,] 1.120094 1.184645 1.645510 2.356024
## [3,] 1.457546 2.021688 1.697089 2.176882
## [4,] 1.651815 1.304356 1.117452 1.246944
## [1] 121744.4
## [,1] [,2] [,3] [,4]
## [1,] -0.16037287 0.11359938 -0.02324926 0.11190611
## [2,] 0.23550530 -0.18782009 -0.00237027 -0.09190726
## [3,] -0.10095159 0.03806419 0.09366849 -0.01903900
## [4,] 0.01832094 0.04109812 -0.05871658 0.00658711
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,] "Julian" "80.6124451942742"
## [2,] "Vanessa" "89.9770676903427"
## [3,] "Nikita" "89.0735739935189"
## [4,] "Jocelyn" "86.5764235518873"
## [5,] "Kefas" "82.5759704783559"
## [6,] "Ardifo" "99.3481901660562"
## [7,] "Sherly" "76.9267243985087"
## [8,] "Putri" "60.913552949205"
## [9,] "Siana" "96.5270642377436"
## [10,] "Jeffry" "77.4445585533977"
## [11,] "Fallen" "86.8105422984809"
## [12,] "Lala" "76.4403099846095"
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("vanessa","Julian","Putri","Sherly","Lala","Siana","Jocelyn","Kefas","Fallen","Sofia","Nikita","jeffry","Ardifo")
age<-c(18,19,18,19,19,19,19,19,21,20,18,19,19)
gender<-c("female","male","female","female","female","female","female","male","male","female","female","female","female")
list<-list(name,age,gender)
list
## [[1]]
## [1] "vanessa" "Julian" "Putri" "Sherly" "Lala" "Siana" "Jocelyn"
## [8] "Kefas" "Fallen" "Sofia" "Nikita" "jeffry" "Ardifo"
##
## [[2]]
## [1] 18 19 18 19 19 19 19 19 21 20 18 19 19
##
## [[3]]
## [1] "female" "male" "female" "female" "female" "female" "female" "male"
## [9] "male" "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:
marital_status <- factor(c("no","no","no","no", "no", "no", "no", "no", "no", "no", "no", "no"))
marital_status
## [1] no no no no no no no no no no no no
## Levels: no
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("Julian","Nikita","Vanessa","Jocelyn","Sherly","Putri"),gender=c("male","female","female","female","female","female"),age=c(19,18,18,19,19,18),marital_status=c("single","single","single","single","single","single"),address_by_city=c("Tangerang","Tangerang","Manado","Tangerang","Tangerang","Tangerang"), stringsAsFactors = F)
DF1
## id name gender age marital_status address_by_city
## 1 1 Julian male 19 single Tangerang
## 2 2 Nikita female 18 single Tangerang
## 3 3 Vanessa female 18 single Manado
## 4 4 Jocelyn female 19 single Tangerang
## 5 5 Sherly female 19 single Tangerang
## 6 6 Putri female 18 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(7:12),name=c("Fallen","Sofia","Lala","Jeffry","Kefas","Ardifo"),gender=c("male","female","female","male","female","female"),age=c(21,20,19,19,19,19),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 7 Fallen male 21 single Tangerang
## 2 8 Sofia female 20 single Tangerang
## 3 9 Lala female 19 single Tangerang
## 4 10 Jeffry male 19 single Tangerang
## 5 11 Kefas female 19 single Tangerang
## 6 12 Ardifo female 19 single Tangerang
In this final exercise, please consider the following tasks:
DF1
and DF2
, assign it as SB19
variable!## id name gender age marital_status address_by_city
## 1 1 Julian male 19 single Tangerang
## 2 2 Nikita female 18 single Tangerang
## 3 3 Vanessa female 18 single Manado
## 4 4 Jocelyn female 19 single Tangerang
## 5 5 Sherly female 19 single Tangerang
## 6 6 Putri female 18 single Tangerang
## 7 7 Fallen male 21 single Tangerang
## 8 8 Sofia female 20 single Tangerang
## 9 9 Lala female 19 single Tangerang
## 10 10 Jeffry male 19 single Tangerang
## 11 11 Kefas female 19 single Tangerang
## 12 12 Ardifo female 19 single Tangerang
SB19
!## id name gender age marital_status address_by_city
## 1 1 Julian male 19 single Tangerang
## 2 2 Nikita female 18 single Tangerang
## 3 3 Vanessa female 18 single Manado
## 4 4 Jocelyn female 19 single Tangerang
## 5 5 Sherly female 19 single Tangerang
## 6 6 Putri female 18 single Tangerang
## 7 7 Fallen male 21 single Tangerang
## 8 8 Sofia female 20 single Tangerang
## 9 9 Lala female 19 single Tangerang
## 10 10 Jeffry male 19 single Tangerang
## 11 11 Kefas female 19 single Tangerang
## 12 12 Ardifo female 19 single Tangerang
SB19
dataset!## id name gender age marital_status address_by_city
## 1 1 Julian male 19 single Tangerang
## 2 2 Nikita female 18 single Tangerang
## 3 3 Vanessa female 18 single Manado
SB19
dataset like an Excel file on your Rstudio?SB19
!## 'data.frame': 12 obs. of 6 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ name : chr "Julian" "Nikita" "Vanessa" "Jocelyn" ...
## $ gender : chr "male" "female" "female" "female" ...
## $ age : num 19 18 18 19 19 18 21 20 19 19 ...
## $ marital_status : chr "single" "single" "single" "single" ...
## $ address_by_city: chr "Tangerang" "Tangerang" "Manado" "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 marital_status address_by_city
## 1 1 Julian male 19 single Tangerang
## 2 7 Fallen male 21 single Tangerang
## 3 10 Jeffry male 19 single Tangerang
## id name gender age marital_status address_by_city
## 1 2 Nikita female 18 single Tangerang
## 2 3 Vanessa female 18 single Manado
## 3 4 Jocelyn female 19 single Tangerang
## 4 5 Sherly female 19 single Tangerang
## 5 6 Putri female 18 single Tangerang
## 6 8 Sofia female 20 single Tangerang
## 7 9 Lala female 19 single Tangerang
## 8 11 Kefas female 19 single Tangerang
## 9 12 Ardifo female 19 single Tangerang