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] 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
## [26] 27 28 29 30
Create a vector B containing 12 character values; all names of your classmate including yourself.
B <- c("Angel", "Irene", "Jeffry", "Julian", "Kefas", "Lala", "Nikita", "Sherly", "Siana", "Supit", "Ardifo", "Fallen")
B## [1] "Angel" "Irene" "Jeffry" "Julian" "Kefas" "Lala" "Nikita" "Sherly"
## [9] "Siana" "Supit" "Ardifo" "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,] 73.90680 71.43729 70.82227 66.26045
## [2,] 98.04732 72.10280 74.11385 95.80472
## [3,] 81.68304 80.22039 76.32970 71.64045
## [4,] 60.87155 75.40760 80.17859 75.58125
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. library(matlib)M1, give your opinion about the result.## [,1] [,2] [,3] [,4]
## [1,] 56.11872 58.41173 58.17010 31.41097
## [2,] 43.05740 39.01182 56.41392 52.72082
## [3,] 46.22255 36.71104 56.13462 36.78458
## [4,] 52.05576 53.14185 56.76434 32.06309
## [,1] [,2] [,3] [,4]
## [1,] 221.7204 214.3119 212.4668 198.7814
## [2,] 294.1420 216.3084 222.3416 287.4142
## [3,] 245.0491 240.6612 228.9891 214.9214
## [4,] 182.6147 226.2228 240.5358 226.7438
## [,1] [,2] [,3] [,4]
## [1,] 130.0255 129.8490 128.9924 97.67142
## [2,] 141.1047 111.1146 130.5278 148.52555
## [3,] 127.9056 116.9314 132.4643 108.42504
## [4,] 112.9273 128.5494 136.9429 107.64434
## [,1] [,2] [,3] [,4]
## [1,] 17.788080 13.02556 12.65217 34.84948
## [2,] 54.989916 33.09098 17.69993 43.08390
## [3,] 35.460499 43.50935 20.19508 34.85587
## [4,] 8.815789 22.26574 23.41425 43.51816
## [,1] [,2] [,3] [,4]
## [1,] 4147.554 4172.776 4119.739 2081.305
## [2,] 4221.663 2812.861 4181.053 5050.904
## [3,] 3775.598 2944.974 4284.738 2635.264
## [4,] 3168.715 4007.299 4551.285 2423.368
## [,1] [,2] [,3] [,4]
## [1,] 1.316972 1.222996 1.217503 2.109468
## [2,] 2.277130 1.848230 1.313751 1.817208
## [3,] 1.767169 2.185184 1.359762 1.947567
## [4,] 1.169353 1.418987 1.412482 2.357267
## [1] 122839.2
## [,1] [,2] [,3] [,4]
## [1,] 0.1432684 0.00177201 -0.08255202 -0.04959873
## [2,] -0.4103731 -0.00365155 0.35464041 0.02824433
## [3,] 0.4589275 -0.03187841 -0.36528230 -0.01568714
## [4,] -0.1927977 0.03603349 0.10016123 0.04163846
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,] "Angel" "83.0653871688992"
## [2,] "Irene" "72.7124506328255"
## [3,] "Jeffry" "94.2052064090967"
## [4,] "Julian" "73.1481749005616"
## [5,] "Kefas" "92.7301126066595"
## [6,] "Lala" "86.7950434144586"
## [7,] "Nikita" "96.1977332923561"
## [8,] "Sherly" "78.0619682371616"
## [9,] "Siana" "87.2655522078276"
## [10,] "Supit" "96.3430074974895"
## [11,] "Ardifo" "70.3745798580348"
## [12,] "Fallen" "67.1457812003791"
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("Angel", "Irene", "Jeffry", "Julian", "Kefas", "Lala", "Nikita", "Sherly", "Siana", "Supit", "Ardifo", "Fallen", "sofia")
age<-c(18,18,19,19,19,19,18,19,19,18,18,20,20)
gender<-c("female","female","male","male","male","female","female","female","female","female","male","male","female")
list<-list(name,age,gender)
list## [[1]]
## [1] "Angel" "Irene" "Jeffry" "Julian" "Kefas" "Lala" "Nikita" "Sherly"
## [9] "Siana" "Supit" "Ardifo" "Fallen" "sofia"
##
## [[2]]
## [1] 18 18 19 19 19 19 18 19 19 18 18 20 20
##
## [[3]]
## [1] "female" "female" "male" "male" "male" "female" "female" "female"
## [9] "female" "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:
name<-c("Angel", "Irene", "Jeffry", "Julian", "Kefas", "Lala", "Nikita", "Sherly", "Siana", "Supit", "Ardifo", "Fallen", "sofia")
marital_status<-factor(c("no","no","no","no","no","yes","no","no","yes","yes","no","yes","no"))
marital_status## [1] no no no no no yes no no yes 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("Angel", "Irene", "Jeffry", "Julian", "Kefas", "Lala"),
gender = c("female","female","male","male","male","female"),
age = c(18,18,19,19,19,19),
marital_status = c("no","no","no","no","no","yes"),
address_by_city = c("Tangerang","Tangerang","Tangerang","Tangerang","Tangerang","Tangerang"), stringsAsFactors = F)
df1## id name gender age marital_status address_by_city
## 1 1 Angel female 18 no Tangerang
## 2 2 Irene female 18 no Tangerang
## 3 3 Jeffry male 19 no Tangerang
## 4 4 Julian male 19 no Tangerang
## 5 5 Kefas male 19 no Tangerang
## 6 6 Lala female 19 yes 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("Nikita", "Sherly", "Siana", "Supit", "Ardifo", "Fallen"),
gender = c("female","female","female","female","male","male"),
age = c(18,19,18,18,19,20),
marital_status = c("no","no","yes","yes","no","yes"),
address_by_city = c("Tangerang","Tangerang","Tangerang","Manado","Kalimantan","Tangerang"), stringsAsFactors = F)
df2## id name gender age marital_status address_by_city
## 1 1 Nikita female 18 no Tangerang
## 2 2 Sherly female 19 no Tangerang
## 3 3 Siana female 18 yes Tangerang
## 4 4 Supit female 18 yes Manado
## 5 5 Ardifo male 19 no Kalimantan
## 6 6 Fallen male 20 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 marital_status address_by_city
## 1 1 Angel female 18 no Tangerang
## 2 2 Irene female 18 no Tangerang
## 3 3 Jeffry male 19 no Tangerang
## 4 4 Julian male 19 no Tangerang
## 5 5 Kefas male 19 no Tangerang
## 6 6 Lala female 19 yes Tangerang
## 7 1 Nikita female 18 no Tangerang
## 8 2 Sherly female 19 no Tangerang
## 9 3 Siana female 18 yes Tangerang
## 10 4 Supit female 18 yes Manado
## 11 5 Ardifo male 19 no Kalimantan
## 12 6 Fallen male 20 yes Tangerang
## id name gender age marital_status address_by_city
## 1 1 Angel female 18 no Tangerang
## 2 2 Irene female 18 no Tangerang
## 3 3 Jeffry male 19 no Tangerang
## 4 4 Julian male 19 no Tangerang
## 5 5 Kefas male 19 no Tangerang
## 6 6 Lala female 19 yes Tangerang
## 'data.frame': 12 obs. of 6 variables:
## $ id : int 1 2 3 4 5 6 1 2 3 4 ...
## $ name : chr "Angel" "Irene" "Jeffry" "Julian" ...
## $ gender : chr "female" "female" "male" "male" ...
## $ age : num 18 18 19 19 19 19 18 19 18 18 ...
## $ marital_status : chr "no" "no" "no" "no" ...
## $ address_by_city: chr "Tangerang" "Tangerang" "Tangerang" "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
## [1] id name gender age
## [5] marital_status address_by_city
## <0 rows> (or 0-length row.names)