Re: [R] Grouping Question
Here's a very "step by step" example with dplyr as I'm trying to teach myself the Tidyverse way of being library(dplyr) # SerialMeasurementMeas_testSerial_test # 117failfail # 116passfail # 212passpass # 28passpass # 210passpass # 319failfail # 313passpass dat <- as.data.frame(list(Serial = c(1,1,2,2,2,3,3), Measurement = c(17, 16, 12, 8, 10, 19, 13), Meas_test = c("fail", "pass", "pass", "pass", "pass", "fail", "pass"))) dat %>% group_by(Serial) %>% summarise(Serial_test = sum(Meas_test == "fail")) %>% mutate(Serial_test = if_else(Serial_test > 0, 1, 0), Serial_test = factor(Serial_test, levels = 0:1, labels = c("pass", "fail"))) -> groupedDat dat %>% left_join(groupedDat) # add -> dat to the end to pip to dat Gives: Serial Measurement Meas_test Serial_test 1 1 17 failfail 2 1 16 passfail 3 2 12 passpass 4 2 8 passpass 5 2 10 passpass 6 3 19 failfail 7 3 13 passfail Would be easier for us if used dput() to share your data but thanks for the minimal example! Chris - Original Message - > From: "Ivan Krylov" > To: "Thomas Subia via R-help" > Cc: "Thomas Subia" > Sent: Sunday, 22 March, 2020 07:24:15 > Subject: Re: [R] Grouping Question > On Sat, 21 Mar 2020 20:01:30 -0700 > Thomas Subia via R-help wrote: > >> Serial_test is a pass, when all of the Meas_test are pass for a given >> serial. Else Serial_test is a fail. > > Use by/tapply in base R or dplyr::group_by if you prefer tidyverse > packages. > > -- > Best regards, > Ivan > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Chris Evans Visiting Professor, University of Sheffield I do some consultation work for the University of Roehampton and other places but remains my main Email address. I have a work web site at: https://www.psyctc.org/psyctc/ and a site I manage for CORE and CORE system trust at: http://www.coresystemtrust.org.uk/ I have "semigrated" to France, see: https://www.psyctc.org/pelerinage2016/semigrating-to-france/ That page will also take you to my blog which started with earlier joys in France and Spain! If you want to book to talk, I am trying to keep that to Thursdays and my diary is at: https://www.psyctc.org/pelerinage2016/ceworkdiary/ Beware: French time, generally an hour ahead of UK. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Grouping Question
On Sat, 21 Mar 2020 20:01:30 -0700 Thomas Subia via R-help wrote: > Serial_test is a pass, when all of the Meas_test are pass for a given > serial. Else Serial_test is a fail. Use by/tapply in base R or dplyr::group_by if you prefer tidyverse packages. -- Best regards, Ivan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Grouping Question
Colleagues, Here is my dataset. Serial Measurement Meas_test Serial_test 1 17 failfail 1 16 passfail 2 12 passpass 2 8 passpass 2 10 passpass 3 19 failfail 3 13 passpass If a measurement is less than or equal to 16, then Meas_test is pass. Else Meas_test is fail This is easy to code. Serial_test is a pass, when all of the Meas_test are pass for a given serial. Else Serial_test is a fail. I'm at a loss to figure out how to do this in R. Some guidance would be appreciated. All the best, Thomas Subia __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] grouping question
Hello I have what is probably a very simple grouping question however, given my limited exposure to R, I have not found a solution yet despite my research efforts and wild attempts at what I thought might produce some sort of result. I have a very simple list of integers that range between 1 and 24. These correspond to hours of the day. I am trying to create a grouping of Day and Night with Day = 6 to 17.99 Night = 1 to 5.59 and 18 to 24 Using the Cut command I can create the segments but I have not found a combine type of command to merger the two night segments. No luck with if/else either. Any help would be greatly appreciated Thank you Will -- View this message in context: http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019922.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grouping question
try this: x [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 y - cut(x, breaks=c(-Inf,6,18, Inf), labels=c('a','b','c')) levels(y) - c('night','day','night') y [1] night night night night night night night day day day day day day day day day day day [19] day night night night night night night Levels: night day On Fri, Oct 29, 2010 at 8:56 PM, will phillips will.phill...@q.com wrote: Hello I have what is probably a very simple grouping question however, given my limited exposure to R, I have not found a solution yet despite my research efforts and wild attempts at what I thought might produce some sort of result. I have a very simple list of integers that range between 1 and 24. These correspond to hours of the day. I am trying to create a grouping of Day and Night with Day = 6 to 17.99 Night = 1 to 5.59 and 18 to 24 Using the Cut command I can create the segments but I have not found a combine type of command to merger the two night segments. No luck with if/else either. Any help would be greatly appreciated Thank you Will -- View this message in context: http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019922.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grouping question
Hi Will, One way would be: x [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 factor(ifelse(x6 x18, 'day', 'night')) [1] night night night night night night night day day day day day day day day [16] day day day night night night night night night night Levels: day night HTH, Jorge On Fri, Oct 29, 2010 at 8:56 PM, will phillips wrote: Hello I have what is probably a very simple grouping question however, given my limited exposure to R, I have not found a solution yet despite my research efforts and wild attempts at what I thought might produce some sort of result. I have a very simple list of integers that range between 1 and 24. These correspond to hours of the day. I am trying to create a grouping of Day and Night with Day = 6 to 17.99 Night = 1 to 5.59 and 18 to 24 Using the Cut command I can create the segments but I have not found a combine type of command to merger the two night segments. No luck with if/else either. Any help would be greatly appreciated Thank you Will -- View this message in context: http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019922.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grouping question
Hello Jim Wow. I tried cut but i see you have an interim step with labels a,b,c but levels night and day. i was really close to this. i have labels night,day,night and it wouldn't let me duplicate labels. I am very greatful for your input Will -- View this message in context: http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019950.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grouping question
Hello Jorge, Thank you for the reply. I tried a few different things with if/else but couldn't get them to go. I really appreciate your feedback. I learned something new from this Will -- View this message in context: http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019952.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.