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 8242411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:09:40+00:00 2026-06-07T21:09:40+00:00

I have data saved in a long list. This is an example of the

  • 0

I have data saved in a long list. This is an example of the first six lines / records:

A <- list(c("JAMES","CHARLES","JAMES","RICHARD"),  
    c("JOHN","ROBERT","CHARLES"),  
    c("CHARLES","WILLIAM","CHARLES","MICHAEL","WILLIAM","DAVID","CHARLES","WILLIAM"),  
    c("CHARLES"),  
    c("CHARLES","CHARLES"),  
    c("MATTHEW","CHARLES","JACK"))  

Now I would like to calculate the relative frequency with which each unique term occurs in each line / record.
Based on my example I would like to achieve an output similar to this:

[1] "JAMES" 0.5 "CHARLES" 0.25 "RICHARD" 0.25  
[2] "JOHN" 0.3333333 "ROBERT" 0.3333333 "CHARLES" 0.3333333  
[3] "CHARLES" 0.375 "WILLIAM" 0.375 "MICHAEL" 0.125 "DAVID" 0.125  
[4] "CHARLES" 1  
[5] "CHARLES" 1  
[6] "MATTHEW" 0.3333333 "CHARLES" 0.3333333 "JACK" 0.3333333  

So far I only know how to calculate the relative frequency of individual terms, unfortunately; e.g.:

> (sapply(A, function(x)sum(grepl("JAMES", x))))/sapply(A, length)  
[1] 0.5 0.0 0.0 0.0 0.0 0.0  

My example contains only ten unique terms, of course. But my actual data contains almost 200 unique terms so the approach above wouldn’t be feasible. Therefore I’m looking for a different way which would allow me to calculate the relative frequency of all of the terms in just one go, please.
In addition to that I would like to sum up these relative frequencies for each unique name over all lines / records.
Based on my example above I would like to achieve an output similar to this one, please:

[1] "JAMES" 0.5  
[2] "CHARLES" 3.291667  
[3] "RICHARD" 0.25  
[4] "JOHN" 0.3333333  
[5] "ROBERT" 0.3333333  
[6] "WILLIAM" 0.375  
[7] "MICHAEL" 0.125  
[8] "DAVID" 0.125  
[9] "MATTHEW" 0.3333333  
[10] "JACK" 0.3333333  

Thank you very much in advance for your consideration!

  • 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-07T21:09:42+00:00Added an answer on June 7, 2026 at 9:09 pm

    You could use ?table and ?aggregate:

    BL <- lapply(A, function(x)table(x)/length(x))
    ## turn list into a vector
    B <- unlist(BL)
    
    ## sum all frequencies
    aggregate(B, list(names(B)), FUN=sum)
    #   Group.1         x
    #1  CHARLES 3.2916667
    #2    DAVID 0.1250000
    #3     JACK 0.3333333
    #4    JAMES 0.5000000
    #5     JOHN 0.3333333
    #6  MATTHEW 0.3333333
    #7  MICHAEL 0.1250000
    #8  RICHARD 0.2500000
    #9   ROBERT 0.3333333
    #10 WILLIAM 0.3750000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the data below saved as a pandas dataframe . With this data,
I have no control over how the data is saved in this table. However,
I have saved data which was saved using NSUserDefaults. I was under the impression
I have following query and data saved in a MySQL database with a timestamp
I have a datatable which contains yearly data saved. e.g. dtDate Value 2010-01-01 00:00:00.000
I have a raw image file that is saved in binary data (no encoding).
I have a MongoDB collection with data that was not saved through my Derby
I have this function // add history paths and save data function AddPath( strTag,
Hi this is a simple question, however I have now stared at it long
i have all my students data in s variable i.e first name,last name,id. which

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.