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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:51:58+00:00 2026-06-06T15:51:58+00:00

I am aggregating a data set in a country-year format with melted <- melt(data,

  • 0

I am aggregating a data set in a country-year format with

melted <- melt(data, id = c("ccode.a","year"))

data.fix <- function(x) c(max = max(x), sum = sum(x), min = min(x),
                          newcol = paste(x, sep = ","))
casted <- cast(melted, ccode.a + year ~ ..., data.fix)

I’d like to concatenate conflictID.a so that for instances in which I aggregate multiple rows into a single row I get all of the values of conflictID.a that were aggregated.

Here is some sample data:

dput(tail(subset(data, select=c(ccode.a,year,onset,conflictID.a)), 100))

I artificially modified the data to reproduce the problem also. So there are two cases in which there are 2 or more rows that have the same year and ccode.a value, but different conflictID.a values, which I’d like to concatenate together on aggregation to a single row per each ccode.a, year.

structure(list(ccode.a = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 41L, 41L, 
41L, 52L, 52L, 70L, 70L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 
90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 
92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 
93L, 93L, 93L, 93L, 93L, 93L, 93L, 93L, 93L, 93L, 93L, 93L, 95L, 
95L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 
100L, 100L, 101L, 101L, 115L, 130L), year = c(2001, 2001, 2001, 
2005, 2006, 2007, 2008, 1989, 1991, 2004, 1990, 1990, 1994, 1996, 
1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 
1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1979, 
1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 
1991, 1977, 1978, 1979, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 
1989, 1990, 1989, 1989, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 
1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 
1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 
2004, 2005, 2006, 2007, 2008, 1982, 1982, 1982, 1995), onset = c(1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), conflictID.a = c(224L, 
224L, 224L, 224L, 224L, 224L, 224L, 186L, 186L, 186L, 183L, 183L, 
205L, 205L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 
36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 120L, 
120L, 120L, 120L, 120L, 120L, 120L, 120L, 120L, 120L, 120L, 120L, 
120L, 140L, 140L, 140L, 140L, 140L, 140L, 140L, 140L, 140L, 140L, 
140L, 140L, 173L, 172L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 
92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 
92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 
80L, 80L, 162L, 208L)), .Names = c("ccode.a", "year", "onset", 
"conflictID.a"), row.names = c(127L, 128L, 130L, 131L, 132L, 
133L, 134L, 277L, 279L, 292L, 395L, 396L, 452L, 454L, 494L, 495L, 
496L, 497L, 498L, 499L, 500L, 501L, 502L, 503L, 504L, 505L, 506L, 
507L, 508L, 509L, 510L, 511L, 512L, 513L, 514L, 566L, 567L, 568L, 
569L, 570L, 571L, 572L, 573L, 574L, 575L, 576L, 577L, 578L, 598L, 
599L, 600L, 603L, 604L, 605L, 606L, 607L, 608L, 609L, 610L, 611L, 
678L, 679L, 699L, 700L, 701L, 702L, 703L, 704L, 705L, 706L, 707L, 
708L, 709L, 710L, 711L, 712L, 713L, 714L, 715L, 716L, 717L, 718L, 
719L, 720L, 721L, 722L, 723L, 724L, 725L, 726L, 727L, 728L, 729L, 
730L, 731L, 732L, 740L, 750L, 812L, 854L), class = "data.frame")
  • 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-06T15:51:59+00:00Added an answer on June 6, 2026 at 3:51 pm

    You don’t need reshape for this, just use plain aggregate.

    # All aggregated values
    aggregate(data$conflictID.a,by=list(data$ccode.a,data$year),c)
    # Just unique values
    aggregate(data$conflictID.a,by=list(data$ccode.a,data$year),unique)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From what I understand, Mashup is aggregating data from separate sources and providing a
I understand that cubes are optimized data structures for aggregating and slicing large amounts
I have a, say, daily income data set of numeric Temporal Properties , like:
I'm working on a project which involves aggregating data from a variety of sources
I'm trying to generate a data set, and I think recursion is required, but
I'm working on a class responsible for aggregating data from several sites at once.
Following up my previous question about aggregating hourly data into daily data, I want
I am Aggregating the data on 'INTERIM_AUTO' table on the basis of Unit ID,
I'm aggregating data from one table into another using a query similar to these:
We have a system that allows users interfacing data into the database to set

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.