Code Is Poetry

Life is Binary

Posts

All country list in PHP

For one of my PHP works I had to implement and use the array of all countries of the world. So, with the help of net, I created the array. The code in PHP is as follows <?php$countries = array(    'AF' => 'Afghanistan',    'AX' => 'Aland Islands',    'AL' => 'Albania',    'DZ' => 'Algeria',    'AS' => 'American Samoa',    'AD' => 'Andorra',    'AO' =>...

Read more

Adding padding to uitextfield

Following code will help you to add padding to the textfield.   UITextField *myTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 200, 35)]; myTextField.delegate = self; myTextField.placeholder = @"Placeholder"; [myTextField setFont:[UIFont systemFontOfSize:14]]; myTextField.returnKeyType = UIReturnKeyDone; myTextField.keyboardType = UIKeyboardTypeDefault; UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)]; myTextField.leftView =...

Read more

Factors - Part-4

# Assign to the variable theory what this chapter is about!theory <- "factors for categorical variables" ######################### # Gender vectorgender_vector <- c("Male", "Female", "Female", "Male", "Male")# Convert gender_vector to a factorfactor_gender_vector <- factor(gender_vector)  # Print out factor_gender_vector(factor_gender_vector) ################################## # Animalsanimals_vector <- c("Elephant", "Giraffe", "Donkey", "Horse")factor_animals_vector...

Read more

Lists - Part-6

# Vector with numerics from 1 up to 10my_vector <- 1:10 # Matrix with numerics from 1 up to 9my_matrix <- matrix(1:9, ncol = 3)# First 10 elements of the built-in data frame mtcarsmy_df <- mtcars[1:10,]# Construct list with these different elements:my_list <- list(my_vector,my_matrix,my_df) ################################## # Vector with numerics from 1 up to 10my_vector <- 1:10 # Matrix with numerics from 1 up to 9my_matrix <- matrix(1:9, ncol = 3)# First 10 elements of...

Read more

data frame - Part-5

# Print out built-in R data frame(mtcars ) ############################### # Call head() on mtcarshead(mtcars)################################ # Investigate the structure of mtcarsstr(mtcars) ##################################### # Definition of vectorsname <- c("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune")type <- c("Terrestrial planet", "Terrestrial planet", "Terrestrial planet",           "Terrestrial...

Read more

Matrix - Part-3

# Construct a matrix with 3 rows that contain the numbers 1 up to 9(matrix(1:9,byrow=TRUE,nrow=3)) ################################# # Box office Star Wars (in millions!)new_hope <- c(460.998, 314.4)empire_strikes <- c(290.475, 247.900)return_jedi <- c(309.306, 165.8)# Create box_officebox_office <- c(new_hope, empire_strikes, return_jedi)# Construct star_wars_matrixstar_wars_matrix <- matrix(box_office,byrow = TRUE,nrow=3) ########################################## # Box...

Read more

Vectors in R - Part-2

# Define the variable vegasvegas <- "Go!"###################### numeric_vector <- c(1, 10, 49)character_vector <- c("a", "b", "c")# Complete the code for boolean_vectorboolean_vector <- c(TRUE, FALSE, TRUE) ############################# # Poker winnings from Monday to Fridaypoker_vector <- c(140, -50, 20, -120, 240)# Roulette winnings from Monday to Fridayroulette_vector <- c(-24, -50, 100, -350, 10) ############################### # Poker winnings from Monday to...

Read more

Basic in R - Part-1

# Calculate 3 + 43 + 4# Calculate 6 + 126 + 12####################### # An addition5 + 5 # A subtraction5 - 5 # A multiplication3 * 5 # A division(5 + 5) / 2 # Exponentiation2^5# Modulo28 %% 6 ################################ # Assign the value 42 to xx <- 42# Print out the value of the variable xx ##################################### Assign the value 5 to the variable my_applesmy_apples <- 5# Print out the value of the variable...

Read more

Condition and loop in R

# if (condition) expr1 else expr2x <- 2; y <- 10if (x==0) y <- 0 else y <- y/x #y# for (variable in sequence) exprx <- 3ASum <- 0; AProd <- 1for (i in 1:x){  ASum <- ASum + i  AProd <- AProd * i}ASum # equivalent to sum(1:x)AProd # equivalemt to prod(1:x)

Read more

factors are used to store categorical data

#factors are used to store categorical dataeyeColor.v <- c("blue","green","brown","yellow","blue","blue","blue")eyeColor.f <- factor(c("blue","green","brown","yellow","blue","blue","blue")) # 1 2 3 4eyeColor.f # it will be displayed as different levels of the factoras.numeric(eyeColor.f)

Read more