aggregation string in R [duplicate]












0
















This question already has an answer here:




  • How to sum a variable by group?

    13 answers




I have a data frame where one column is string names (v1), and the second column is string values(v2), I would like to aggregate those entries and sum their string values.(V1 and V2 are list)



V1 and V2 are list



trp_str



    V1  V2

1 a,x,v 0.07128713

2 b,x,c 0.06336634

3 c,x,v 0.04752475

4 c,x,v 0.04752475

5 d,x,v 0.06336634

6 a,x,v 0.07128713

i want to get like this
V1 V2
1 a,x,v 0.14257426

2 b,x,c 0.06336634

3 c,x,v 0.0950495

4 d,x,v 0.06336634


when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured
Error in aggregate.data.frame(as.data.frame(x), ...) :
arguments must have same length










share|improve this question















marked as duplicate by arvi1000, zx8754 r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 7:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    dput() of sample data

    – sai saran
    Nov 19 '18 at 6:57











  • u can directly use aggregate function right?

    – sai saran
    Nov 19 '18 at 6:58











  • Pretty sure there are lot of answers for this question already, but you want aggregate. Or the dplyr package (group_by + summarise) or the built-in aggregation capabilities of the data.table package

    – arvi1000
    Nov 19 '18 at 7:00











  • when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured Error in aggregate.data.frame(as.data.frame(x), ...) : arguments must have same length

    – Kiran Pg
    Nov 19 '18 at 7:09











  • @KiranPg provide reproducible example. I think you need aggregate(trp_str$V2, by=list(V1=trp_str$V1), FUN=sum)

    – zx8754
    Nov 19 '18 at 7:30
















0
















This question already has an answer here:




  • How to sum a variable by group?

    13 answers




I have a data frame where one column is string names (v1), and the second column is string values(v2), I would like to aggregate those entries and sum their string values.(V1 and V2 are list)



V1 and V2 are list



trp_str



    V1  V2

1 a,x,v 0.07128713

2 b,x,c 0.06336634

3 c,x,v 0.04752475

4 c,x,v 0.04752475

5 d,x,v 0.06336634

6 a,x,v 0.07128713

i want to get like this
V1 V2
1 a,x,v 0.14257426

2 b,x,c 0.06336634

3 c,x,v 0.0950495

4 d,x,v 0.06336634


when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured
Error in aggregate.data.frame(as.data.frame(x), ...) :
arguments must have same length










share|improve this question















marked as duplicate by arvi1000, zx8754 r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 7:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    dput() of sample data

    – sai saran
    Nov 19 '18 at 6:57











  • u can directly use aggregate function right?

    – sai saran
    Nov 19 '18 at 6:58











  • Pretty sure there are lot of answers for this question already, but you want aggregate. Or the dplyr package (group_by + summarise) or the built-in aggregation capabilities of the data.table package

    – arvi1000
    Nov 19 '18 at 7:00











  • when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured Error in aggregate.data.frame(as.data.frame(x), ...) : arguments must have same length

    – Kiran Pg
    Nov 19 '18 at 7:09











  • @KiranPg provide reproducible example. I think you need aggregate(trp_str$V2, by=list(V1=trp_str$V1), FUN=sum)

    – zx8754
    Nov 19 '18 at 7:30














0












0








0









This question already has an answer here:




  • How to sum a variable by group?

    13 answers




I have a data frame where one column is string names (v1), and the second column is string values(v2), I would like to aggregate those entries and sum their string values.(V1 and V2 are list)



V1 and V2 are list



trp_str



    V1  V2

1 a,x,v 0.07128713

2 b,x,c 0.06336634

3 c,x,v 0.04752475

4 c,x,v 0.04752475

5 d,x,v 0.06336634

6 a,x,v 0.07128713

i want to get like this
V1 V2
1 a,x,v 0.14257426

2 b,x,c 0.06336634

3 c,x,v 0.0950495

4 d,x,v 0.06336634


when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured
Error in aggregate.data.frame(as.data.frame(x), ...) :
arguments must have same length










share|improve this question

















This question already has an answer here:




  • How to sum a variable by group?

    13 answers




I have a data frame where one column is string names (v1), and the second column is string values(v2), I would like to aggregate those entries and sum their string values.(V1 and V2 are list)



V1 and V2 are list



trp_str



    V1  V2

1 a,x,v 0.07128713

2 b,x,c 0.06336634

3 c,x,v 0.04752475

4 c,x,v 0.04752475

5 d,x,v 0.06336634

6 a,x,v 0.07128713

i want to get like this
V1 V2
1 a,x,v 0.14257426

