Is there a way to count how many times a specific word appears in R

mathsnoob

I am new to R and web scraping. For practice purposes I am trying to scrape information from a fake book website. So far I have managed to scrape the book titles, find the mean length of each word in the book titles, find the most used word and also find the most used word excluding stopwords. However, I am now trying to find how many times a specific word occurs. For example, how many times the word 'me' appears in the book titles, yet I am not sure how to isolate a specific word.

Code so far:

url<-'http://books.toscrape.com/index.html'

url %>%
  read_html() %>%
  html_nodes('h3 a') %>%
  html_attr('title')->titles
titles

values<-lapply(titles,nchar)
mean(unlist(values))

mostUsedWord<-head(sort(table(tolower(unlist(strsplit(titles, '\\s+')))), decreasing = TRUE))[1]
mostUsedWord 

all_words <- tolower(unlist(strsplit(titles, '\\s+')))
noStopWords <- head(sort(table(all_words[!all_words %in% tm::stopwords()]), decreasing = TRUE))[1:3]
noStopWords

I would like to find out how many times specific words occur, not just the most frequent words that are used.

user438383

Is this what you are after?

word='me'
data.frame(word = table(all_words)) %>% dplyr::filter(word.all_words == word)
word.all_words word.Freq
1             me         1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to count how many times each word appears?

From Dev

Count how many times a word appears in a text file

From Dev

Search and count how many times do the specific command appears in array

From Dev

Count How Many Times a Value Appears Php

From Dev

SQL COUNT how many times a value appears

From Dev

Count how many times a value appears in this array?

From Dev

Count how many number of times a value appears

From Dev

EXCEL: I want to count how many times a certain word appears in a column if it's in the same row if another word appears

From Dev

Excel - how to count how many times a word appears within a certain date range

From Dev

How to count how many times each individual word appears in text file

From Dev

How to search a LinkedList for a specific word and return where it is in the list and how many times it appears

From Dev

How to count the times a specific character appears in a file?

From Dev

How to count how many times a specific letter appears in a string? (C++)

From Dev

Count how many repeated times each record appears and select minimum and maximum of specific column

From Dev

Count how many times a word exist in column

From Dev

Count number of times a word appears

From Dev

How to check how many times a word appears in a txt file in php?

From Python

How to count how many times an entity appears with another entity

From Dev

How to count how many times each line appears in a file

From Dev

Excel: How to count how many times a consecutive text value appears

From Dev

Regular expressions - counting how many times a word appears in a text

From Python

Recursion function to count how many times a certain sequence appears

From Dev

count how many times a row appears in a different dataset

From Dev

Count how many times each token appears in each rows of a DataFrame

From Dev

Count how many times a character appears with another character

From Dev

Mongo: add fields with count of how many times another field appears

From Java

Look for a certain String inside another and count how many times it appears

From Dev

Count how many times a value appears continuously in Hive/SQL

From Dev

Count how many times a series of strings appears in a list - Python

Related Related

  1. 1

    how to count how many times each word appears?

  2. 2

    Count how many times a word appears in a text file

  3. 3

    Search and count how many times do the specific command appears in array

  4. 4

    Count How Many Times a Value Appears Php

  5. 5

    SQL COUNT how many times a value appears

  6. 6

    Count how many times a value appears in this array?

  7. 7

    Count how many number of times a value appears

  8. 8

    EXCEL: I want to count how many times a certain word appears in a column if it's in the same row if another word appears

  9. 9

    Excel - how to count how many times a word appears within a certain date range

  10. 10

    How to count how many times each individual word appears in text file

  11. 11

    How to search a LinkedList for a specific word and return where it is in the list and how many times it appears

  12. 12

    How to count the times a specific character appears in a file?

  13. 13

    How to count how many times a specific letter appears in a string? (C++)

  14. 14

    Count how many repeated times each record appears and select minimum and maximum of specific column

  15. 15

    Count how many times a word exist in column

  16. 16

    Count number of times a word appears

  17. 17

    How to check how many times a word appears in a txt file in php?

  18. 18

    How to count how many times an entity appears with another entity

  19. 19

    How to count how many times each line appears in a file

  20. 20

    Excel: How to count how many times a consecutive text value appears

  21. 21

    Regular expressions - counting how many times a word appears in a text

  22. 22

    Recursion function to count how many times a certain sequence appears

  23. 23

    count how many times a row appears in a different dataset

  24. 24

    Count how many times each token appears in each rows of a DataFrame

  25. 25

    Count how many times a character appears with another character

  26. 26

    Mongo: add fields with count of how many times another field appears

  27. 27

    Look for a certain String inside another and count how many times it appears

  28. 28

    Count how many times a value appears continuously in Hive/SQL

  29. 29

    Count how many times a series of strings appears in a list - Python

HotTag

Archive