## How to Create, Modify, and access elements of Create, Modify, access elements of Vectors in Rstudio

# Let us create vectors in R
# Vectors are one-dimension arrays that can hold numeric data, character data, or logical data.

`# vector defination in R # numeric vectorage <- c(3, 25, 30, 55, 60)#character vectorabc <- c("Ram", "Rahim", "Joseph", "SIdhu", "Mahaveer")abc[1] "Ram" "Rahim" "Joseph" "SIdhu" "Mahaveer"# Logical vectorlogical_vector <- c(TRUE, TRUE, TRUE, FALSE, FALSE )# How to assign names to the vectornames(age) <- c("Ram", "Rahim", "Joseph", "SIdhu", "Mahaveer")ageRam Rahim Joseph SIdhu Mahaveer 3 25 30 55 60 names(age) <- abcageRam Rahim Joseph SIdhu Mahaveer 3 25 30 55 60 age <- c(3, 25, 30, 55, 60)age2 <- c(6, 7, 8, 9, 10)Total_age <- age + age2Total_age[1] 9 32 38 64 70total_ag <- sum(age)total_ag[1] 173total_ag2 <- sum(age2)total_ag2[1] 40total_ag > total_ag2[1] TRUEtotal_ag <- mean(age)total_ag[1] 34.6total_ag2 <- mean(age2)total_ag2[1] 8total_ag == total_ag2[1] FALSEtotal_ag != total_ag2[1] TRUE# Let us go to las vegas for gambling# 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) # let us add names to the winning daysnames(poker_vector) <-c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")poker_vectorMonday Tuesday Wednesday Thursday Friday 140 -50 20 -120 240 names(roulette_vector) <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")## Alternativelydays_vector <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")names(poker_vector) <- days_vectornames(roulette_vector)<- days_vector## What was your net profit / loss every daytotal_daily <- poker_vector + roulette_vectortotal_dailyMonday Tuesday Wednesday Thursday Friday 164 0 120 230 250  # Total winnings with poker total_poker <- sum(poker_vector) # Total winnings with roulette total_roulette <-sum(roulette_vector) total_week <- (total_poker + total_roulette) total_week[1] 764 # Check if you realized higher total gains in poker than in roulette total_poker > total_roulette[1] FALSE # Define a new variable based on a selection poker_wednesday <- poker_vector[3]# Define a new variable based on a selection poker_midweek <- poker_vector[c(2, 3, 4)]poker_midweek <- poker_vector [2:4] poker_midweekTuesday Wednesday Thursday -50 20 -120  poker_monday <- poker_vector ["Monday"] poker_monday Monday 140  average_midweek_gain <- mean(poker_vector[c("Monday", "Tuesday", "Wednesday")]) average_midweek_gain <- mean(poker_vector [2:4]) # What days of the week did you make money on poker? selection_vector <- poker_vector > 0 # Select from poker_vector these days poker_winning_days <- poker_vector[selection_vector] poker_winning_daysMonday Wednesday Friday 140 20 240 # What days of the week did you make money on roulette? selection_vector <- roulette_vector > 0 # Select from roulette_vector these days roulette_winning_days <- roulette_vector[selection_vector]`