Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

Data science with R( Sept 14 - Sept 30,2020)| Rahul

Hi All... With regards to the comcast project , i have completed it but an error is incurring while using the Rmarkdown.

The error is

"Error in `$<-.data.frame`(`*tmp*`, ComplaintType, value = c(NA, NA, NA, :
replacement has 1441 rows, data has 2224"

Could you please assist so that i can submit the project
 

Hitesh H S

Well-Known Member
Staff member
Simplilearn Support
Hi,

still on that comcast project and now i am trying the wordcloud that we learnt in class. However, the borrowed code from class doesn't help.
I tried looking up forums with no answer. Anyone have the answer

library(tm)
install.packages("tmap")
library(tmap)
detach(package:tm, unload=TRUE)
df3=complaint$Customer_Complaint
df3<- Corpus(df3)
inspect(df3)
toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
df3 <- tm_map(df3, toSpace, "@")
df3 <- tm_map(df3, toSpace, "-")
df3 <- tm_map(df3, toSpace, "@")
df3 <- tm_map(df3, toSpace, "/")
df3 <- tm_map(df3, toSpace, "!")
df3 <- tm_map(df3, toSpace, "?")
inspect(df3)


Regards,
Flynn
Hi Flynn,

Please find the below code for your reference:

library("wordcloud2")
library("tm")
library("SnowballC")
library("wordcloud")
library("RColorBrewer")

df <-(comcast$Customer.Complaint)

# Load the data as a corpus
#library("corpus")
docs <- Corpus(VectorSource(dh))
class(docs)

inspect(docs)

#Text toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
docs <- tm_map(docs, toSpace, "/")
docs <- tm_map(docs, toSpace, "@")
docs <- tm_map(docs, toSpace, "\\|")

CLEANING Convert the text to lower case
docs <- tm_map(docs, content_transformer(tolower))
# Remove numbers
docs <- tm_map(docs, removeNumbers) #
Remove english common stopwords
docs <- tm_map(docs, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
docs <- tm_map(docs, removeWords, c("blabla1", "blabla2"))
# Remove punctuations
docs <- tm_map(docs, removePunctuation)
# Eliminate extra white spaces
docs <- tm_map(docs, stripWhitespace)

DTM
dtm <- TermDocumentMatrix(docs)
m <- as.matrix(dtm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 10)

set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 2,scale=c(5.5,0.60), max.words=200, random.order=FALSE, rot.per=0.75,colors=brewer.pal(8, "Paired"))

I hope this helps you.

Happy Learning !!!
 

Hitesh H S

Well-Known Member
Staff member
Simplilearn Support
Hi All... With regards to the comcast project , i have completed it but an error is incurring while using the Rmarkdown.

The error is

"Error in `$<-.data.frame`(`*tmp*`, ComplaintType, value = c(NA, NA, NA, :
replacement has 1441 rows, data has 2224"

Could you please assist so that i can submit the project
Hi Vivek,

Can you please share the complete code so that we can help you accordingly.

Happy Learning
 

Flynn_1

Member
Any luck with the comcast project. I am still stuck with no help. I have my code below. Does anyone know how to generate a wordcloud. I followed what we learnt in class and i am unable to solve it.

complaint=read.csv("C:/Users/flynn/Downloads/1567503160_comcasttelecomcomplaintsdata/Comcast_Complaints.csv")
View(complaint)
complaint_new=complaint
names(complaint)[1]<-"Ticket"
names(complaint)<- gsub( "\\.", "_", names(complaint))
View(complaint)
sum(is.na(complaint))
complaint$Dt<-parse_date_time(complaint$Date, orders="%d!-%m!-%y!")
complaint$month<-month(complaint$Dt)
complaint$month= format(complaint$Dt, "%B")
complaint$day=strftime(complaint$Dt, "%A")
View(complaint)
df1=dplyr::select(complaint, Customer_Complaint, month)%>%group_by(month)%>% summarize(nbr_records=n())
View(df1)
unique(complaint$Status)
df2=dplyr::select(complaint, Customer_Complaint, day)%>%group_by(day)%>% summarize(nbr_records=n())
View(df2)
complaint = transform(complaint,FinalStatus = ifelse((Status=='Open'|Status=='Pending'),"Open","Closed"))
View(complaint)
df3 = VCorpus(VectorSource(complaint$Customer_Complaint))
View(df3)
df4 <- tolower(df3)
View(df4)
# Cleaning data by removing punctuations, numbers etc
df4 <- gsub("@", " ", df4)
df4 <- gsub("[[:punct:]]", " ", df4)
df4 <- gsub("#\\w+", "", df4)
df4 <- gsub("[^\x01-\x7F]", "", df4)
df4 <- gsub("\\d+\\w*\\d*", "", df4)
df4 <- gsub("$", "", df4)
df4 <- gsub("%", "", df4)
df4 <- gsub("[[:digit:]]", "", df4)
df4 <- stripWhitespace(df4)
View(df4)
# remove stop words
df4 <- removeWords(df4, stopwords())
View(df4)
df4 <- VectorSource(df4)
#create a corpus object
df4 <- VCorpus(df4)
#feed it to tdm
#Creating matrix
dtm <- TermDocumentMatrix(df4)
View(dtm)
m <- as.matrix(df4)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 10)
set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words=200, random.order=FALSE, rot.per=0.35,
colorPalette = "black")
 

