aggregation string in R [duplicate]

Multi tool use
Multi tool use












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



Xwe9pspqD,m9433Skf0occN9f,dfDToO3yxqt,70Yn6UDUOcq
nUdFGT V9YNZAcn lD1iwUnyK,uAM0

Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

Guess what letter conforming each word

Run scheduled task as local user group (not BUILTIN)