filter the same values in a row add the same values together












0















In the sample of the dataset below, from the icase_id column, I want to remove numbers that appear more than two (>2) and less than (<2) times.



icase_id 2,2,3,3,3,1,4,4



summ
2
3
1
2
3
4
2
1




  1. after doing that, want to count the total of each set of numbers and save it in one single icase_id, example as this:


icase_id 2, 4



summ 5, 3



so i need someones help how to accomplished this exercise. Thanking in advance










share|improve this question

























  • So, would you say you want to keep only the values that occur exactly 3 times? What have you tried, where are you stuck?

    – Gregor
    Nov 14 '18 at 2:35











  • yeah in the icase_id column, i want to keep only values that occure 3x. less than or more than 3x will be removed. then in the second point, sum the values using one specific number identity as shown in figure 2. i tried mRS_score %>% dplyr::filter(icase_id %in% ==3) but that gives me different output compare to what am asking

    – Karamo
    Nov 14 '18 at 2:48













  • icase_id %in% 3 would only keep icase_id if its value is 3. You need to count each case id. Look up group_by and n(). .Reading An introduction to dplyr would be a good place to start - it covers this stuff well.

    – Gregor
    Nov 14 '18 at 3:03











  • Pls post data no pictures

    – vaettchen
    Nov 14 '18 at 3:25











  • i want to do that i was not able to post data thats why.. sorry for that..

    – Karamo
    Nov 14 '18 at 4:13
















0















In the sample of the dataset below, from the icase_id column, I want to remove numbers that appear more than two (>2) and less than (<2) times.



icase_id 2,2,3,3,3,1,4,4



summ
2
3
1
2
3
4
2
1




  1. after doing that, want to count the total of each set of numbers and save it in one single icase_id, example as this:


icase_id 2, 4



summ 5, 3



so i need someones help how to accomplished this exercise. Thanking in advance










share|improve this question

























  • So, would you say you want to keep only the values that occur exactly 3 times? What have you tried, where are you stuck?

    – Gregor
    Nov 14 '18 at 2:35











  • yeah in the icase_id column, i want to keep only values that occure 3x. less than or more than 3x will be removed. then in the second point, sum the values using one specific number identity as shown in figure 2. i tried mRS_score %>% dplyr::filter(icase_id %in% ==3) but that gives me different output compare to what am asking

    – Karamo
    Nov 14 '18 at 2:48













  • icase_id %in% 3 would only keep icase_id if its value is 3. You need to count each case id. Look up group_by and n(). .Reading An introduction to dplyr would be a good place to start - it covers this stuff well.

    – Gregor
    Nov 14 '18 at 3:03











  • Pls post data no pictures

    – vaettchen
    Nov 14 '18 at 3:25











  • i want to do that i was not able to post data thats why.. sorry for that..

    – Karamo
    Nov 14 '18 at 4:13














0












0








0








In the sample of the dataset below, from the icase_id column, I want to remove numbers that appear more than two (>2) and less than (<2) times.



icase_id 2,2,3,3,3,1,4,4



summ
2
3
1
2
3
4
2
1




  1. after doing that, want to count the total of each set of numbers and save it in one single icase_id, example as this:


icase_id 2, 4



summ 5, 3



so i need someones help how to accomplished this exercise. Thanking in advance










share|improve this question
















In the sample of the dataset below, from the icase_id column, I want to remove numbers that appear more than two (>2) and less than (<2) times.



icase_id 2,2,3,3,3,1,4,4



summ
2
3
1
2
3
4
2
1




  1. after doing that, want to count the total of each set of numbers and save it in one single icase_id, example as this:


icase_id 2, 4



summ 5, 3



so i need someones help how to accomplished this exercise. Thanking in advance







r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 4:24







Karamo

















asked Nov 14 '18 at 2:32









KaramoKaramo

102




102













  • So, would you say you want to keep only the values that occur exactly 3 times? What have you tried, where are you stuck?

    – Gregor
    Nov 14 '18 at 2:35











  • yeah in the icase_id column, i want to keep only values that occure 3x. less than or more than 3x will be removed. then in the second point, sum the values using one specific number identity as shown in figure 2. i tried mRS_score %>% dplyr::filter(icase_id %in% ==3) but that gives me different output compare to what am asking

    – Karamo
    Nov 14 '18 at 2:48













  • icase_id %in% 3 would only keep icase_id if its value is 3. You need to count each case id. Look up group_by and n(). .Reading An introduction to dplyr would be a good place to start - it covers this stuff well.

    – Gregor
    Nov 14 '18 at 3:03











  • Pls post data no pictures

    – vaettchen
    Nov 14 '18 at 3:25











  • i want to do that i was not able to post data thats why.. sorry for that..

    – Karamo
    Nov 14 '18 at 4:13



















  • So, would you say you want to keep only the values that occur exactly 3 times? What have you tried, where are you stuck?

    – Gregor
    Nov 14 '18 at 2:35











  • yeah in the icase_id column, i want to keep only values that occure 3x. less than or more than 3x will be removed. then in the second point, sum the values using one specific number identity as shown in figure 2. i tried mRS_score %>% dplyr::filter(icase_id %in% ==3) but that gives me different output compare to what am asking

    – Karamo
    Nov 14 '18 at 2:48













  • icase_id %in% 3 would only keep icase_id if its value is 3. You need to count each case id. Look up group_by and n(). .Reading An introduction to dplyr would be a good place to start - it covers this stuff well.

    – Gregor
    Nov 14 '18 at 3:03











  • Pls post data no pictures

    – vaettchen
    Nov 14 '18 at 3:25











  • i want to do that i was not able to post data thats why.. sorry for that..

    – Karamo
    Nov 14 '18 at 4:13

