2 b,x,c 0.06336634

3 c,x,v 0.0950495

4 d,x,v 0.06336634


when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured
Error in aggregate.data.frame(as.data.frame(x), ...) :
arguments must have same length





This question already has an answer here:




  • How to sum a variable by group?

    13 answers








r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 11:40







Kiran Pg

















asked Nov 19 '18 at 6:55









Kiran PgKiran Pg

239




239




marked as duplicate by arvi1000, zx8754 r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 7:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by arvi1000, zx8754 r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 7:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    dput() of sample data

    – sai saran
    Nov 19 '18 at 6:57











  • u can directly use aggregate function right?

    – sai saran
    Nov 19 '18 at 6:58











  • Pretty sure there are lot of answers for this question already, but you want aggregate. Or the dplyr package (group_by + summarise) or the built-in aggregation capabilities of the data.table package

    – arvi1000
    Nov 19 '18 at 7:00











  • when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured Error in aggregate.data.frame(as.data.frame(x), ...) : arguments must have same length

    – Kiran Pg
    Nov 19 '18 at 7:09











  • @KiranPg provide reproducible example. I think you need aggregate(trp_str$V2, by=list(V1=trp_str$V1), FUN=sum)

    – zx8754
    Nov 19 '18 at 7:30














  • 1





    dput() of sample data

    – sai saran
    Nov 19 '18 at 6:57











  • u can directly use aggregate function right?

    – sai saran
    Nov 19 '18 at 6:58











  • Pretty sure there are lot of answers for this question already, but you want aggregate. Or the dplyr package (group_by + summarise) or the built-in aggregation capabilities of the data.table package

    – arvi1000
    Nov 19 '18 at 7:00











  • when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured Error in aggregate.data.frame(as.data.frame(x), ...) : arguments must have same length

    – Kiran Pg
    Nov 19 '18 at 7:09











  • @KiranPg provide reproducible example. I think you need aggregate(trp_str$V2, by=list(V1=trp_str$V1), FUN=sum)

    – zx8754
    Nov 19 '18 at 7:30








1




1





dput() of sample data

– sai saran
Nov 19 '18 at 6:57





dput() of sample data

– sai saran
Nov 19 '18 at 6:57













u can directly use aggregate function right?

– sai saran
Nov 19 '18 at 6:58





u can directly use aggregate function right?

– sai saran
Nov 19 '18 at 6:58













Pretty sure there are lot of answers for this question already, but you want aggregate. Or the dplyr package (group_by + summarise) or the built-in aggregation capabilities of the data.table package

– arvi1000
Nov 19 '18 at 7:00





Pretty sure there are lot of answers for this question already, but you want aggregate. Or the dplyr package (group_by + summarise) or the built-in aggregation capabilities of the data.table package

– arvi1000
Nov 19 '18 at 7:00













when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured Error in aggregate.data.frame(as.data.frame(x), ...) : arguments must have same length

– Kiran Pg
Nov 19 '18 at 7:09





when i used aggregate(trp_str$V1, by=list(V2=trp_str$V2), FUN=sum) following error occured Error in aggregate.data.frame(as.data.frame(x), ...) : arguments must have same length

– Kiran Pg
Nov 19 '18 at 7:09













@KiranPg provide reproducible example. I think you need aggregate(trp_str$V2, by=list(V1=trp_str$V1), FUN=sum)

– zx8754
Nov 19 '18 at 7:30





@KiranPg provide reproducible example. I think you need aggregate(trp_str$V2, by=list(V1=trp_str$V1), FUN=sum)

– zx8754
Nov 19 '18 at 7:30












1 Answer
1






active

oldest

votes


















0














This is very simple operation. A lot of it already has been answered on this site



This should work for you



library(dplyr)

df <- data.frame(V1 = c('a,x,v','b,x,c', 'c,x,v', 'c,x,v', 'd,x,v', 'a,x,v'),
V2 = c(0.07128713, 0.06336634, 0.04752475, 0.04752475, 0.06336634,0.07128713))

df %>% group_by(V1) %>% summarise(Total = sum(V2))


Basically, you group by V1 column, then use the summarise function to sum up the values in V2 column. Here, I named the column that holds the sums Total but you can name it whatever you want.






share|improve this answer
























  • when i apply this show Error in grouped_df_impl(data, unname(vars), drop) : Column V1 can't be used as a grouping variable because it's a list

    – Kiran Pg
    Nov 19 '18 at 7:46











  • if you have your data in a list format, convert it to a dataframe. I thought you said you have a dataframe.

    – Wally Ali
    Nov 20 '18 at 5:11


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














