This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(100) | |
clicks_28 <- round(runif (28,3000,4000)) | |
sales_28 <- seq(from=100, to=150, length = 28) | |
visitors_28 <- runif (28, 1000, 1100) | |
discount_28 <- rep(c(1,1,1,0.5),7) | |
mrp <- 5 # maximum retail price | |
daily_max_revenue <- sales_28 * mrp # daily maximum revenue | |
daily_actual_revenue <- daily_max_revenue * discount_28 # revenue with discount | |
total_revenue <- sum(daily_actual_revenue) # total revenue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Direct assignment | |
system.time ({ | |
item_id_hypo <- numeric() | |
for(i in 1:10000000){ | |
item_id_hypo[i] <- i | |
} | |
item_id_hypo | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |