by Albert Major
nrow(data) to see how many rows (movies) are in the dataset and ncol(data) to check the number of columns (variables).summary(data) provides a quick overview of key statistics for all variables, including mean, median, minimum, and maximum values.table(column_name) to count how many times a specific category appears (e.g., how many movies belong to the drama genre).subset(data, condition). This allows users to analyze specific subsets of their dataset.as.factor(), which makes it easier to analyze and summarize categorical data efficiently.is.na(data) to identify missing values, which is crucial in data analysis to avoid errors.The dataset contains a column called rating, which represents the IMDb score of each movie.
We can sort the dataset to find the highest-rated movies:
ordered_movies <- data[order(-data$rating), ]
head(ordered_movies, 10)
This will display the top 10 highest-rated movies.
Example results: The Shawshank Redemption (9.3 rating), The Godfather, and other critically acclaimed films.
Additional filtering can be done, such as finding only high-rated comedies or movies released after a certain year.
A scatter plot helps us see how movie ratings change over release years:
plot(data$year, data$rating, xlab="Release Year", ylab="IMDb Rating", main="Movie Ratings Over Time", col="blue", cex=0.5)
Observations:
Customizing scatter plots:
cex=0.3 makes dots smaller for better visibility.col="red" can highlight certain categories.abline(lm(data$rating ~ data$year), col="black") adds a regression line.A histogram shows how movie ratings are distributed:
hist(data$rating, breaks=20, col="pink", main="Distribution of IMDb Ratings", xlab="Rating", ylab="Frequency")
Observations:
breaks=50 for a more detailed view.Adding density lines:
hist(data$rating, probability=TRUE, col="lightblue", main="Density of Ratings")
lines(density(data$rating), col="red", lwd=2)
This helps us see the smooth distribution of data rather than just bar counts.