Flynn_1

Member
Thanks Hitesh, it works. I found out that my mistake was with the as.matrix function. For some reason the code from the class was not working. I tried instead and it works. The reference helped as well
dtm <- TermDocumentMatrix(df4) %>%
as.matrix()
View(dtm)




Hi Flynn,

Please find the below code for your reference:

library("wordcloud2")
library("tm")
library("SnowballC")
library("wordcloud")
library("RColorBrewer")

df <-(comcast$Customer.Complaint)

# Load the data as a corpus
#library("corpus")
docs <- Corpus(VectorSource(dh))
class(docs)

inspect(docs)

#Text toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
docs <- tm_map(docs, toSpace, "/")
docs <- tm_map(docs, toSpace, "@")
docs <- tm_map(docs, toSpace, "\\|")

CLEANING Convert the text to lower case
docs <- tm_map(docs, content_transformer(tolower))
# Remove numbers
docs <- tm_map(docs, removeNumbers) #
Remove english common stopwords
docs <- tm_map(docs, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
docs <- tm_map(docs, removeWords, c("blabla1", "blabla2"))
# Remove punctuations
docs <- tm_map(docs, removePunctuation)
# Eliminate extra white spaces
docs <- tm_map(docs, stripWhitespace)

DTM
dtm <- TermDocumentMatrix(docs)
m <- as.matrix(dtm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 10)

set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 2,scale=c(5.5,0.60), max.words=200, random.order=FALSE, rot.per=0.75,colors=brewer.pal(8, "Paired"))

I hope this helps you.

Happy Learning !!!
 

Hitesh H S

Well-Known Member
Staff member
Simplilearn Support
Thanks Hitesh, it works. I found out that my mistake was with the as.matrix function. For some reason the code from the class was not working. I tried instead and it works. The reference helped as well
dtm <- TermDocumentMatrix(df4) %>%
as.matrix()
View(dtm)
I am Glad this helped you.

Happy Learning !!!
 
plz help, i got stuck, not able to complete my project
always getting this error message while knitting in r markdown

"Error in object[] : object of type 'closure' is not subsettable
Calls: <Anonymous> ... withVisible -> eval -> eval -> summary -> summary.default
Execution halted"
Screenshot 2020-10-05 005441.jpg
 

Hitesh H S

Well-Known Member
Staff member
Simplilearn Support
plz help, i got stuck, not able to complete my project
always getting this error message while knitting in r markdown

"Error in object[] : object of type 'closure' is not subsettable
Calls: <Anonymous> ... withVisible -> eval -> eval -> summary -> summary.default
Execution halted"
View attachment 11865
Hi Ashish,

The reason why you are getting this error is that there is some problem with your code. Please check your code properly before you knit.

Happy Learning !!!!
 
I have a question regarding the comcast project.

I created a code to try to answer the question below
Which complaint types are maximum i.e., around internet, network issues, or across any other domains.
- Create a new categorical variable with value as Open and Closed. Open & Pending is to be categorized as Open and Closed & Solved is to be categorized as Closed.

Could you tell me why the code is not working. I basically want to use the if statement to create a new column. I thought it would be simple but cannot figure out the solution. Thanks in advance


if (complaint$Status == "Open" |"Pending" )
{
complaint$Status_Category = "Open"
}else{
complaint$Status_Category = "Closed"
}

View(complaint)
I Tried like this.

str(unique(ComcastData$Status))
ComcastData$NewCat = gsub(pattern = '\\Pending',replacement = 'Open', x= ComcastData$Status)
str(unique(ComcastData$NewCat))
View(ComcastData)
ComcastData$NewCat = gsub(pattern = '\\Solved',replacement = 'Closed', x= ComcastData$NewCat)
View(ComcastData)
str(unique(ComcastData$NewCat))
 
Hi
Did anyone try the simulation test? How did it go? It's MCQs right? So how is it actually? Do we need to execute commands in R and find answers or is the pattern more theoretical?
Thank You
 

Hitesh H S

