M

@mjclave123

Data Frame & Lists

R
3 years ago
# These are the methode which can store multi type not like vector array or matrix. Country_data_1 = data.frame(country = c('India', 'US', 'UK'), population = c(1420000000, 50000000, 45000000), EU = c(FALSE,TRUE,TRUE)) Country_data_1 class(Countr

section -7 exercise

R
3 years ago
#1 matrix_example = matrix(c(100,23,42,23,342,203), nrow=3, ncol=2) matrix_example #2 one_matrix = matrix_example/matrix_example #one_matrix #3 one_matrix[,1] = log(matrix_example[,1])

section 7 coding exercise

R
3 years ago
# Create a matrix with 5 rows and three columns # named pokemons # Feed the following data: # c(120, 100, 40, 50, 80, 36, 40, 10, 25, 30, # 3, 1, 1, 1, 2) # Leave the default byrow argument pokemons = matrix(c(120, 100, 40, 50, 80, 36, 40, 10, 25

Matrix

R
3 years ago
# by default matrix is filled by column example_matrix = matrix(data=1:5, nrow=10, ncol=5) #example_matrix #class(example_matrix) matrix_1 = matrix(data=(1:6), nrow = 2, ncol = 3, byrow=TRUE) matrix_2 = matrix(data=(7:12), nrow = 3, ncol = 2, byro

section 6 practical exercise

R
3 years ago
#1 fourdim = array(1:10,c(2,3,2,2)) #2 fourdim[2,2,2,2]= NA #3 mean(fourdim, na.rm=TRUE) #4

section 6(paper)

R
3 years ago
# Create a 4 dimensional array based on the vector # 1:4 and with 3, 4, 5 and 2 elements on each dimension, # by this order # save the array on a multidim named object multidim <- array(1:4,dim=c(3,4,5,2)) multidim # Save the vector with the

combining Arrays

R
3 years ago
my_array = array(2:5,c(2,2)) this_array = array(14:17,c(2,2)) print('My_Array') my_array print('This_array') this_array print('combining arrays on row') my_array_1 = rbind(my_array,this_array) my_array_1

dimnames feature in array

R
3 years ago
country_data = array(c(40000,12000,3,0.5,20000,1300000,2.3,5),c(2,2,2), dimnames = list(c('US','India'),c('Population','GDP'),c(2001,2023))) country_data country_data['India','GDP','2001'] country_data['US','Population','2023'] # to fetch the dim

Calculation on array

R
3 years ago
my_arrray = array(c(100,100,100),c(3,3,2)) my_arrray print('apply squre root on first matrix of array') my_arrray[,,1] = sqrt(my_arrray[, , 1]) my_arrray print('2nd columns of 1st matrix power of 3') my_arrray[,2,1] = my_arrray[,2,1]**3 my_arrray

basics of Array

R
3 years ago
my_array = array(1:16,c(4,4)) my_array #All rows in 4th column my_array[,4] #2nd and 3rd rows in 3rd column my_array[2:3,3]

introduction in array

R
3 years ago
#R arrays are the methode to store the data in multiple dimension # as vector is a type of methode to store the data in single dimenison. #array_name[row,column,matrix] example_array = array(data=c(10,14,15,20,21,24,23,25), dim=c(2,4,1)) example_

section-5 exercise

R
3 years ago
#1 boolean_vec = c(TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE) #2 numeric_vec = as.numeric(boolean_vec) #numeric_vec #3 is.numeric(numeric_vec)

section-5(Data type)

R
3 years ago
# This is our example vector (don't change this) years <- c(2008,2009,2010,2011,2012,2013, "YEAR") # Extract the underlying data type of the vector years # and store it in a variable called type_years type_years = typeof(years) type_years #

Dealing with Dates

R
3 years ago
dates = as.Date(c('15-06-2023','25-06-2023'), format='%d-%m-%Y') class(dates) typeof(dates) num_dates = as.numeric(dates) class(num_dates) dates[1:length(dates)]

Factor Data type

R
3 years ago
# It is used to store the distinct data it make the code run faster if you are having large amount of data # because it just store the distinct values with index numbers. labels = c('Asia','Africa','Oceania','Europe','Antarctica','North America' ,'

section-5.4

R
3 years ago
word = "23" as.numeric(word) years = c(2001, 2002, 2003, "Not a year") class(years) new_years = as.character(years) new_years[1:length(new_years)] n_years = as.numeric(new_years) n_years[1:length(n_years)]

typeof & is feature

R
3 years ago
n_vector = c(23,45,34,67) class(n_vector) typeof(n_vector) c_vector = c(1,2,3,"4") class(c_vector) typeof(c_vector) as.numeric(c_vector)+3

section-5

R
3 years ago
number = 1 class(number) typeof(number) my_date = as.Date('01-01-2023') class(my_date) typeof(my_date) as.numeric(my_date) word = "NewsPaper"

Data type conversion

R
3 years ago
v = "12345" # data type conversion as.integer(v)+12345 as.numeric(v) num =1 as.logical(num) as.character(v) # to get the Data type of a variable

Assessment_1(secion 4)

R
3 years ago
kids_ages = c(12, 11, 12, 13, 14, 13, 12, 10, 12, 12, 14, 13) mean(kids_ages) median(kids_ages) subset_ages = c(kids_ages < 11 | kids_ages>13) subset_ages[1:length(subset_ages)] names(kids_ages) = c("John", "Rachel", "Joe", "Anne", "There