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] 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
## [1] 9 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("Vanessa","Kefas","Putri","Sherly","Julian","Siana","Irene","Jeff","Ardifo","Nikita","Falen","Pak Bakti")
B## [1] "Vanessa" "Kefas" "Putri" "Sherly" "Julian" "Siana"
## [7] "Irene" "Jeff" "Ardifo" "Nikita" "Falen" "Pak Bakti"
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,] 67.23816 61.18320 87.94154 76.33923
## [2,] 91.13866 62.44757 86.04402 79.02070
## [3,] 83.39362 75.34107 89.00813 86.00201
## [4,] 78.86857 66.94802 70.43566 91.00305
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,] 51.61999 37.29140 50.80204 56.88910
## [2,] 30.59969 39.23575 33.69697 33.52260
## [3,] 44.86591 59.46710 38.70641 50.51787
## [4,] 37.41516 53.09179 59.50612 44.41530
## [,1] [,2] [,3] [,4]
## [1,] 201.7145 183.5496 263.8246 229.0177
## [2,] 273.4160 187.3427 258.1321 237.0621
## [3,] 250.1809 226.0232 267.0244 258.0060
## [4,] 236.6057 200.8441 211.3070 273.0092
## [,1] [,2] [,3] [,4]
## [1,] 118.8582 98.4746 138.7436 133.2283
## [2,] 121.7383 101.6833 119.7410 112.5433
## [3,] 128.2595 134.8082 127.7145 136.5199
## [4,] 116.2837 120.0398 129.9418 135.4184
## [,1] [,2] [,3] [,4]
## [1,] 15.61818 23.89180 37.13950 19.45013
## [2,] 60.53897 23.21182 52.34705 45.49810
## [3,] 38.52771 15.87397 50.30171 35.48414
## [4,] 41.45341 13.85624 10.92954 46.58775
## [,1] [,2] [,3] [,4]
## [1,] 3470.833 2281.607 4467.610 4342.870
## [2,] 2788.815 2450.177 2899.423 2648.979
## [3,] 3741.530 4480.314 3445.185 4344.638
## [4,] 2950.880 3554.390 4191.353 4041.928
## [,1] [,2] [,3] [,4]
## [1,] 1.302561 1.640679 1.731063 1.341896
## [2,] 2.978418 1.591599 2.553465 2.357237
## [3,] 1.858730 1.266937 2.299571 1.702408
## [4,] 2.107931 1.260986 1.183671 2.048912
## [1] 466181.3
## [,1] [,2] [,3] [,4]
## [1,] -0.03973559 0.04599510 0.00009424 -0.00669521
## [2,] -0.05622104 -0.04517971 0.12237446 -0.02925667
## [3,] 0.04592637 0.00614591 -0.02130521 -0.02372830
## [4,] 0.04025054 -0.01138166 -0.07361857 0.05667982
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,] "Vanessa" "84.8610673937947"
## [2,] "Kefas" "62.5760619994253"
## [3,] "Putri" "79.2125416826457"
## [4,] "Sherly" "95.9395293146372"
## [5,] "Julian" "89.4922980573028"
## [6,] "Siana" "79.3086503725499"
## [7,] "Irene" "87.701786858961"
## [8,] "Jeff" "90.3806035220623"
## [9,] "Ardifo" "91.8740678392351"
## [10,] "Nikita" "66.0207219514996"
## [11,] "Falen" "67.3714509699494"
## [12,] "Pak Bakti" "93.9443835243583"
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("Kefas","Vanessa","Jeffry","Irene","Nikita","Angel","Siana","Falen","Lala","Ardifo","Julian","Sherly")
age<- c(18,18,19,19,18,19,19,22,19,19,19,19)
gender<- c("male","female","male","female","female","female","female","male","female","male","male","female")
list<- list(name,age,gender)
list## [[1]]
## [1] "Kefas" "Vanessa" "Jeffry" "Irene" "Nikita" "Angel" "Siana"
## [8] "Falen" "Lala" "Ardifo" "Julian" "Sherly"
##
## [[2]]
## [1] 18 18 19 19 18 19 19 22 19 19 19 19
##
## [[3]]
## [1] "male" "female" "male" "female" "female" "female" "female" "male"
## [9] "female" "male" "male" "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("Kefas","Vanessa","Jeffry","Irene","Nikita","Angel"),
gender= c("male","female","male","female","female","female"),
age = c(18,18,19,19,18,19),
marital_status = c("single","single","single","single",
"single","single"),
address_by_city = c("Medang","Manado","Jakarta","Tangerang","Tangerang Selatan","Tiga Raksa"),stringsAsFactors = F)
DF1## id name gender age marital_status address_by_city
## 1 1 Kefas male 18 single Medang
## 2 2 Vanessa female 18 single Manado
## 3 3 Jeffry male 19 single Jakarta
## 4 4 Irene female 19 single Tangerang
## 5 5 Nikita female 18 single Tangerang Selatan
## 6 6 Angel female 19 single Tiga Raksa
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("Siana","Falen","Lala","Ardifo","Julian","Sherly"),
gender = c("female","male","female","male","male","female"),
age = c(19,22,19,19,19,19),
marital_status = c("single","Dating","Dating","single","single","single"),
address_by_city = c("Tangerang","Manado","Tangerang","Kalimantan","Tangerang","Jakarta"),stringsAsFactors = F)
DF2## id name gender age marital_status address_by_city
## 1 7 Siana female 19 single Tangerang
## 2 8 Falen male 22 Dating Manado
## 3 9 Lala female 19 Dating Tangerang
## 4 10 Ardifo male 19 single Kalimantan
## 5 11 Julian male 19 single Tangerang
## 6 12 Sherly female 19 single Jakarta
In this final exercise, please consider the following tasks:
DF1 and DF2, assign it as SB19 variable!SB19!## id name gender age marital_status address_by_city
## 1 1 Kefas male 18 single Medang
## 2 2 Vanessa female 18 single Manado
## 3 3 Jeffry male 19 single Jakarta
## 4 4 Irene female 19 single Tangerang
## 5 5 Nikita female 18 single Tangerang Selatan
## 6 6 Angel female 19 single Tiga Raksa
## 7 7 Siana female 19 single Tangerang
## 8 8 Falen male 22 Dating Manado
## 9 9 Lala female 19 Dating Tangerang
## 10 10 Ardifo male 19 single Kalimantan
## 11 11 Julian male 19 single Tangerang
## 12 12 Sherly female 19 single Jakarta
SB19 dataset!## id name gender age marital_status address_by_city
## 1 1 Kefas male 18 single Medang
## 2 2 Vanessa female 18 single Manado
## 3 3 Jeffry male 19 single Jakarta
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 "Kefas" "Vanessa" "Jeffry" "Irene" ...
## $ gender : chr "male" "female" "male" "female" ...
## $ age : num 18 18 19 19 18 19 19 22 19 19 ...
## $ marital_status : chr "single" "single" "single" "single" ...
## $ address_by_city: chr "Medang" "Manado" "Jakarta" "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 Kefas male 18 single Medang
## 2 3 Jeffry male 19 single Jakarta
## 3 8 Falen male 22 Dating Manado
## 4 10 Ardifo male 19 single Kalimantan
## 5 11 Julian male 19 single Tangerang
## id name gender age marital_status address_by_city
## 1 2 Vanessa female 18 single Manado
## 2 4 Irene female 19 single Tangerang
## 3 5 Nikita female 18 single Tangerang Selatan
## 4 6 Angel female 19 single Tiga Raksa
## 5 7 Siana female 19 single Tangerang
## 6 9 Lala female 19 Dating Tangerang
## 7 12 Sherly female 19 single Jakarta