Well-Known Member
Staff member
Simplilearn Support
Hi,
I haven't submitted my Project yet. I have been tested Covid +ve. Is it fine if I take some more time?
Hi Karthik,

Please do not worry about submitting your project now. You can start working on your project after recovering.

Get well soon !!!
 

Trapti Jain

Active Member
Guys
I am getting an error while trying ggplot please check the below code and error

install.packages("tidyverse")
library(tidyverse)

install.packages("ggmap")
library(ggplot2)
ggplot2()

ggplot2()
Error in ggplot2() : could not find function "ggplot2"

TIA
 
upload_2020-10-11_7-13-51.png

Hi Hitesh can you pls help me out in importing the output so that i can submit the project.
While doing knit to pdf am getting this Error as line 19 not found.
though i tried installing tinytex package but still no use
 
Last edited:

Hitesh H S

Well-Known Member
Staff member
Simplilearn Support
View attachment 12020

Hi Hitesh can you pls help me out in importing the output so that i can submit the project.
While doing knit to pdf am getting this Error as line 19 not found.
though i tried installing tinytex package but still no use
Hi Rakesh,

Your getting this error because the object is nor initiated. Please refer to line no. 21 and do the necessary changes. Post that you'll be able to kint the script to HTML.

In case you still face this issue, please reach out to us by raising a ticket.

I hope this helps you.

Happy Learning!!!
 

_89902

Member
## Provide the trend chart for the number of complaints at monthly and daily granularity levels.

ComcastData$Month=strftime(ComcastData$DateLubridate,"%b")

ComcastData$DateNew=strftime(ComcastData$DateLubridate,"%d")

library(dplyr)
View(ComcastData)

## Number of complaints at a daily level
daily_count=ComcastData %>% group_by(ComcastData$DateNew)%>%filter %>% summarize(NumofComplaints=n()) %>% arrange(desc(NumofComplaints))

daily_count

## Number of complaints at a monthly level
monthly_count=ComcastData %>% group_by(ComcastData$Month) %>% summarize(NumofComplaints=n()) %>% arrange(desc(NumofComplaints))

monthly_count



monthly_count=select(summarise(group_by(ComcastData,Month=as.integer(Month(DateLubridate))),
Count=n()),Month)

monthly_count

esquisse::esquisser()
### Trend chart for Month and Counts

library(ggplot2)

ggplot(monthly_count)+
geom_line(mapping = aes(x =ComcastData$Month, y= NumberofComplaints)) +
xlab("Month") + ylab("Noofcomplaints") +
theme(panel.background=element_blank()) +
theme(plot.background=element_rect(fill = "white")) +
theme(panel.grid.major=element_line(color="dark grey")) + labs(title = "Month vs Count")+
scale_x_continuous(breaks = monthly_count$Month)


#### Trend chart for Day and counts

ggplot(daily_count) +
geom_line(mapping = aes(x =Date, y=Count)) +
theme(axis.text = element_text(angle = 75)) +
scale_x_datetime(breaks = "1 week",date_labels = "%d/%m") +
xlab("Date") + ylab("Noofcomplaints") + labs(title = "Trend chart for n of complaints at daily levels") +
ylim(0,200) + theme(panel.background=element_blank()) +
theme(plot.background=element_rect(fill = "white")) +
theme(panel.grid.major=element_line(color="dark grey"))

I am unable to plot trend chart. Please help
 

Hitesh H S

Well-Known Member
Staff member
Simplilearn Support
## Provide the trend chart for the number of complaints at monthly and daily granularity levels.

ComcastData$Month=strftime(ComcastData$DateLubridate,"%b")

ComcastData$DateNew=strftime(ComcastData$DateLubridate,"%d")

library(dplyr)
View(ComcastData)

## Number of complaints at a daily level
daily_count=ComcastData %>% group_by(ComcastData$DateNew)%>%filter %>% summarize(NumofComplaints=n()) %>% arrange(desc(NumofComplaints))

daily_count

## Number of complaints at a monthly level
monthly_count=ComcastData %>% group_by(ComcastData$Month) %>% summarize(NumofComplaints=n()) %>% arrange(desc(NumofComplaints))

monthly_count



monthly_count=select(summarise(group_by(ComcastData,Month=as.integer(Month(DateLubridate))),
Count=n()),Month)

monthly_count

esquisse::esquisser()
### Trend chart for Month and Counts

library(ggplot2)

ggplot(monthly_count)+
geom_line(mapping = aes(x =ComcastData$Month, y= NumberofComplaints)) +
xlab("Month") + ylab("Noofcomplaints") +
theme(panel.background=element_blank()) +
theme(plot.background=element_rect(fill = "white")) +
theme(panel.grid.major=element_line(color="dark grey")) + labs(title = "Month vs Count")+
scale_x_continuous(breaks = monthly_count$Month)


