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.
Create a vector B containing 12 character values; all names of your classmate including yourself.
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,] 81.68144 73.29600 82.41606 85.42531
## [2,] 71.00837 91.38658 71.11925 94.14819
## [3,] 92.68124 82.02532 67.72642 73.71539
## [4,] 81.54683 75.35091 89.74501 96.79342
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,] 49.70648 43.63910 37.04688 48.32535
## [2,] 36.88629 44.94298 36.46199 41.16777
## [3,] 34.95572 30.24714 37.60137 55.60057
## [4,] 46.56440 49.07322 37.29046 44.21500
## [,1] [,2] [,3] [,4]
## [1,] 245.0443 219.8880 247.2482 256.2759
## [2,] 213.0251 274.1597 213.3578 282.4446
## [3,] 278.0437 246.0760 203.1793 221.1462
## [4,] 244.6405 226.0527 269.2350 290.3803
## [,1] [,2] [,3] [,4]
## [1,] 131.3879 116.9351 119.4629 133.7507
## [2,] 107.8947 136.3296 107.5812 135.3160
## [3,] 127.6370 112.2725 105.3278 129.3160
## [4,] 128.1112 124.4241 127.0355 141.0084
## [,1] [,2] [,3] [,4]
## [1,] 31.97496 29.65690 45.36918 37.09996
## [2,] 34.12208 46.44361 34.65726 52.98042
## [3,] 57.72553 51.77818 30.12505 18.11482
## [4,] 34.98243 26.27769 52.45455 52.57842
## [,1] [,2] [,3] [,4]
## [1,] 4060.097 3198.572 3053.258 4128.208
## [2,] 2619.235 4107.185 2593.150 3875.872
## [3,] 3239.739 2481.031 2546.607 4098.618
## [4,] 3797.179 3697.712 3346.633 4279.721
## [,1] [,2] [,3] [,4]
## [1,] 1.643275 1.679595 2.224642 1.767712
## [2,] 1.925061 2.033390 1.950504 2.286939
## [3,] 2.651390 2.711837 1.801169 1.325803
## [4,] 1.751270 1.535479 2.406648 2.189154
## [1] -200218.6
## [,1] [,2] [,3] [,4]
## [1,] -0.1872203 -0.04029345 0.08121915 0.1425697
## [2,] 0.2415703 0.05038687 -0.06303488 -0.2142027
## [3,] 0.3664700 0.01524629 -0.11225602 -0.2527675
## [4,] -0.3701096 -0.01941426 0.08472672 0.2913306
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.## [1] "Fallen" "Lala" "Siana" "Julian" "Kefas" "Ardifo" "Jeffry"
## [8] "Vanessa" "Angel" "Sherly" "Nikita" "Irene"
## [1] 86.95994 78.74587 75.87039 99.71909 94.53966 65.17817 66.86537 85.16390
## [9] 78.02772 83.83012 96.56034 79.37854
## names scores
## [1,] "Fallen" "86.9599413871765"
## [2,] "Lala" "78.7458743341267"
## [3,] "Siana" "75.8703937008977"
## [4,] "Julian" "99.71909083426"
## [5,] "Kefas" "94.5396636147052"
## [6,] "Ardifo" "65.1781670004129"
## [7,] "Jeffry" "66.8653709534556"
## [8,] "Vanessa" "85.1638979185373"
## [9,] "Angel" "78.0277225840837"
## [10,] "Sherly" "83.8301196880639"
## [11,] "Nikita" "96.5603438857943"
## [12,] "Irene" "79.3785389792174"
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("Fallen","Lala","Siana","Julian","Kefas","Ardifo","Jeffry","Vanessa","Angel","Sherly","Nikita","Irene")
age <- c("21","19","19","19","19","19","19","19","19","19","19","19")
gender <- c("male", "female", "female", "male", "male", "male", "male", "female", "female", "female", "female", "female")
List <- list(name, age, gender)
List## [[1]]
## [1] "Fallen" "Lala" "Siana" "Julian" "Kefas" "Ardifo" "Jeffry"
## [8] "Vanessa" "Angel" "Sherly" "Nikita" "Irene"
##
## [[2]]
## [1] "21" "19" "19" "19" "19" "19" "19" "19" "19" "19" "19" "19"
##
## [[3]]
## [1] "male" "female" "female" "male" "male" "male" "male" "female"
## [9] "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("married","single","married","single","single","married","single","married","married","single","married","single"))
marital_status## [1] married single married single single married single married married
## [10] single married single
## Levels: married single
## [[1]]
## [1] "Fallen" "Lala" "Siana" "Julian" "Kefas" "Ardifo" "Jeffry"
## [8] "Vanessa" "Angel" "Sherly" "Nikita" "Irene"
##
## [[2]]
## [1] "21" "19" "19" "19" "19" "19" "19" "19" "19" "19" "19" "19"
##
## [[3]]
## [1] "male" "female" "female" "male" "male" "male" "male" "female"
## [9] "female" "female" "female" "female"
##
## [[4]]
## [1] married single married single single married single married married
## [10] single married single
## Levels: married single
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", "Vanessa", "Sherly", "Angel", "Jeffry", "Jocelyn"),
gender = c("Male", "Female", "Female", "Female", "Male", "Female"),
age = c("19","19","19","19","19","19"),
marital_status = c("single","single","single","single","single","single"),
address_by_city = c("Tangerang", "Manado", "Jakarta", "Tangerang", "Tangerang", "Tangerang"),
stringsAsFactors = F)
DF1## id name gender age marital_status address_by_city
## 1 1 Julian Male 19 single Tangerang
## 2 2 Vanessa Female 19 single Manado
## 3 3 Sherly Female 19 single Jakarta
## 4 4 Angel Female 19 single Tangerang
## 5 5 Jeffry Male 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(7:12),
name = c("Kefas", "Nikita", "Ardifo", "Siana", "Fallen", "Ayu"),
gender = c("Male", "Female", "Male", "Female", "Male", "Female"),
age = c("19","19","19","19","21","19"),
marital_status = c("single","single","single","single","single","single"),
address_by_city = c("Tangerang", "Jakarta", "Palangkaraya", "Tangerang", "Tangerang", "Jakarta"),
stringsAsFactors = F)
DF2## id name gender age marital_status address_by_city
## 1 7 Kefas Male 19 single Tangerang
## 2 8 Nikita Female 19 single Jakarta
## 3 9 Ardifo Male 19 single Palangkaraya
## 4 10 Siana Female 19 single Tangerang
## 5 11 Fallen Male 21 single Tangerang
## 6 12 Ayu Female 19 single Jakarta
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 Julian Male 19 single Tangerang
## 2 2 Vanessa Female 19 single Manado
## 3 3 Sherly Female 19 single Jakarta
## 4 4 Angel Female 19 single Tangerang
## 5 5 Jeffry Male 19 single Tangerang
## 6 6 Jocelyn Female 19 single Tangerang
## 7 7 Kefas Male 19 single Tangerang
## 8 8 Nikita Female 19 single Jakarta
## 9 9 Ardifo Male 19 single Palangkaraya
## 10 10 Siana Female 19 single Tangerang
## 11 11 Fallen Male 21 single Tangerang
## 12 12 Ayu Female 19 single Jakarta
## id name gender age marital_status address_by_city
## 1 1 Julian Male 19 single Tangerang
## 2 2 Vanessa Female 19 single Manado
## 3 3 Sherly Female 19 single Jakarta
## 'data.frame': 12 obs. of 6 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ name : chr "Julian" "Vanessa" "Sherly" "Angel" ...
## $ gender : chr "Male" "Female" "Female" "Female" ...
## $ age : chr "19" "19" "19" "19" ...
## $ marital_status : chr "single" "single" "single" "single" ...
## $ address_by_city: chr "Tangerang" "Manado" "Jakarta" "Tangerang" ...
## [1] 12 6
Using filter we can split the data by categoty we want
##
## 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 5 Jeffry Male 19 single Tangerang
## 3 7 Kefas Male 19 single Tangerang
## 4 9 Ardifo Male 19 single Palangkaraya
## 5 11 Fallen Male 21 single Tangerang
## id name gender age marital_status address_by_city
## 1 2 Vanessa Female 19 single Manado
## 2 3 Sherly Female 19 single Jakarta
## 3 4 Angel Female 19 single Tangerang
## 4 6 Jocelyn Female 19 single Tangerang
## 5 8 Nikita Female 19 single Jakarta
## 6 10 Siana Female 19 single Tangerang
## 7 12 Ayu Female 19 single Jakarta