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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:35:51+00:00 2026-06-18T22:35:51+00:00

I am trying to take the following data, and then uses this data to

  • 0

I am trying to take the following data, and then uses this data to create a table which has the information broken down by state.

Here’s the data:

> head(mydf2, 10)
    lead_id buyer_account_id amount state
1  52055267               62    300    CA
2  52055267               64    264    CA
3  52055305               64    152    CA
4  52057682               62     75    NJ
5  52060519               62    750    OR
6  52060519               64    574    OR
15 52065951               64    152    TN
17 52066749               62    600    CO
18 52062751               64    167    OR
20 52071186               64    925    MN

I’ve allready subset the states that I’m interested in and have just the data I’m interested in:

mydf2 = subset(mydf, state %in% c("NV","AL","OR","CO","TN","SC","MN","NJ","KY","CA"))

Here’s an idea of what I’m looking for:

State     Amount       Count
NV        1              50  
NV        2              35  
NV        3              20
NV        4              15
AL        1              10 
AL        2              6
AL        3              4
AL        4              1
...

For each state, I’m trying to find a count for each amount “level.” I don’t necessary need to group the amount variable, but keep in mind that they are are not just 1,2,3, etc

> mydf$amount
   [1]  300  264  152   75  750  574  113  152  750  152  675  489  188  263  152  152  600  167   34  925  375  156  675  152  488  204  152  152
  [29]  600  489  488   75  152  152  489  222  563  215  452  152  152   75  100  113  152  150  152  150  152  452  150  152  152  225  600  620
  [57]  113  152  150  152  152  152  152  152  152  152  640  236  152  480  152  152  200  152  560  152  240  222  152  152  120  257  152  400

Is there an elegant solution for this in R for this or will I be stuck using Excel (yuck!).

  • 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-18T22:35:53+00:00Added an answer on June 18, 2026 at 10:35 pm

    I am not sure if I understand correctly (you have two data.frames mydf and mydf2). I’ll assume your data is in mydf. Using aggregate:

    mydf$count <- 1:nrow(mydf)
    aggregate(data = mydf, count ~ amount + state, length)
    

    Is this what you are looking for?

    Note: here count is a variable that is created just to get directly the output of the 3rd column as count.

    Alternatives with ddply from plyr:

    # no need to create a variable called count
    ddply(mydf, .(state, amount), summarise, count=length(lead_id))
    

    Here’ one could use any column that exists in one’s data instead of lead_id. Even state:

    ddply(mydf, .(state, amount), summarise, count=length(state))
    

    Or equivalently without using summarise:

    ddply(mydf, .(state, amount), function(x) c(count=nrow(x)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to scrape data from the table at the following url: http://www.nfpa.org/itemDetail.asp?categoryID=953&itemID=23033 The
I'm trying to do the following(in this order): Create a Rich Text Format file
I am trying to take information out of a MySQL database, which I will
I couldn't find any information pertaining to this question. I am trying to create
I'm trying to do the following: http://www.pastebin.org/113337 I'm wondering why the scrolling won't take
trying to take this content: <div class=content>one,two,three</div> <div class=content>four,five,six</div> <div class=content>seven,eight,nine</div> and .split and
I'm trying to take a multibyte string of Greek characters and trim it down
I'm trying to use the entity framework to take data (nested relationships) from one
I am trying to create a pageing and sorting object data source that before
I am trying to trying to update create a query that will sort data

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.