Skip to content

Instantly share code, notes, and snippets.

Avatar

Selva Prabhakaran selva86

View GitHub Profile
View 8_1_challenge_r_course.R
# 1. You have a vector which contains four coupons codes for Asian flights.
# Replace all 'asia' with 'europe'
flight_coupons <- c("asiafly", "asiaflynow", "asiaflymiles", "asiamarch")
# 2. Extract the first names from the emails.
emails <- c("vito.corleone@apple.com", "michael.corleone@reddit.com")
View 7_2_Challenge_R_Course.R
options(scipen=999)
set.seed(100)
year <- 2001:2050 # X Axis
population <- 7000 + (1:50 * runif(50, .5, .55) * 100) # Y Axis 1
econ <- sample(40:70, 50, replace = T) # Y Axis 2
View 7_1_Challenge_R_Course.R
# Make a scatterplot with following variables and which looks like this.
# Top half: Points above 150 on Y axis is 'green3' else 'red'.
# Input
set.seed(42)
x <- runif(100, min = 10, max=20)
y <- runif(100, min = 100, max= 200)
View 7_1_Challenge_R_Course.R
# Make a scatterplot with following variables and which looks like this.
# Top half: Points above 150 on Y axis is 'green3' else 'red'.
# Input
set.seed(42)
x <- runif(100, min = 10, max=20)
y <- runif(100, min = 100, max= 200)
View error_handling_challenge.R
# Add error handling to `largest_hypotenuse()` so it ignores incorrect cases and captures largest
# hypotenuse for eligible cases.
hypotenuse <- function(side1, side2){
side1 <- as.numeric(side1); side2 <- as.numeric(side2)
sqrt(side1^2 + side2^2)
}
View 6_3_Dataframes.R
country <- c("France", "Germany", "Greece", "Italy", "Portugal", "Spain") # Countries
gdp_growth <- c(1.3, 0.3, 1.9, 0.3, NA, 2) # GDP growth
mkt_type <- factor(c("High", "High", "Low", "Medium", "Low", "Medium")) # Categories
df <- data.frame(country = country,
gdp_growth = gdp_growth,
market_typ = mkt_type,
stringsAsFactors = F)
View 6_2_Dataframes2.R
country <- c("France", "Germany", "Greece",
"Italy", "Portugal", "Spain", 'Spain') # Countries
gdp_growth <- c(1.3, 0.3, 1.9, 0.3, NA, 2, 0) # GDP growth
mkt_type <- factor(c("High", "High", "Low", "Medium", "Low", "Medium", 'Low')) # Categories
df <- data.frame(country = country,
gdp_grwth = gdp_growth,
market_typ = mkt_type,
stringsAsFactors = F)
df <- rbind(df, df, df, df)
View 6_challenges.R
country <- c("France", "Germany", "Greece", "Italy", "Portugal", "Spain") # Countries
gdp_growth <- c(1.3, 0.3, 1.9, 0.3, NA, 2) # GDP growth
mkt_type <- factor(c("High", "High", "Low", "Medium", "Low", "Medium")) # Categories
df <- data.frame(country = country,
gdp_grwth = gdp_growth,
market_typ = mkt_type,
stringsAsFactors = F)
View 5_1_Lists.R
# 1. From the list m below, get the number of page likes on the 10th day of the month
reviews <- c("spongy burgers", "hot and good","crispier than expected",
"hard to chew", "too large to chew", "takes time", "filling",
"unhealthy but delicious" )
set.seed(100)
pages <- 1:100
page_likes <- round(runif(30,1000,8000),0)
m <- list(reviews,pages,page_likes)
View 4_2_SetOperations_Challenge.R
m1 <- c(7, 4, 4, 14, 8, 14, 8, 1, 4, 1, 13, 5, 12, 13, 11, 5, 15, 1, 7, 4, 8, 4)
m2 <- c(17, 18, 7, 6, 20, 9, 20, 14, 5, 12, 15, 20, 8, 14, 14, 15, 12, 7, 20, 8, 8, 13, 8)
m1
m2
# Find items that are not common between m1 and m2
You can’t perform that action at this time.