#### Trend chart for Day and counts

ggplot(daily_count) +
geom_line(mapping = aes(x =Date, y=Count)) +
theme(axis.text = element_text(angle = 75)) +
scale_x_datetime(breaks = "1 week",date_labels = "%d/%m") +
xlab("Date") + ylab("Noofcomplaints") + labs(title = "Trend chart for n of complaints at daily levels") +
ylim(0,200) + theme(panel.background=element_blank()) +
theme(plot.background=element_rect(fill = "white")) +
theme(panel.grid.major=element_line(color="dark grey"))

I am unable to plot trend chart. Please help
Hi Learner,

can you please let us know what is the exact error that you're facing? kindly revert by sharing the exact error that you're facing and also attach screenshots.
 

_89902

Member
Hello everyone

Please help me with this one


network_tickets=contains(ComcastData$CustomerComplaint,match='network',ignore.case = T)

internet_tickets=contains(ComcastData$CustomerComplaint,match = 'internet',ignore.case = T)

bill_tickets=contains(ComcastData$CustomerComplaint,match='bill',ignore.case = T)

email_tickets=contains(ComcastData$CustomerComplaint,match="email", ignore.case = T)

charge_tickets=contains(ComcastData$CustomerComplaint,match='charge ',ignore.case = T)

ComcastData$ComplaintType[network_tickets]='Network'
ComcastData$ComplaintType[internet_tickets]='Internet'

ComcastData$ComplaintType[bill_tickets]='Billing'
ComcastData$ComplaintType[email_tickets]='Email'

ComcastData$ComplaintType[charge_tickets]='Charges'

ComcastData$ComplaintType[- c(network_tickets,internet_tickets,bill_tickets,email_tickets,charge_tickets)]="Others"

View(ComcastData)


Error
Error in `$<-.data.frame`(`*tmp*`, ComplaintType, value = c(NA, NA, NA, :
replacement has 1441 rows, data has 2224
i am finding this error. Please help team
 
Hi Flynn,

Please find the below code for your reference:

library("wordcloud2")
library("tm")
library("SnowballC")
library("wordcloud")
library("RColorBrewer")

df <-(comcast$Customer.Complaint)

# Load the data as a corpus
#library("corpus")
docs <- Corpus(VectorSource(dh))
class(docs)

inspect(docs)

#Text toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
docs <- tm_map(docs, toSpace, "/")
docs <- tm_map(docs, toSpace, "@")
docs <- tm_map(docs, toSpace, "\\|")

CLEANING Convert the text to lower case
docs <- tm_map(docs, content_transformer(tolower))
# Remove numbers
docs <- tm_map(docs, removeNumbers) #
Remove english common stopwords
docs <- tm_map(docs, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
docs <- tm_map(docs, removeWords, c("blabla1", "blabla2"))
# Remove punctuations
docs <- tm_map(docs, removePunctuation)
# Eliminate extra white spaces
docs <- tm_map(docs, stripWhitespace)

DTM
dtm <- TermDocumentMatrix(docs)
m <- as.matrix(dtm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 10)

set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 2,scale=c(5.5,0.60), max.words=200, random.order=FALSE, rot.per=0.75,colors=brewer.pal(8, "Paired"))

I hope this helps you.

Happy Learning !!!



Can you please help after doing this word cloude how to flag it to a new variable? what i mean is after doing this how to categorise the wordcloud output into particular issue type like internet,network, sevice issue, biiling issue
 
Last edited:

Divya Pandove

Member
Alumni
Hi - I am going through the recordings of this course and some of them are not available for me to download (screenshot attached). I am particularly interested in the below two recordings:

Sept 24
Sept 29

Can someone help me resolve this issue?

Thank you!!!
 

Attachments

  • Screen Shot 2020-11-22 at 4.50.14 PM.png
    Screen Shot 2020-11-22 at 4.50.14 PM.png
    95.2 KB · Views: 0

Trapti Jain

Active Member
Hello everyone ,
I am trying to do comcast project, while manipulating the data facing the error, please find the below

Comcast.Complaints.data$Date<- dmy(Comcast.Complaints.data$Date)
Comcast.Complaints.data$Date<-dmy(Comcast.Complaints.data$Date)
Error in dmy(Comcast.Complaints.data$Date) :
could not find function "dmy"

when i am calling library (lubridate)
getting below error

library(lubridate)
Error: package or namespace load failed for ‘lubridate’ in get(Info[i, 1], envir = env):
cannot open file 'C:/Users/Dell/Documents/R/win-library/4.0/generics/R/generics.rdb': No such file or directory
In addition: Warning message:
package ‘lubridate’ was built under R version 4.0.2

Kindly help
 
Top