Hello, there, My patterns are defined by variables, for example:z="h"v="x" I have a vector: a=c("th","mx","t") I would like to find elements in vector a that contain either "h", or "x" grep("h|x", a) apparently works. However, when I tried: grep(z|v,a), it did not work. Can anyone help how to handle such situation? Thanks. Ace On Wednesday, March 18, 2015 5:52 PM, Fix Ace <acefix at rocketmail.com> wrote: Thank you very much! I do need to learn more about R!! On Tuesday, March 17, 2015 9:26 PM, William Dunlap <wdunlap at tibco.com> wrote: Fix Ace wrote?? ?What is the default "n"? 512:? ?> length(density(rnorm(10^6))$x)? ?[1] 512? ?> args(density.default)? ?function (x, bw = "nrd0", adjust = 1, kernel = c("gaussian",?? ? ? ?"epanechnikov", "rectangular", "triangular", "biweight",?? ? ? ?"cosine", "optcosine"), weights = NULL, window = kernel,?? ? ? ?width, give.Rkern = FALSE, n = 512, from, to, cut = 3, na.rm = FALSE,?? ? ? ?...)? ?NULL? ?> ?density # or ?density.default, should also tell you about its meaning Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 17, 2015 at 7:02 PM, Fix Ace <acefix at rocketmail.com> wrote: Thank you for the email. What is the default "n"? Thanks! On Tuesday, March 17, 2015 4:06 PM, William Dunlap <wdunlap at tibco.com> wrote: Increasing the value of 'n' given to density will give an estimate at more points so it will look smoother.? Try n=2^18. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 17, 2015 at 12:06 PM, Fix Ace <acefix at rocketmail.com> wrote: ?I have a dataset with 6187 elements, ranged from 3 to 104028. When I tried to examine only small range of data, I found that the plot was not smooth (as shown below): plot(density(test$V2), xlim=c(0,1000)) ?Is there away to make it smoother? Thanks a lot!! ? ? ? ______________________________________________ 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]]
The | symbol has a completely different meaning in R syntax than it has in regular expression syntax. R hands of pattern strings to the regex library without looking inside the strings any more than it has to. Likewise, the regex library has no clue about R syntax. Your attempt failed to create a character string for grep to give to the regex library. To do that read ?paste. grep( paste( z, v, sep = "|" ), a ) On Thu, 22 Sep 2016, Fix Ace via R-help wrote:> Hello, there, > My patterns are defined by variables, for example:z="h"v="x" > I have a vector: > a=c("th","mx","t") > I would like to find elements in vector a that contain either "h", or "x" > grep("h|x", a) apparently works. However, when I tried: grep(z|v,a), it did not work. Can anyone help how to handle such situation? > Thanks. > Ace > > On Wednesday, March 18, 2015 5:52 PM, Fix Ace <acefix at rocketmail.com> wrote: > > > Thank you very much! > I do need to learn more about R!! > > > On Tuesday, March 17, 2015 9:26 PM, William Dunlap <wdunlap at tibco.com> wrote: > > > Fix Ace wrote?? ?What is the default "n"? > 512:? ?> length(density(rnorm(10^6))$x)? ?[1] 512? ?> args(density.default)? ?function (x, bw = "nrd0", adjust = 1, kernel = c("gaussian",?? ? ? ?"epanechnikov", "rectangular", "triangular", "biweight",?? ? ? ?"cosine", "optcosine"), weights = NULL, window = kernel,?? ? ? ?width, give.Rkern = FALSE, n = 512, from, to, cut = 3, na.rm = FALSE,?? ? ? ?...)? ?NULL? ?> ?density # or ?density.default, should also tell you about its meaning > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > On Tue, Mar 17, 2015 at 7:02 PM, Fix Ace <acefix at rocketmail.com> wrote: > > Thank you for the email. > What is the default "n"? > Thanks! > > > On Tuesday, March 17, 2015 4:06 PM, William Dunlap <wdunlap at tibco.com> wrote: > > > Increasing the value of 'n' given to density will give an estimate at more points so it will look smoother.? Try n=2^18. > Bill Dunlap > TIBCO Software > wdunlap tibco.com > On Tue, Mar 17, 2015 at 12:06 PM, Fix Ace <acefix at rocketmail.com> wrote: > > > > ?I have a dataset with 6187 elements, ranged from 3 to 104028. When I tried to examine only small range of data, I found that the plot was not smooth (as shown below): > plot(density(test$V2), xlim=c(0,1000)) > > > ?Is there away to make it smoother? > Thanks a lot!! > > ? > > > ? > > > > ? > ______________________________________________ > 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]] > > ______________________________________________ > 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.--------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k ---------------------------------------------------------------------------
"The | symbol has a completely different meaning in R syntax than it has in regular expression syntax." Well, actually it doesn't -- loosely speaking, they both mean "or" (ok -- interpreting concatenation as "or" is a bit of a stretch). Perhaps to clarify your statement (stop here if none is needed!): 1) z|v is an R expression that evaluates to the disjunction of the values of objects z and v, which should be logical (and will be coerced to logicals if needed and possible). That is, the result is logical, 2) paste(z,v, sep = "|") evaluates to a character string which is the concatenation of character string values of z and v with "|" in the middle. regex needs character strings to define its patterns. Clear? Cheers, Bert 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, Sep 23, 2016 at 9:34 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> The | symbol has a completely different meaning in R syntax than it has in > regular expression syntax. R hands of pattern strings to the regex library > without looking inside the strings any more than it has to. Likewise, the > regex library has no clue about R syntax. Your attempt failed to create a > character string for grep to give to the regex library. To do that read > ?paste. > > grep( paste( z, v, sep = "|" ), a ) > > > On Thu, 22 Sep 2016, Fix Ace via R-help wrote: > >> Hello, there, >> My patterns are defined by variables, for example:z="h"v="x" >> I have a vector: a=c("th","mx","t") >> I would like to find elements in vector a that contain either "h", or "x" >> grep("h|x", a) apparently works. However, when I tried: grep(z|v,a), it >> did not work. Can anyone help how to handle such situation? >> Thanks. >> Ace >> On Wednesday, March 18, 2015 5:52 PM, Fix Ace <acefix at rocketmail.com> >> wrote: >> >> >> Thank you very much! >> I do need to learn more about R!! >> >> On Tuesday, March 17, 2015 9:26 PM, William Dunlap <wdunlap at tibco.com> >> wrote: >> >> >> Fix Ace wrote What is the default "n"? >> 512: > length(density(rnorm(10^6))$x) [1] 512 > >> args(density.default) function (x, bw = "nrd0", adjust = 1, kernel >> c("gaussian", "epanechnikov", "rectangular", "triangular", >> "biweight", "cosine", "optcosine"), weights = NULL, window = kernel, >> width, give.Rkern = FALSE, n = 512, from, to, cut = 3, na.rm = FALSE, >> ...) NULL > ?density # or ?density.default, should also tell you about >> its meaning >> >> Bill Dunlap >> TIBCO Software >> wdunlap tibco.com >> On Tue, Mar 17, 2015 at 7:02 PM, Fix Ace <acefix at rocketmail.com> wrote: >> >> Thank you for the email. >> What is the default "n"? >> Thanks! >> >> On Tuesday, March 17, 2015 4:06 PM, William Dunlap <wdunlap at tibco.com> >> wrote: >> >> >> Increasing the value of 'n' given to density will give an estimate at more >> points so it will look smoother. Try n=2^18. >> Bill Dunlap >> TIBCO Software >> wdunlap tibco.com >> On Tue, Mar 17, 2015 at 12:06 PM, Fix Ace <acefix at rocketmail.com> wrote: >> >> >> >> I have a dataset with 6187 elements, ranged from 3 to 104028. When I >> tried to examine only small range of data, I found that the plot was not >> smooth (as shown below): >> plot(density(test$V2), xlim=c(0,1000)) >> >> >> Is there away to make it smoother? >> Thanks a lot!! >> >> >> >> >> >> >> >> >> ______________________________________________ >> 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]] >> >> ______________________________________________ >> 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. > > > --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go Live... > DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --------------------------------------------------------------------------- > > ______________________________________________ > 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.
Fix Ace
2016-Nov-21 20:05 UTC
[R] how to use vector of values to change row order of a heatmap
Hello, there, R document for heatmap says that Rowv could be a vector of values to specify the row order. However, I couldn't figure out how to apply it. A simple example here:> b=as.data.frame(matrix(c(3,4,5,8,9,10,13,14,15,27,19,20),3,4))> b? V1 V2 V3 V4 1? 3? 8 13 27 2? 4? 9 14 19 3? 5 10 15 20> row.names(b)=c("a","b","c") > b? V1 V2 V3 V4 a? 3? 8 13 27 b? 4? 9 14 19 c? 5 10 15 20> heatmap(as.matrix(b))What I got: Now I would like to put row "a" to the top row, how do I do that?I tried provide a vector of values (all the possible combination of 1,2,3) to Rowv,? "a" is always stay at the bottom Any input would be very helpful! Ace -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 10962 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20161121/64a973c3/attachment.png>