Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8211291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:22:48+00:00 2026-06-07T10:22:48+00:00

I have a list comprised of words. > head(splitWords2) [[1]] [1] Some additional information

  • 0

I have a list comprised of words.

> head(splitWords2)
[[1]]
 [1] "Some"        "additional"  "information" "that"        "we"          "would"       "need"        "to"          "replicate"   "the"        
[11] "experiment"  "is"          "how"         "much"        "vinegar"     "should"      "be"          "placed"      "in"          "each"       
[21] "identical"   "container"   "or"          "what"        "tool"        "use"         "measure"     "mass"        "of"          "four"       
[31] "different"   "samples"     "and"         "distilled"   "water"       "rinse"       "after"       "taking"      "them"        "out"        

[[2]]
 [1] "After"       "reading"     "the"         "expirement"  "I"           "realized"    "that"        "additional"  "information" "you"        
[11] "need"        "to"          "replicate"   "expireiment" "is"          "one"         "amant"       "of"          "vinegar"     "poured"     
[21] "in"          "each"        "container"   "two"         "label"       "containers"  "before"      "start"       "yar"         "and"        
[31] "three"       "write"       "a"           "conclusion"  "make"        "sure"        "results"     "are"         "accurate" 

I have a vector of words that I want to count the occurrences of in EACH element of the list, NOT the total number of occurrences in the entire list.

I think the way to do it is a combination of the str_count() function from the stringr package and one of the *ply() functions, but I can’t make it work.

numWorder1 <- sapply(ifelse(str_count(unlist(splitWords2), ignore.case("we" ) )> 0, 1, 0))

where “we” will eventually be a word from a vector of words to count occurrences of .

My ideal output would be something like:

lineNum       count
   1           0
   2           1
   3           1
   4           0
  ...         ...

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:22:50+00:00Added an answer on June 7, 2026 at 10:22 am

    For one specific word:

    words <- list(a = c("a","b","c","a","a","b"), b = c("w","w","q","a"))
    $a
    [1] "a" "b" "c" "a" "a" "b"
    
    $b
    [1] "w" "w" "q" "a"
    wt <- data.frame(lineNum = 1:length(words))
    wt$count <- sapply(words, function(x) sum(str_count(x, "a")))
      lineNum count
    1       1     3
    2       2     1
    

    If vector w contains words that you want to count:

    w <- c("a","q","e")
    allwords <- lapply(w, function(z) data.frame(lineNum = 1:length(words), 
                count = sapply(words, function(x) sum(str_count(x, z)))))
    names(allwords) <- w
    $a
      lineNum count
    a       1     3
    b       2     1
    
    $q
      lineNum count
    a       1     0
    b       2     1
    
    $e
      lineNum count
    a       1     0
    b       2     0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of words in which some are composed words, in example
I have a list view comprised of the following: // Add column headers for
I have a list of fields/columns that comprises of Sharepoint specific fields/columns, my own
i have list of rows that user select and i want to delete them,
I have a simple Smart TV app that shows a list of items in
I have a code aaabbbcccdddeee that I split up into 3 letter words (such
Friends, I have a dynamic sql query that I would like to execute and
I have a list L composed from random numbers (defvar L '(1 4 2
I have list of input area in the form with id like contact1_title, contact2_title,
I have list of articles on the page in table and i want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.