Hi all For the data below, I would like to return a logical value indicating differences in the data. #Create data Data..<-data.frame(a=rep(1,10),b=c(rep(1,9),2),c=c(rep(1,8),2,2)) a b c 1 1 1 1 2 1 1 1 3 1 1 1 4 1 1 1 5 1 1 1 6 1 1 1 7 1 1 1 8 1 1 1 9 1 1 2 10 1 2 2 So what I want is to return logical value telling me if all the values are the same. So the result would be a b c DidChange 1 1 1 1 FALSE 2 1 1 1 FALSE 3 1 1 1 FALSE 4 1 1 1 FALSE 5 1 1 1 FALSE 6 1 1 1 FALSE 7 1 1 1 FALSE 8 1 1 1 FALSE 9 1 1 2 TRUE 10 1 2 2 TRUE I bet apply could handle this elegantly but that family of functions is still not 100% intuitive to me. Thoughts. Thanks everyone Cheers, Josh -- View this message in context: http://r.789695.n4.nabble.com/I-bet-apply-has-a-solution-tp4362294p4362294.html Sent from the R help mailing list archive at Nabble.com.
I bet apply has a solution
8 messages · LCOG1, Justin Haynes, Ista Zahn +5 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120206/ad60f580/attachment.pl>
Hi Josh, How about apply(Data, 1, function(row) sd(row) == 0) ? Best, Ista
On Mon, Feb 6, 2012 at 1:34 PM, LCOG1 <jroll at lcog.org> wrote:
Hi all For the data below, I would like to return a logical value indicating differences in the data. #Create data Data..<-data.frame(a=rep(1,10),b=c(rep(1,9),2),c=c(rep(1,8),2,2)) ? a b c 1 ?1 1 1 2 ?1 1 1 3 ?1 1 1 4 ?1 1 1 5 ?1 1 1 6 ?1 1 1 7 ?1 1 1 8 ?1 1 1 9 ?1 1 2 10 1 2 2 So what I want is to return logical value telling me if all the values are the same. ?So the result would be a b c DidChange 1 ?1 1 1 ? ? FALSE 2 ?1 1 1 ? ? FALSE 3 ?1 1 1 ? ? FALSE 4 ?1 1 1 ? ? FALSE 5 ?1 1 1 ? ? FALSE 6 ?1 1 1 ? ? FALSE 7 ?1 1 1 ? ? FALSE 8 ?1 1 1 ? ? FALSE 9 ?1 1 2 ? ? ?TRUE 10 1 2 2 ? ? ?TRUE I bet apply could handle this elegantly but that family of functions is still not 100% intuitive to me. ?Thoughts. ?Thanks everyone Cheers, ?Josh -- View this message in context: http://r.789695.n4.nabble.com/I-bet-apply-has-a-solution-tp4362294p4362294.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at 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.
Ah. That's the one. Thank you. -----Original Message----- From: Ista Zahn [mailto:istazahn at gmail.com] Sent: Monday, February 06, 2012 11:12 AM To: ROLL Josh F Cc: r-help at r-project.org Subject: Re: [R] I bet apply has a solution Hi Josh, How about apply(Data, 1, function(row) sd(row) == 0) ? Best, Ista
On Mon, Feb 6, 2012 at 1:34 PM, LCOG1 <jroll at lcog.org> wrote:
Hi all For the data below, I would like to return a logical value indicating differences in the data. #Create data Data..<-data.frame(a=rep(1,10),b=c(rep(1,9),2),c=c(rep(1,8),2,2)) ? a b c 1 ?1 1 1 2 ?1 1 1 3 ?1 1 1 4 ?1 1 1 5 ?1 1 1 6 ?1 1 1 7 ?1 1 1 8 ?1 1 1 9 ?1 1 2 10 1 2 2 So what I want is to return logical value telling me if all the values are the same. ?So the result would be a b c DidChange 1 ?1 1 1 ? ? FALSE 2 ?1 1 1 ? ? FALSE 3 ?1 1 1 ? ? FALSE 4 ?1 1 1 ? ? FALSE 5 ?1 1 1 ? ? FALSE 6 ?1 1 1 ? ? FALSE 7 ?1 1 1 ? ? FALSE 8 ?1 1 1 ? ? FALSE 9 ?1 1 2 ? ? ?TRUE 10 1 2 2 ? ? ?TRUE I bet apply could handle this elegantly but that family of functions is still not 100% intuitive to me. ?Thoughts. ?Thanks everyone Cheers, ?Josh -- View this message in context: http://r.789695.n4.nabble.com/I-bet-apply-has-a-solution-tp4362294p436 2294.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at 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.
duplicated(Data..)
On Mon, Feb 6, 2012 at 11:34 AM, LCOG1 <jroll at lcog.org> wrote:
Hi all For the data below, I would like to return a logical value indicating differences in the data. #Create data Data..<-data.frame(a=rep(1,10),b=c(rep(1,9),2),c=c(rep(1,8),2,2)) ? a b c 1 ?1 1 1 2 ?1 1 1 3 ?1 1 1 4 ?1 1 1 5 ?1 1 1 6 ?1 1 1 7 ?1 1 1 8 ?1 1 1 9 ?1 1 2 10 1 2 2 So what I want is to return logical value telling me if all the values are the same. ?So the result would be a b c DidChange 1 ?1 1 1 ? ? FALSE 2 ?1 1 1 ? ? FALSE 3 ?1 1 1 ? ? FALSE 4 ?1 1 1 ? ? FALSE 5 ?1 1 1 ? ? FALSE 6 ?1 1 1 ? ? FALSE 7 ?1 1 1 ? ? FALSE 8 ?1 1 1 ? ? FALSE 9 ?1 1 2 ? ? ?TRUE 10 1 2 2 ? ? ?TRUE I bet apply could handle this elegantly but that family of functions is still not 100% intuitive to me. ?Thoughts. ?Thanks everyone Cheers, ?Josh -- View this message in context: http://r.789695.n4.nabble.com/I-bet-apply-has-a-solution-tp4362294p4362294.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120206/046defb6/attachment.pl>
No. This does not do anything like what the OP wanted.
Did you ***try*** it, for crying out loud?
cheers,
Rolf Turner
On 07/02/12 08:29, ilai wrote:
duplicated(Data..) On Mon, Feb 6, 2012 at 11:34 AM, LCOG1<jroll at lcog.org> wrote:
Hi all For the data below, I would like to return a logical value indicating differences in the data. #Create data Data..<-data.frame(a=rep(1,10),b=c(rep(1,9),2),c=c(rep(1,8),2,2)) a b c 1 1 1 1 2 1 1 1 3 1 1 1 4 1 1 1 5 1 1 1 6 1 1 1 7 1 1 1 8 1 1 1 9 1 1 2 10 1 2 2 So what I want is to return logical value telling me if all the values are the same. So the result would be a b c DidChange 1 1 1 1 FALSE 2 1 1 1 FALSE 3 1 1 1 FALSE 4 1 1 1 FALSE 5 1 1 1 FALSE 6 1 1 1 FALSE 7 1 1 1 FALSE 8 1 1 1 FALSE 9 1 1 2 TRUE 10 1 2 2 TRUE I bet apply could handle this elegantly but that family of functions is still not 100% intuitive to me. Thoughts. Thanks everyone Cheers, Josh
Hi as.logical(rowSums(apply(Data, 2, diff)>0)) here is another option. Regards Petr
Hi all For the data below, I would like to return a logical value indicating differences in the data. #Create data Data..<-data.frame(a=rep(1,10),b=c(rep(1,9),2),c=c(rep(1,8),2,2)) a b c 1 1 1 1 2 1 1 1 3 1 1 1 4 1 1 1 5 1 1 1 6 1 1 1 7 1 1 1 8 1 1 1 9 1 1 2 10 1 2 2 So what I want is to return logical value telling me if all the values
are
the same. So the result would be a b c DidChange 1 1 1 1 FALSE 2 1 1 1 FALSE 3 1 1 1 FALSE 4 1 1 1 FALSE 5 1 1 1 FALSE 6 1 1 1 FALSE 7 1 1 1 FALSE 8 1 1 1 FALSE 9 1 1 2 TRUE 10 1 2 2 TRUE I bet apply could handle this elegantly but that family of functions is still not 100% intuitive to me. Thoughts. Thanks everyone Cheers, Josh -- View this message in context: http://r.789695.n4.nabble.com/I-bet-apply- has-a-solution-tp4362294p4362294.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at 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.