So, would you say you want to keep only the values that occur exactly 3 times? What have you tried, where are you stuck?

– Gregor
Nov 14 '18 at 2:35





So, would you say you want to keep only the values that occur exactly 3 times? What have you tried, where are you stuck?

– Gregor
Nov 14 '18 at 2:35













yeah in the icase_id column, i want to keep only values that occure 3x. less than or more than 3x will be removed. then in the second point, sum the values using one specific number identity as shown in figure 2. i tried mRS_score %>% dplyr::filter(icase_id %in% ==3) but that gives me different output compare to what am asking

– Karamo
Nov 14 '18 at 2:48







yeah in the icase_id column, i want to keep only values that occure 3x. less than or more than 3x will be removed. then in the second point, sum the values using one specific number identity as shown in figure 2. i tried mRS_score %>% dplyr::filter(icase_id %in% ==3) but that gives me different output compare to what am asking

– Karamo
Nov 14 '18 at 2:48















icase_id %in% 3 would only keep icase_id if its value is 3. You need to count each case id. Look up group_by and n(). .Reading An introduction to dplyr would be a good place to start - it covers this stuff well.

– Gregor
Nov 14 '18 at 3:03





icase_id %in% 3 would only keep icase_id if its value is 3. You need to count each case id. Look up group_by and n(). .Reading An introduction to dplyr would be a good place to start - it covers this stuff well.

– Gregor
Nov 14 '18 at 3:03













Pls post data no pictures

– vaettchen
Nov 14 '18 at 3:25





Pls post data no pictures

– vaettchen
Nov 14 '18 at 3:25













i want to do that i was not able to post data thats why.. sorry for that..

– Karamo
Nov 14 '18 at 4:13





i want to do that i was not able to post data thats why.. sorry for that..

– Karamo
Nov 14 '18 at 4:13












1 Answer
1






active

oldest

votes


















0














Pretty basic stuff with library(dplyr)



df <- cbind.data.frame(icase_id=c(2,2,3,3,3,1,4,4),summ=c(2, 3, 1, 2, 3, 4, 2, 1))

df %>%
group_by(icase_id) %>%
filter(n()==2 ) %>%
summarise(summ=sum(summ))





share|improve this answer
























  • excellent! thanks for the answer

    – Karamo
    Nov 15 '18 at 3:10











  • that was magnificent.. in case it was three columns, and i want to apply the above code to all of the dataset where will i place the square bracket and comma?

    – Karamo
    Nov 15 '18 at 3:37











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292370%2ffilter-the-same-values-in-a-row-add-the-same-values-together%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Pretty basic stuff with library(dplyr)



df <- cbind.data.frame(icase_id=c(2,2,3,3,3,1,4,4),summ=c(2, 3, 1, 2, 3, 4, 2, 1))

df %>%
group_by(icase_id) %>%
filter(n()==2 ) %>%
summarise(summ=sum(summ))





share|improve this answer
























  • excellent! thanks for the answer

    – Karamo
    Nov 15 '18 at 3:10











  • that was magnificent.. in case it was three columns, and i want to apply the above code to all of the dataset where will i place the square bracket and comma?

    – Karamo
    Nov 15 '18 at 3:37
















0














Pretty basic stuff with library(dplyr)



df <- cbind.data.frame(icase_id=c(2,2,3,3,3,1,4,4),summ=c(2, 3, 1, 2, 3, 4, 2, 1))

df %>%
group_by(icase_id) %>%
filter(n()==2 ) %>%
summarise(summ=sum(summ))





share|improve this answer
























  • excellent! thanks for the answer

    – Karamo
    Nov 15 '18 at 3:10











  • that was magnificent.. in case it was three columns, and i want to apply the above code to all of the dataset where will i place the square bracket and comma?

    – Karamo
    Nov 15 '18 at 3:37














0












0








0







Pretty basic stuff with library(dplyr)



df <- cbind.data.frame(icase_id=c(2,2,3,3,3,1,4,4),summ=c(2, 3, 1, 2, 3, 4, 2, 1))

df %>%
group_by(icase_id) %>%
filter(n()==2 ) %>%
summarise(summ=sum(summ))





share|improve this answer













Pretty basic stuff with library(dplyr)



df <- cbind.data.frame(icase_id=c(2,2,3,3,3,1,4,4),summ=c(2, 3, 1, 2, 3, 4, 2, 1))

df %>%
group_by(icase_id) %>%
filter(n()==2 ) %>%
summarise(summ=sum(summ))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 5:55









CERCER

412415




412415













  • excellent! thanks for the answer

    – Karamo
    Nov 15 '18 at 3:10











  • that was magnificent.. in case it was three columns, and i want to apply the above code to all of the dataset where will i place the square bracket and comma?

    – Karamo
    Nov 15 '18 at 3:37



















  • excellent! thanks for the answer

    – Karamo
    Nov 15 '18 at 3:10











  • that was magnificent.. in case it was three columns, and i want to apply the above code to all of the dataset where will i place the square bracket and comma?

    – Karamo
    Nov 15 '18 at 3:37

















excellent! thanks for the answer

– Karamo
Nov 15 '18 at 3:10





excellent! thanks for the answer

– Karamo
Nov 15 '18 at 3:10













that was magnificent.. in case it was three columns, and i want to apply the above code to all of the dataset where will i place the square bracket and comma?

– Karamo
Nov 15 '18 at 3:37





that was magnificent.. in case it was three columns, and i want to apply the above code to all of the dataset where will i place the square bracket and comma?

– Karamo
Nov 15 '18 at 3:37


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292370%2ffilter-the-same-values-in-a-row-add-the-same-values-together%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values