[R] Subsetting for unwanted values

Joris Meys jorismeys at gmail.com
Fri Jun 4 02:11:06 CEST 2010


>  PcToAdd_<-Pc[!(Pc %in% Pc.X)]
> PcToAdd_
[1] "Res" "Os"  "Gov" "Rur"
>  PcToAdd_<-subset(Pc,!(Pc %in% Pc.X))
> PcToAdd_
[1] "Res" "Os"  "Gov" "Rur"
>


On Fri, Jun 4, 2010 at 1:52 AM, LCOG1 <jroll at lcog.org> wrote:
>
> Hi all,
>   I have toyed with this for too long today and in the past i used multiple
> lines of code to get at what i want.  Consider the following:
>
> All i need to do is subset Pc to the values that do not equal Pc.X.  The
> first attempt doesnt work because i have unequal lengths.  The second
> attempt doesnt give me an the right answer.
>
>
> Pc<-c("Res","Com","Ind","Os","Mix","Gov","Rur")
> Pc.X<-c("Com","Ind","Mix")
>  PcToAdd_<-Pc[Pc!=Pc.X]
> #Doesnt Work
> AND
>
>  PcToAdd_<-subset(Pc.X,Pc.X %in% Pc)
> #Works but doesnt get me what i want
>
> I am looking a return of PcToAdd_ <- "Res"  "Os" "Gov" "Rur"
>
> This has got to be a simple answer.  Thanks
> --
> View this message in context: http://r.789695.n4.nabble.com/Subsetting-for-unwanted-values-tp2242506p2242506.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.
>



-- 
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



More information about the R-help mailing list