The following "subset command works. I was hoping the second would as well but it does not. My definition of exclude is rejected. Help please? Thanks. > mydata<-subset(mydata, +??????????????? prim>-9???? & highsch>-9? & tert>-9 & +??????????????? govt>-9???? & nongovt>-9? & +??????????????? married>-9? & urban>-9??? & +??????????????? smhmyes>-9? & smhmno>-9?? & smhmnoru>-9 & +??????????????? workouts>-9 & seconhan>-9 & reliyes>-9) > exclude<-????? prim==-9???? | highsch==-9? | tert==-9 | +??????????????? govt==-9???? | nongovt==-9? | +??????????????? married==-9? | urban==-9??? | +??????????????? smhmyes==-9? | smhmno==-9?? | smhmnoru==-9 | +??????????????? workouts==-9 | seconhan==-9 | reliyes==-9 Error: object 'prim' not found > mydata<-subset(mydata,-exclude) Error in eval(e, x, parent.frame()) : object 'exclude' not found >
I don't see a "second one". Looks like you forgot the subset function call? On October 15, 2021 6:23:56 PM PDT, Steven Yen <styen at ntu.edu.tw> wrote:>The following "subset command works. I was hoping the second would as >well but it does not. > >My definition of exclude is rejected. > >Help please? Thanks. > > > mydata<-subset(mydata, >+??????????????? prim>-9???? & highsch>-9? & tert>-9 & >+??????????????? govt>-9???? & nongovt>-9? & >+??????????????? married>-9? & urban>-9??? & >+??????????????? smhmyes>-9? & smhmno>-9?? & smhmnoru>-9 & >+??????????????? workouts>-9 & seconhan>-9 & reliyes>-9) > > > exclude<-????? prim==-9???? | highsch==-9? | tert==-9 | >+??????????????? govt==-9???? | nongovt==-9? | >+??????????????? married==-9? | urban==-9??? | >+??????????????? smhmyes==-9? | smhmno==-9?? | smhmnoru==-9 | >+??????????????? workouts==-9 | seconhan==-9 | reliyes==-9 >Error: object 'prim' not found > > mydata<-subset(mydata,-exclude) >Error in eval(e, x, parent.frame()) : object 'exclude' not found > > > >______________________________________________ >R-help at 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.-- Sent from my phone. Please excuse my brevity.
the second command doesn't tell R that the variables are in the data.frame mydata. you will need exclude <- with(mydata, prim==-9 | etc) also you will need logical negation ! not arithmetic negation -> -c(TRUE,FALSE)[1] -1 0> as.logical(-c(TRUE,FALSE))[1] TRUE FALSE> !c(TRUE,FALSE)[1] FALSE TRUE> On Oct 15, 2021, at 21:23, Steven Yen <styen at ntu.edu.tw> wrote: > > The following "subset command works. I was hoping the second would as well but it does not. > > My definition of exclude is rejected. > > Help please? Thanks. > > > mydata<-subset(mydata, > + prim>-9 & highsch>-9 & tert>-9 & > + govt>-9 & nongovt>-9 & > + married>-9 & urban>-9 & > + smhmyes>-9 & smhmno>-9 & smhmnoru>-9 & > + workouts>-9 & seconhan>-9 & reliyes>-9) > > > exclude<- prim==-9 | highsch==-9 | tert==-9 | > + govt==-9 | nongovt==-9 | > + married==-9 | urban==-9 | > + smhmyes==-9 | smhmno==-9 | smhmnoru==-9 | > + workouts==-9 | seconhan==-9 | reliyes==-9 > Error: object 'prim' not found > > mydata<-subset(mydata,-exclude) > Error in eval(e, x, parent.frame()) : object 'exclude' not found > > > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=04%7C01%7Crmh%40temple.edu%7Ca1d470378fc24c832f7708d99043b804%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637699443365577347%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=DFLP8ZLggvu1NVs9ufyWUdT5hJNKd0v7UYwcHCXncVk%3D&reserved=0 > PLEASE do read the posting guide https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7Ca1d470378fc24c832f7708d99043b804%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637699443365577347%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=4g2tnLBCnnWezCp%2FZIYFRCxrIKa4VDD46WRQohT5Ftk%3D&reserved=0 > and provide commented, minimal, self-contained, reproducible code.
I assume that prim, etc. are columns of your data frame, mydata. Ergo, the error message "prim not found" as 'prim' etc. does not exist in the Global environment. exclude <- with(mydata, prim == -9, etc. ) should get what you want to evaluate your second subset statement if I have understood correctly, as it will look for those names within mydata. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Oct 15, 2021 at 6:24 PM Steven Yen <styen at ntu.edu.tw> wrote:> The following "subset command works. I was hoping the second would as > well but it does not. > > My definition of exclude is rejected. > > Help please? Thanks. > > > mydata<-subset(mydata, > + prim>-9 & highsch>-9 & tert>-9 & > + govt>-9 & nongovt>-9 & > + married>-9 & urban>-9 & > + smhmyes>-9 & smhmno>-9 & smhmnoru>-9 & > + workouts>-9 & seconhan>-9 & reliyes>-9) > > > exclude<- prim==-9 | highsch==-9 | tert==-9 | > + govt==-9 | nongovt==-9 | > + married==-9 | urban==-9 | > + smhmyes==-9 | smhmno==-9 | smhmnoru==-9 | > + workouts==-9 | seconhan==-9 | reliyes==-9 > Error: object 'prim' not found > > mydata<-subset(mydata,-exclude) > Error in eval(e, x, parent.frame()) : object 'exclude' not found > > > > ______________________________________________ > R-help at 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. >[[alternative HTML version deleted]]