Yes,

First, select only columns C1 to C6, then look for values greater than 0,
after use this to select the columns in original subset.

On Sun, Jul 5, 2009 at 4:48 PM, Mark Knecht <markkne...@gmail.com> wrote:

> On Sun, Jul 5, 2009 at 12:30 PM, Henrique Dallazuanna<www...@gmail.com>
> wrote:
> > Try this:
> >
> > subset(test[3,], select=C1:C6)[,subset(test[3,], select = C1:C6) > 0]
> >
> > subset(test[6,], select=C1:C6)[,subset(test[6,], select = C1:C6) > 0]
> >
> >
>
> I must admit I like this one. Pleasing to look at. It seems
> approachable. Thanks!
>
> If I understand this the second subset gets evaluated first producing
> either TRUE or FALSE, and then the first subset gets evaluated but
> only for the entries that are TRUE? Is that the process?
>
> Thanks,
> Mark
>
> >
> > On Sun, Jul 5, 2009 at 1:19 PM, Mark Knecht <markkne...@gmail.com>
> wrote:
> >>
> >> On Sun, Jul 5, 2009 at 8:18 AM, David Winsemius<dwinsem...@comcast.net>
> >> wrote:
> >> >
> >> > On Jul 5, 2009, at 10:50 AM, Uwe Ligges wrote:
> >> >
> >> >>
> >> >>
> >> >> David Winsemius wrote:
> >> >>>
> >> >>> So if your values are calculated from other values then consider
> using
> >> >>> all.equal()
> >> >>> And repeated applications of the testing criteria process are
> >> >>> effective:
> >> >>> test[3,][which(names(test)=="C1"):(which(test[3,] == 0.0)-1)]
> >> >>>   C1   C2   C3
> >> >>> 3 0.52 0.66 0.51
> >> >>> (and a warning that does not seem accurate to me.)
> >> >>> In which(names(test) == "C1"):(which(test[3, ] == 0) - 1) :
> >> >>>  numerical expression has 3 elements: only the first used
> >> >>
> >> >>
> >> >> David,
> >> >>
> >> >> # which(test[3,] == 0.0)
> >> >> [1] 6 7 8
> >> >>
> >> >> and in a:b a and b must be length 1 vectors (scalars) otherwise just
> >> >> the
> >> >> first element (in this case 6) is used.
> >> >>
> >> >> That leads us to the conclusion that writing the line above is not
> >> >> really
> >> >> the cleanest way or you intended something different ....
> >> >
> >> > Thanks, Uwe. I see my confusion. I did want 6 to be used  and it looks
> >> > as
> >> > though I would not be getting in truouble this way, but a cleaner
> method
> >> > would be to access only the first element of which(test[3, ] == 0):
> >> >
> >> > test[3,][ which(names(test) == "C1") : (which(test[3,] == 0.0)[1]-1) ]
> >> >
> >> >>
> >> >> David
> >> >
> >> >>> Seems to me that all of the element were used. I cannot explain that
> >> >>> warning but am pretty sure it can be ignored.
> >> >>>
> >> >
> >> > David Winsemius, MD
> >> > Heritage Laboratories
> >> > West Hartford, CT
> >> >
> >> >
> >>
> >> OK - making lots more headway. Thanks for your help.
> >>
> >> QUESTION: How do I handle the case where I'm testing for 0 and don't
> >> find it? In this case I need to all of the row from C1:C6.
> >>
> >> test <- data.frame(A=1:10, B=100, C1=runif(10), C2=runif(10),
> >> C3=runif(10), C4=runif(10), C5=runif(10), C6=runif(10))
> >> test<-round(test,2)
> >>
> >> #Make array ragged
> >> test$C3[2]<-0;test$C4[2]<-0;test$C5[2]<-0;test$C6[2]<-0
> >> test$C4[3]<-0;test$C5[3]<-0;test$C6[3]<-0
> >> test$C6[7]<-0
> >> test$C4[8]<-0;test$C5[8]<-0;test$C6[8]<-0
> >>
> >> test
> >>
> >> #C1 always the same so calculate it only once
> >> StartCol <- which(names(test)=="C1")
> >>
> >> #Print row 3 explicitly
> >> test[3,][StartCol :(which(test[3,] == 0.0)[1]-1)]
> >>
> >> #Row 6 fails because 0 is not found
> >> test[6,][StartCol :(which(test[6,] == 0.0)[1]-1)]
> >>
> >> EndCol <- which(test[6,] == 0.0)[1]-1
> >> EndCol
> >>
> >> Thanks,
> >> Mark
> >>
> >> ______________________________________________
> >> 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.
> >
> >
> >
> > --
> > Henrique Dallazuanna
> > Curitiba-Paraná-Brasil
> > 25° 25' 40" S 49° 16' 22" O
> >
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[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.

Reply via email to