100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary Intro. To Research in Marketing Spring R Codes Assignments

Rating
-
Sold
1
Pages
15
Uploaded on
23-09-2024
Written in
2024/2025

This document includes all the necessary codes to pass the assignments for R for the course Introduction to Research in Marketing. Each week the assignments differ in different versions, however only small indicated changes need to be made in the coding in the first few steps to cover the different versions of the assignment or only a different number needs to be read from the output.

Show more Read less
Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
September 23, 2024
Number of pages
15
Written in
2024/2025
Type
Summary

Subjects

Content preview

R Codes for Introduction to Research in Marketing:
R Programming:
Week 1:
# Import boxoffice data:
install.packages(c("data.table","readxl"))
library(data.table)
library(readxl)
setwd("/Users/rafaelhoutepen/Downloads/IRM")
boxofficemojo_com <- read_excel("boxofficemojo.com.xlsx")
setDT(boxofficemojo_com)
View(boxofficemojo_com)
summary(boxofficemojo_com)

# Import the imdb data:
install.packages("readr")
library(readr)
imdb_com <- read_csv("imdb.com.csv")
setDT(imdb_com)
View(imdb_com)
summary(imdb_com)
imdb_com[, budget_num := as.numeric(imdb.com_budget)]

# Merge the two data sets:
movies <- merge(boxofficemojo_com,imdb_com, by.x =
c("boxofficemojo.com_imdb.com_id"), by.y = c("imdb.com_id"), all.x = TRUE)
View(movies)

# Save the workspace and the newly created data set:
save.image("Data.RData")
write_csv(movies, "movies.csv")
install.packages("writexl")
library(writexl)
write_xlsx(movies, "movies.xlsx")

# Visualization:
boxplot(movies$boxofficemojo.com_openinggross)
table(movies$boxofficemojo.com_MPAArating)
barplot(table(movies$boxofficemojo.com_MPAArating))
barplot(table(movies$boxofficemojo.com_MPAArating)/
sum(table(movies$boxofficemojo.com_MPAArating))*100)
install.packages("ggplot2")
library(ggplot2)
ggplot(movies, aes(boxofficemojo.com_MPAArating)) + geom_bar()
ggplot(movies, aes(boxofficemojo.com_MPAArating)) + geom_bar(aes(y =
after_stat(count)/sum(after_stat(count))*100)) + ylab("percentage")

# Bivariate visualization:

, movies[, boxofficemojo.com_MPAArating_R := ifelse(boxofficemojo.com_MPAArating == 'R',
1, 0)]
movies[is.na(boxofficemojo.com_MPAArating_R), boxofficemojo.com_MPAArating_R := 0]
ggplot(movies, aes(x=as.factor(boxofficemojo.com_MPAArating_R),
y=boxofficemojo.com_openinggross)) + geom_boxplot()
ggplot(movies, aes(x=as.factor(imdb.com_basedonbook),
y=boxofficemojo.com_openinggross)) + geom_boxplot()
ggplot(movies[!is.na(imdb.com_basedonbook),], aes(x=as.factor(imdb.com_basedonbook),
y=boxofficemojo.com_openinggross)) + geom_boxplot()
ggplot(movies, aes(x=budget_num, y=boxofficemojo.com_openinggross)) + geom_point()

# Aggregate and then plot:
temp <- movies[, .(boxofficemojo.com_openinggross_mean =
mean(boxofficemojo.com_openinggross)), by=c("imdb.com_year")]
temp <- movies[, .(boxofficemojo.com_openinggross_mean =
mean(boxofficemojo.com_openinggross, na.rm=TRUE)), by=c("imdb.com_year")]
temp <- movies[!is.na(imdb.com_year), .(boxofficemojo.com_openinggross_mean =
mean(boxofficemojo.com_openinggross, na.rm=TRUE)), by=c("imdb.com_year")]
setorderv(temp, c("imdb.com_year"))
ggplot(temp, aes(x=imdb.com_year, y=boxofficemojo.com_openinggross_mean)) +
geom_line()

# Hypothesis testing:
movies[!is.na(imdb.com_basedonbook), .(boxofficemojo.com_openinggross_mean =
mean(boxofficemojo.com_openinggross, na.rm=TRUE)), by=c("imdb.com_basedonbook")]
install.packages("car")
library(car)
leveneTest(boxofficemojo.com_openinggross ~ as.factor(imdb.com_basedonbook), movies,
center=mean)
t.test(boxofficemojo.com_openinggross ~ imdb.com_basedonbook, movies,
var.equal=TRUE)

# Question 1:
subset(movies, boxofficemojo.com_openingtheaters >= 500)
wide_release_movies <- movies[boxofficemojo.com_openingtheaters >= 500]
View(wide_release_movies)

# Question 2:
# Remove NAs from 'imdb.com_genres' column in 'wide_release_movies'
wide_release_movies$imdb.com_genres <-
na.omit(wide_release_movies$imdb.com_genres)

# Create a new dataset without NAs in 'imdb.com_genres'
wide_release_movies_no_na <- wide_release_movies[!
is.na(wide_release_movies$imdb.com_genres), ]

library(dplyr)
$6.59
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Document also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
RafaelHoutepen Tilburg University
Follow You need to be logged in order to follow users or courses
Sold
188
Member since
6 year
Number of followers
60
Documents
45
Last sold
2 days ago
Rafael's University Store!

I am a Dutch student at Tilburg University following the Msc Marketing Management and before that I completed the pre-master in Marketing Management as well as a Bachelor in Tourism Management. I would like to make other students happy by sharing my summaries and essays

4.0

22 reviews

5
7
4
8
3
7
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions