Recent Question/Assignment

Exercise 4 – Text Mining & Sentiment Analysis
Prince is considered among one the most talented American musicians of his generation. He was a songwriter who could perform at a professional level on virtually all the instruments he required. Some people say that he wrote more than 1,000 songs in a wide range of genera like funk, soul, jazz, heavy metal, punk, and disco, amongst others.
His lyrics were very diverse and talked about various topics. In this exercise, you will discover the most used words in his songs lyrics and some of the emotions that he showed through some of his songs.
1. Download the file prince_data.csv from Blackboard.
2. In R-Studio create a new R program with the following code. Make sure to insert your own R code in the red markings of the code below.
#set the working directory setwd(-c:\YourPath\YourFolder-)
# for nrc and afinn lexicons install.packages(-textdata-)
#load the necessary libraries to run the analysis
#remembr to install the libraries first if you have not done so library(tidytext)
library(dplyr) library(stringr) library(wordcloud2) library(sentimentr) library(ggplot2)
# Read the dataset that contains the lyrics to Princes songs prince.df - read.csv(-prince_data.csv-)
#get the “nrc” lexicon ***Note that you will have to install the library for the first time before running this line ***
get_sentiments(-nrc-)
#create a token of words - separate the sentences into individual words #put the token of words in a variable named princeTable
Insert your code here

#filter “joy” sentiments from the nrc lexicon
nrc_joy - get_sentiments(-nrc-) % % filter(sentiment == -joy-)
#filter “fear” sentiments form the nrc lexicon
nrc_fear - get_sentiments(-nrc-) % % filter(sentiment == -fear-)
#filter all the words from princeTable that are part of the album “Purple Rain” and place them in a variable named prince_album
Insert your code here
# merge Prince’s album words with the joy words from nrc and count them.
Place the results into a variable named prince_joy
prince_joy - prince_album % % inner_join(nrc_joy) % % count(word, sort
= TRUE)
# merge Prince’s album words with the fear words from nrc and count them. Place the results into a variable named prince_fear
Insert your code here
#create a word cloud for the “joy” words in Prince’s “Purple Rain” album Insert your code here
#create a word cloud for the “fear” words in Prince’s “Purple Rain” album Insert your code here
3. Create a MS-Word document. Take screen shots of the R code (take as many to show the whole code) also, convert both word clouds to .jpeg* files and insert them in your Word document as pictures.
*Use the “Export” option on R-Studio’s Viewer Tab to save the image as .jpeg

Looking for answers ?


Recent Questions