Re: [R] Wild cards for dataframes
A terse but useful resource is to use R's Help docs: ?regex. It also gives the R regex syntax, which can of course differ from others, especially in regard to escapes. Do note that the rseek.org site is a better place to ask for such info than here. Or just searching on "regular expressions R". 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 22, 2021 at 2:21 AM Steven Yen wrote: > I like to be able to use a command with something similar to a "wild > card". Below, lines 4 works to delete all three dataframes, but line 5 > does not work. Any elegant way to accomplish this? My list of dataframes > can be long and so this would be convenient. > > data.1<-data.frame(x=1:3,y=4:6,z=7:9) > data.2<-data.1 > data.3<-data.1 > rm(data.1,data.2,data.3) > rm(data.*) > > __ > R-help@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]] __ R-help@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.
Re: [R] Wild cards for dataframes
Well, Wikipedia is probably the place where people who know some topic can check if people who wrote the article did it right :) You can try this short subchapter in R for Data Science (by Hadley Wickham) as a starting point: https://r4ds.had.co.nz/strings.html#matching-patterns-with-regular-expressions Best regards, Grzegorz pt., 22 paź 2021 o 15:14 Eric Berger napisał(a): > > You can check out Wikipedia for regular expressions: > > https://en.wikipedia.org/wiki/Regular_expression > > > > > On Fri, Oct 22, 2021 at 3:48 PM Steven Yen wrote: > > > Thanks, it works! > > > > What can I read to understand more about this part "\\..*$" of the > > pattern? And more such as ^ and $ that I know from experience? > > > > On 2021/10/22 下午 06:22, Rui Barradas wrote: > > > Hello, > > > > > > Use ls() with argument pattern. It accepts a regex and returns a > > > vector of objects names matching the pattern. > > > > > > > > > rm(list = ls(pattern = "data\\..*$")) > > > > > > > > > Hope this helps, > > > > > > Rui Barradas > > > > > > Às 10:20 de 22/10/21, Steven Yen escreveu: > > >> I like to be able to use a command with something similar to a "wild > > >> card". Below, lines 4 works to delete all three dataframes, but line > > >> 5 does not work. Any elegant way to accomplish this? My list of > > >> dataframes can be long and so this would be convenient. > > >> > > >> data.1<-data.frame(x=1:3,y=4:6,z=7:9) > > >> data.2<-data.1 > > >> data.3<-data.1 > > >> rm(data.1,data.2,data.3) > > >> rm(data.*) > > >> > > >> __ > > >> R-help@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. > > > > __ > > R-help@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]] > > __ > R-help@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. __ R-help@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.
Re: [R] Wild cards for dataframes
You can check out Wikipedia for regular expressions: https://en.wikipedia.org/wiki/Regular_expression On Fri, Oct 22, 2021 at 3:48 PM Steven Yen wrote: > Thanks, it works! > > What can I read to understand more about this part "\\..*$" of the > pattern? And more such as ^ and $ that I know from experience? > > On 2021/10/22 下午 06:22, Rui Barradas wrote: > > Hello, > > > > Use ls() with argument pattern. It accepts a regex and returns a > > vector of objects names matching the pattern. > > > > > > rm(list = ls(pattern = "data\\..*$")) > > > > > > Hope this helps, > > > > Rui Barradas > > > > Às 10:20 de 22/10/21, Steven Yen escreveu: > >> I like to be able to use a command with something similar to a "wild > >> card". Below, lines 4 works to delete all three dataframes, but line > >> 5 does not work. Any elegant way to accomplish this? My list of > >> dataframes can be long and so this would be convenient. > >> > >> data.1<-data.frame(x=1:3,y=4:6,z=7:9) > >> data.2<-data.1 > >> data.3<-data.1 > >> rm(data.1,data.2,data.3) > >> rm(data.*) > >> > >> __ > >> R-help@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. > > __ > R-help@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]] __ R-help@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.
Re: [R] Wild cards for dataframes
Thanks, it works! What can I read to understand more about this part "\\..*$" of the pattern? And more such as ^ and $ that I know from experience? On 2021/10/22 下午 06:22, Rui Barradas wrote: Hello, Use ls() with argument pattern. It accepts a regex and returns a vector of objects names matching the pattern. rm(list = ls(pattern = "data\\..*$")) Hope this helps, Rui Barradas Às 10:20 de 22/10/21, Steven Yen escreveu: I like to be able to use a command with something similar to a "wild card". Below, lines 4 works to delete all three dataframes, but line 5 does not work. Any elegant way to accomplish this? My list of dataframes can be long and so this would be convenient. data.1<-data.frame(x=1:3,y=4:6,z=7:9) data.2<-data.1 data.3<-data.1 rm(data.1,data.2,data.3) rm(data.*) __ R-help@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. __ R-help@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.
Re: [R] Wild cards for dataframes
Hello, Use ls() with argument pattern. It accepts a regex and returns a vector of objects names matching the pattern. rm(list = ls(pattern = "data\\..*$")) Hope this helps, Rui Barradas Às 10:20 de 22/10/21, Steven Yen escreveu: I like to be able to use a command with something similar to a "wild card". Below, lines 4 works to delete all three dataframes, but line 5 does not work. Any elegant way to accomplish this? My list of dataframes can be long and so this would be convenient. data.1<-data.frame(x=1:3,y=4:6,z=7:9) data.2<-data.1 data.3<-data.1 rm(data.1,data.2,data.3) rm(data.*) __ R-help@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. __ R-help@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.
[R] Wild cards for dataframes
I like to be able to use a command with something similar to a "wild card". Below, lines 4 works to delete all three dataframes, but line 5 does not work. Any elegant way to accomplish this? My list of dataframes can be long and so this would be convenient. data.1<-data.frame(x=1:3,y=4:6,z=7:9) data.2<-data.1 data.3<-data.1 rm(data.1,data.2,data.3) rm(data.*) __ R-help@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.