This is very simple operation. A lot of it already has been answered on this site



This should work for you



library(dplyr)

df <- data.frame(V1 = c('a,x,v','b,x,c', 'c,x,v', 'c,x,v', 'd,x,v', 'a,x,v'),
V2 = c(0.07128713, 0.06336634, 0.04752475, 0.04752475, 0.06336634,0.07128713))

df %>% group_by(V1) %>% summarise(Total = sum(V2))


Basically, you group by V1 column, then use the summarise function to sum up the values in V2 column. Here, I named the column that holds the sums Total but you can name it whatever you want.






share|improve this answer
























  • when i apply this show Error in grouped_df_impl(data, unname(vars), drop) : Column V1 can't be used as a grouping variable because it's a list

    – Kiran Pg
    Nov 19 '18 at 7:46











  • if you have your data in a list format, convert it to a dataframe. I thought you said you have a dataframe.

    – Wally Ali
    Nov 20 '18 at 5:11
















0














This is very simple operation. A lot of it already has been answered on this site



This should work for you



library(dplyr)

df <- data.frame(V1 = c('a,x,v','b,x,c', 'c,x,v', 'c,x,v', 'd,x,v', 'a,x,v'),
V2 = c(0.07128713, 0.06336634, 0.04752475, 0.04752475, 0.06336634,0.07128713))

df %>% group_by(V1) %>% summarise(Total = sum(V2))


Basically, you group by V1 column, then use the summarise function to sum up the values in V2 column. Here, I named the column that holds the sums Total but you can name it whatever you want.






share|improve this answer
























  • when i apply this show Error in grouped_df_impl(data, unname(vars), drop) : Column V1 can't be used as a grouping variable because it's a list

    – Kiran Pg
    Nov 19 '18 at 7:46











  • if you have your data in a list format, convert it to a dataframe. I thought you said you have a dataframe.

    – Wally Ali
    Nov 20 '18 at 5:11














0












0








0







This is very simple operation. A lot of it already has been answered on this site



This should work for you



library(dplyr)

df <- data.frame(V1 = c('a,x,v','b,x,c', 'c,x,v', 'c,x,v', 'd,x,v', 'a,x,v'),
V2 = c(0.07128713, 0.06336634, 0.04752475, 0.04752475, 0.06336634,0.07128713))

df %>% group_by(V1) %>% summarise(Total = sum(V2))


Basically, you group by V1 column, then use the summarise function to sum up the values in V2 column. Here, I named the column that holds the sums Total but you can name it whatever you want.






share|improve this answer













This is very simple operation. A lot of it already has been answered on this site



This should work for you



library(dplyr)

df <- data.frame(V1 = c('a,x,v','b,x,c', 'c,x,v', 'c,x,v', 'd,x,v', 'a,x,v'),
V2 = c(0.07128713, 0.06336634, 0.04752475, 0.04752475, 0.06336634,0.07128713))

df %>% group_by(V1) %>% summarise(Total = sum(V2))


Basically, you group by V1 column, then use the summarise function to sum up the values in V2 column. Here, I named the column that holds the sums Total but you can name it whatever you want.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 7:18









Wally AliWally Ali

2,162917




2,162917













  • when i apply this show Error in grouped_df_impl(data, unname(vars), drop) : Column V1 can't be used as a grouping variable because it's a list

    – Kiran Pg
    Nov 19 '18 at 7:46











  • if you have your data in a list format, convert it to a dataframe. I thought you said you have a dataframe.

    – Wally Ali
    Nov 20 '18 at 5:11



















  • when i apply this show Error in grouped_df_impl(data, unname(vars), drop) : Column V1 can't be used as a grouping variable because it's a list

    – Kiran Pg
    Nov 19 '18 at 7:46











  • if you have your data in a list format, convert it to a dataframe. I thought you said you have a dataframe.

    – Wally Ali
    Nov 20 '18 at 5:11

















when i apply this show Error in grouped_df_impl(data, unname(vars), drop) : Column V1 can't be used as a grouping variable because it's a list

– Kiran Pg
Nov 19 '18 at 7:46





when i apply this show Error in grouped_df_impl(data, unname(vars), drop) : Column V1 can't be used as a grouping variable because it's a list

– Kiran Pg
Nov 19 '18 at 7:46













if you have your data in a list format, convert it to a dataframe. I thought you said you have a dataframe.

– Wally Ali
Nov 20 '18 at 5:11





if you have your data in a list format, convert it to a dataframe. I thought you said you have a dataframe.

– Wally Ali
Nov 20 '18 at 5:11



Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?