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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:41:44+00:00 2026-06-15T14:41:44+00:00

I would like to add a column to a data frame with the count

  • 0

I would like to add a column to a data frame with the count of matches in another data frame, this seems pretty trivial but I can’t seem to get it to work. Example:

smaller_df$CountOfMatches <- nrow(subset(larger_df, Date == smaller_df$Date))

This gives me the error:

In `==.default`(Date, smaller_df$Date) :
  longer object length is not a multiple of shorter object length

I know the data frames are different lengths, I’m not asking for a merge, I simply need for that for every row/date (valid date object) in the smaller_df; a count how many matches in the larger_df.

I’m very new to R so there must be something fundamental and very trivial I’m missing here.

Thanks in advance

  • 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-15T14:41:45+00:00Added an answer on June 15, 2026 at 2:41 pm

    Here’s what seems fairly straightforward:

    smaller_df$bigDfCount <-sapply( smaller_df$Date,  
                            FUN=function(x) length(larger_df[larger_df$Date==x, "Date"] ) )
    smaller_df
    
             Date bigDfCount
    1  2000-01-01          4
    2  2000-01-02          2
    3  2000-01-03          5
    4  2000-01-04          4
    5  2000-01-05          5
    6  2000-01-06          6
    7  2000-01-07          2
    8  2000-01-08          5
    9  2000-01-09          3
    10 2000-01-10          3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add a column to every data frame in my R
I would like to add a column from behind code to a data bound
I have a data frame with 1666 rows. I would like to add a
I have a dataframe and would like to add a new column where the
I have own project and i would like add for this class same as
this is a simple html question but I would like to know the correct
I would like to add a column to the table which contains either of
How can you add variables to a dataframe in a for-loop? I would like
I would like to add the data entered in the text box to the
How would I convert a column of R formulas to include the data frame

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.