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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:17:23+00:00 2026-06-17T20:17:23+00:00

I have a data set (test) v1 v2 v3 v4 v5 v6 1 1

  • 0

I have a data set (test)

v1 v2  v3  v4  v5  v6
1   1   1   0   0   0 
2   2   1   1   0   0 
3   2   1   0   0   0 
4   3   1   0   0   0 
5   3   1   1   0   1 
6   3   1   0   1   1 

structure(list(V1 = 1:6, V2 = c(1L, 2L, 2L, 3L, 3L, 3L), V3 = c(1L, 
1L, 1L, 1L, 1L, 1L), V4 = c(0L, 1L, 0L, 0L, 1L, 0L), V5 = c(0L, 
0L, 0L, 0L, 0L, 1L), V6 = c(0L, 0L, 0L, 0L, 1L, 1L)), .Names = c("V1", 
"V2", "V3", "V4", "V5", "V6"), class = "data.frame", row.names = c(NA, 
-6L))

and I want to achieve this

v1  v2  v3  v4  v5  v6
 1   1   1   0   0   0  
 5   2   2   1   0   0  
15   3   3   1   1   2  

I have tried this:

aggregate(test[c('v3', 'v4', 'v5','v6')], list('v2'), FUN=sum, na.rm=TRUE)

which is not working. I want to aggregate the data in (test) based on V2 and sum the other variables.

  • 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-17T20:17:24+00:00Added an answer on June 17, 2026 at 8:17 pm

    Change your aggregate command to:

    aggregate(. ~ V2, test, sum)
    #   V2 V1 V3 V4 V5 V6
    # 1  1  1  1  0  0  0
    # 2  2  5  2  1  0  0
    # 3  3 15  3  1  1  2
    

    Some things to note:

    1. R is case sensitive. The sample data you provided has variables named with upper-case “V”s, but the sample code you’ve tried has lower-case “v”s.
    2. You’re trying to refer to the variable names directly. For that, you either need to be using the formula notation for aggregate() or you need to be using with() or (not recommended) attach().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a melted data.frame, dput(x), below: ## dput(x) x <- structure(list(variable = structure(c(1L,
Another ggplot legend question! I have a dataset of the form test <- data.frame(
I have a data set that resembles this: id product_id size color price created_date
I can't figure out why this isn't working. I have a data set with
I have the dataframe test <- structure(list( y2002 = c(freshman,freshman,freshman,sophomore,sophomore,senior), y2003 = c(freshman,junior,junior,sophomore,sophomore,senior), y2004
I have a table structure like this: CREATE TABLE `test` ( `a` tinyint(3) unsigned
I have the following simple data structure (details omitted for brevity): @Audited @Entity class
I have a dataset and I want to test to see how close it
I have a data set comprised of 5 minute price observations (not an xts
I have a data set with over 50,000 geocoded points (lat-long). Each point has

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.