Dear R People: I have the following:> ls(pattern="NY*")[1] "CRAN_df" "CRAN_df0" "CRAN_df1" "CRAN_mat" "CRAN_sp" [6] "CRAN_spdf1" "CRAN_spdf2" "CRAN_spdf4" "delauney_NY" "dist2_NY" [11] "dist3_NY" "Gabriel_NY" "NY8a_nb" "rel_neigh_NY" "scot_BNG" [16] "SOI_NY"> rm(pattern="NY*")Warning message: In rm(pattern = "NY*") : object 'NY*' not found>How do I remove all of NY* items, please? I suspect it might be an sapply issue thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com
On Jan 16, 2011, at 4:08 PM, Erin Hodgess wrote:> Dear R People: > > I have the following: > >> ls(pattern="NY*") > [1] "CRAN_df" "CRAN_df0" "CRAN_df1" "CRAN_mat" > "CRAN_sp" > [6] "CRAN_spdf1" "CRAN_spdf2" "CRAN_spdf4" "delauney_NY" > "dist2_NY" > [11] "dist3_NY" "Gabriel_NY" "NY8a_nb" "rel_neigh_NY" > "scot_BNG" > [16] "SOI_NY" >> rm(pattern="NY*") > Warning message: > In rm(pattern = "NY*") : object 'NY*' not found >> > > How do I remove all of NY* items, please? I suspect it might be an > sapply issue > thanks,Perhaps: rm(list= ls()[grep("NY", ls()] ) If there is a pattern argument to rm (I haven't looked) then it's possible that it would have succeeded with pattern="NY", assuming you want any object name with "NY" someplace in it. The "*" looks wrong for grepping. ".+" would have looked more greppish, but its not really needed.> Erin > > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodgess at gmail.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.David Winsemius, MD West Hartford, CT
On Sun, Jan 16, 2011 at 1:08 PM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:> Dear R People: > > I have the following: > >> ls(pattern="NY*") > ?[1] "CRAN_df" ? ? ?"CRAN_df0" ? ? "CRAN_df1" ? ? "CRAN_mat" ? ? "CRAN_sp" > ?[6] "CRAN_spdf1" ? "CRAN_spdf2" ? "CRAN_spdf4" ? "delauney_NY" ?"dist2_NY" > [11] "dist3_NY" ? ? "Gabriel_NY" ? "NY8a_nb" ? ? ?"rel_neigh_NY" "scot_BNG" > [16] "SOI_NY" >> rm(pattern="NY*")there is no "pattern" argument in rm(), the only reason trying to use it did not fail is that it has the ... argument to allow many objects to be passed that you would like removed.> Warning message: > In rm(pattern = "NY*") : object 'NY*' not foundI do not believe '*' works in regular expressions as I suspect you are trying to use it. See ?regexp for details.>> > > How do I remove all of NY* items, please? ?I suspect it might be an sapply issueThere is a list argument to rm() that you can use in conjunction with ls(): rm(list = ls(pattern = "NY")) Cheers, Josh> thanks, > Erin > > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodgess at gmail.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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
How about ls(pattern="NY") #rm(list=ls(pattern="NY")) On Sunday 16 January 2011 22:08:16 Erin Hodgess wrote:> Dear R People: > > I have the following: > > > ls(pattern="NY*") > [1] "CRAN_df" "CRAN_df0" "CRAN_df1" "CRAN_mat" "CRAN_sp" > [6] "CRAN_spdf1" "CRAN_spdf2" "CRAN_spdf4" "delauney_NY" "dist2_NY" > [11] "dist3_NY" "Gabriel_NY" "NY8a_nb" "rel_neigh_NY" "scot_BNG" > [16] "SOI_NY" > > rm(pattern="NY*") > Warning message: > In rm(pattern = "NY*") : object 'NY*' not found > > > > How do I remove all of NY* items, please? I suspect it might be an sapply issue > thanks, > Erin > > >
or .... rm(list=ls(pattern="^NY")) if you only want those objects that begin with "NY" ... HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/a-remove-question-tp3220411p3220562.html Sent from the R help mailing list archive at Nabble.com.