Re: [R] to raise in a loop more than 1
Dear Damien, > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of damien landais > Sent: Friday, June 26, 2009 11:16 AM > To: R-help@r-project.org > Subject: [R] to raise in a loop more than 1 > > I would raise x,y and z in a loop but I won't raise of 1. I > tried this but it doesn't work > > mydata=matrix(nrow=1500,ncol=3) > i=1 > for(x in 0:10){ > for(y in 0:20){ > for(z in 0:10){ > mydata[i,]=c(x,y,z) > i=i+1 > z=z+2} > y=y+4} > x=x+2} > > And I would have something like that > x y z > 0 0 0 > 0 0 2 > 0 0 4 > 0 0 6 > 0 0 8 > 0 0 10 > 0 4 0 > 0 4 2 > ... > I am not exactly sure what you want. If my guess is correct, this will reproduce the desired output: x <- seq(from=0, to=10, by=2) y <- seq(from=0, to=20, by=4) z <- seq(from=0, to=10, by=2) mydata2 <- expand.grid(x=as.factor(x), y=as.factor(y), z=as.factor(z)) mydata3 <- with(mydata2, mydata2[order(x,y,z),] ) head(mydata3, n=8) Hope this helps, Roland -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] [R} seasonal differencing
Hi, > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Joseph Magagnoli > Sent: Thursday, April 02, 2009 5:36 PM > To: r-help@r-project.org > Subject: [R] [R} seasonal differencing > > Hi all, > I was wondering how to construct a seasonal differenced time series > variable. > I used the following code to construct a 12 span seasonal difference > > seasonal<-diff(V2, lag=12, differences=1) > > is this correct? > > thank you in advance > joe > I think this is fine. Just playing around (see below), I obtained what I would expect. :-) > V2 <- rep(x=1:12, times=5) > seasonal <- diff(V2, lag=12, differences=1) > V2 [1] 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 1 [26] 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 1 2 [51] 3 4 5 6 7 8 9 10 11 12 > seasonal [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [39] 0 0 0 0 0 0 0 0 0 0 > Hope this helps, Roland -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] newton method
Hi, you might be also interested in a general overview as given here: http://cran.r-project.org/web/views/Optimization.html Hope this helps, Roland > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Kubovy > Sent: Monday, March 23, 2009 4:35 AM > To: Roslina Zakaria > Cc: r-help@r-project.org > Subject: Re: [R] newton method > > Take a look at the functionsnlm(), optim() in the stats package and > maxNR() in the maxLik package. > > On Mar 22, 2009, at 11:15 PM, Roslina Zakaria wrote: > > > Does R has a topic on newton's method? > > > _ > Professor Michael Kubovy > University of Virginia > Department of Psychology > Postal Address: > P.O.Box 400400, Charlottesville, VA 22904-4400 > Express Parcels Address: > Gilmer Hall, Room 102, McCormick Road, Charlottesville, VA 22903 > Office:B011; Phone: +1-434-982-4729 > Lab:B019; Phone: +1-434-982-4751 > WWW:http://www.people.virginia.edu/~mk9y/ > Skype name: polyurinsane > > > > > > [[alternative HTML version deleted]] > > __ > R-help@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. > -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] Finding Lambda in Poisson distribution
Hi, > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Saeed Ahmadi > Sent: Monday, March 02, 2009 3:16 PM > To: r-help@r-project.org > Subject: [R] Finding Lambda in Poisson distribution > > > Hi, > > I have a dataset. First of all, I know that my dataset shall > follow the > Poission distribution. Now I have two questions: > 1) How can I check that my data follow the Poisson distribution? > 2) How can I calculate Lambda of my data? is this maybe some homework? For 2): I simulated data and did some simple MLE. I don't know if this is the recommended way, but it worked fine for me. Best, Roland -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] Bold Face in Plot
Dear Prof. Ripley, > -Original Message- > From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk] > Sent: Monday, March 02, 2009 3:05 PM > To: Rau, Roland > Cc: r-help@r-project.org > Subject: Re: [R] Bold Face in Plot > > thestring <- "the-actual-string" > plot(0:1,0:1,type="n") > text(x=0.5, y=0.5, labels=thestring, font=2) > thank you very much. Using the font argument, I accomplished what I wanted to do. Thanks again, Roland -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
[R] Bold Face in Plot
Dear all, I am trying to plot some text in bold face which works fine: plot(0:1,0:1,type="n") text(x=0.5, y=0.5, labels=expression(bold("the-actual-string"))) Now when I try to do the following, the displayed text reads thestring: thestring <- "the-actual-string" plot(0:1,0:1,type="n") text(x=0.5, y=0.5, labels=expression(bold(thestring))) Can someone tell me what I am doing wrong? I assume it is rather simple but I am stuck somehow. Thanks in advance, Roland P.S. I tried it using ("ancient") R 2.7.0 on Windows32 and version 2.8.1 on GNU/Linux (Ubuntu 8.10). -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] New York Times - R - article a fraud?
Hi, it seems to me that this article in the NYT started many discussions. Maybe I missed it but are there some responses to the article by Ihaka & Gentleman? Or maybe by John Chambers as the central person for the development of S (hope I am not mistaken here)? I'd be more interested in their opinions than another "outrage!" posting. Thanks, Roland > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of eugene dalt > Sent: Tuesday, February 03, 2009 1:49 AM > To: r-h...@stat.math.ethz.ch > Subject: [R] New York Times - R - article a fraud? > > I worked on some ad data before and I found NYT article very > biaised and not far from a fraud... Anyone knows if they got > money from a - company - to play 'R'? > > Check out the title: R U Ready for R? Seems to me this > title was stolen from XLSolutions > www.xlsolutions-corp.com and they never mentioned > XLSolutions in the article! > > They mentioned commercial Rnever mentioned R-PLUS > (www.experience-rplus.com), nor RSTAT > (http://random-technologies-llc.com). > > I attended Trevor's class and his comment on the article is alarming: > > -- > - > As a long time user of S, Splus and now R, I loved the article on R > until I read the paragraph on how it all started. > > I quote: > "According to them, the notion of devising something like R sprang up > during a hallway conversation. They both wanted technology better > suited for their statistics students, who needed to analyze data and > produce graphical models of the information. Most comparable software > had been designed by computer scientists and proved hard to use." > > This is grossly ungenerous to the original inventors of the > wonderful S > language underlying the R system. > -- > - > > I think R community should report this fraudulent article to > the NYT ed board. It's fraud, not journalism and someone has > to say it! > > 1- They got money for itfine it's business as usual > (unless someone knows someone and took some bribes). Yes... > One company seems to appear many many times in the article... > 2- It's a 'free' article, then it's rubish as usual. > > > > > > __ > R-help@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. > -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] Plot dagger symbol in R
Dear all, thank you very much. Yes, indeed, I should have included the sessionInfo(). Both examples (unicode and standard encoding) work fine; however, I prefer the suggestion by Prof. Ripley since it allows me to do things like: plot(1, main=expression(e^"\206")) This fails, however, with: plot(1, main=expression(e^"\u2020")) Thank you once again, Roland > sessionInfo() R version 2.7.0 (2008-04-22) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base > > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Prof Brian Ripley > Sent: Thursday, January 29, 2009 1:35 PM > To: Mark Difford > Cc: r-help@r-project.org > Subject: Re: [R] Plot dagger symbol in R > > On Thu, 29 Jan 2009, Mark Difford wrote: > > > > > Hi Roland, > > > >>> But this is obviously not a dagger and it seems the Adobe > Symbol font > >>> does not have a dagger. > > > > True, but ... Yoda was here. > > > > plot(0:1,0:1, type="n") > > text(x=0.5, y=0.5, labels=expression("\u2020")) > > text(x=0.4, y=0.6, labels=expression("\u2021")) > > > > ?plotmath, sub "Other symbols" ... "Any Unicode character > can be" > > > > Regards, Mark. > > > > PS: Works under Windows Vista, but ... > > That would be expected to work > > (in a UTF-8 locale || on Windows) > && on a device with Unicode support > && in a font that has the glyph. > > (it works on Windows because we fake much of a UTF-8 locale there). > > There is an alternative: dagger _is_ in the standard Adobe character > set, so this will work as something \206 (untested) in 8-bit Windows > character sets on windows(), postscript(), pdf() ... devices > > As ever, the information asked for in the posting guide helps us give > a better answer. > > > > > > > Rau, Roland wrote: > >> > >> Dear all, > >> > >> I would like to plot the dagger symbol in R (like LaTeX's \dagger). > >> However, I was unable to do so. > >> > >> First, I thought maybe dagger actually exists just like the degree > >> symbol: > >> > >> plot(0:1,0:1, type="n") > >> text(x=0.5, y=0.5, labels=expression(degree)) > >> > >> plot(0:1,0:1, type="n") > >> text(x=0.5, y=0.5, labels=expression(dagger)) > >> > >> However, this was not very successful. New hope emerged that I will > >> succeed when I read the help page (as so often) for ?plotmath. > >> There I discovered the 'symbol' thing and read that the > Adobe Symbol > >> font encodings are used. The closest thing I could fine, > though, was: > >> > >> plot(0:1,0:1, type="n") > >> text(x=0.5, y=0.5, labels=expression(symbol("\247"))) > >> > >> But this is obviously not a dagger and it seems the Adobe > Symbol font > >> does not have a dagger. > > But the Adobe Standard encoding does. > > >> We also know this :-D > >> > >> library(fortunes) > >> fortune("Yoda") > >> > >> So maybe someone can give me some advice? > >> > >> Thanks in advance, > >> Roland > > -- > Brian D. Ripley, rip...@stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UKFax: +44 1865 272595 > > __ > R-help@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. > -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
[R] Plot dagger symbol in R
Dear all, I would like to plot the dagger symbol in R (like LaTeX's \dagger). However, I was unable to do so. First, I thought maybe dagger actually exists just like the degree symbol: plot(0:1,0:1, type="n") text(x=0.5, y=0.5, labels=expression(degree)) plot(0:1,0:1, type="n") text(x=0.5, y=0.5, labels=expression(dagger)) However, this was not very successful. New hope emerged that I will succeed when I read the help page (as so often) for ?plotmath. There I discovered the 'symbol' thing and read that the Adobe Symbol font encodings are used. The closest thing I could fine, though, was: plot(0:1,0:1, type="n") text(x=0.5, y=0.5, labels=expression(symbol("\247"))) But this is obviously not a dagger and it seems the Adobe Symbol font does not have a dagger. We also know this :-D library(fortunes) fortune("Yoda") So maybe someone can give me some advice? Thanks in advance, Roland -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] Sweave encoding problem
Hi Gerrit, > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Gerrit Voigt > Sent: Monday, January 19, 2009 4:48 PM > To: r-help@r-project.org > Subject: [R] Sweave encoding problem > > Hello, > Sweave seems to have trouble processing german letters in R. > For example, my noweb R-input looks like this. > <<>>= > Oberflächenfehler = c(4, 11, 6, 2, 7, 9) > @ > If I send it through Sweave, I get the following error message. > > error: chunk 1 > Error in parse(text = chunk) : unexpected input in "Oberflä" > extra: Warning message: > In readLines(f[1]) : >underfull last line in "C:\" > > (my R is in german, so I needed to translate the error > message myself.) > > I got the impression, that this is an encoding issue of > Sweave, since > the input typed into R directly works just fine. The encoding > I use in > my noweb document is utf8. I don't think it has something to do with German letters. I saved the following text in a file 'sweavy.Snw': \documentclass{article} \begin{document} Hello World! <<>>= 1+1 @ <<>>= Oberflächenfehler = c(4, 11, 6, 2, 7, 9) @ \end{document} This is what happened in R: > library(utils) > Sweave("sweavy.Snw") Writing to file sweavy.tex Processing code chunks ... 1 : echo term verbatim 2 : echo term verbatim You can now run LaTeX on 'sweavy.tex' > > sessionInfo() R version 2.7.0 (2008-04-22) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base And also the dvi looked fine after processing "latex sweavy.tex" To make things sure, I did in my editor (GNU Emacs 22.1.50.1) C-x RET f utf-8 to change set-buffer-file-coding-system to utf-8. Still works fine. Maybe this helps you further to track down the reason for the problem?!? Best, Roland -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] regex -> negate a word
Thanks! (I have to admit, though, that I expected something simple) Thanks, Roland -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Sun 1/18/2009 8:54 PM To: Rau, Roland Cc: r-help@r-project.org Subject: Re: [R] regex -> negate a word Try this: grep("^([^a]|a[^b]|ab[^c])*.{0,2}$", x, perl = TRUE) On Sun, Jan 18, 2009 at 2:37 PM, Rau, Roland wrote: > Thank you very much to all of you for your fast and excellent help. > Since the "-grep(...)" solution seems to be favored by most of the answers, > I just wonder if there is really no regular expression which does the job?!? > > Thanks again, > Roland > > > > -Original Message- > From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] > Sent: Sun 1/18/2009 8:28 PM > To: Rau, Roland > Cc: r-help@r-project.org > Subject: Re: [R] regex -> negate a word > > Try this: > > # indexes > setdiff(seq_along(x), grep("abc", x)) > > # values > setdiff(x, grep("abc", x, value = TRUE)) > > Another possibility is: > > z <- "abc" > x0 <- c(x, z) # to handle no match case > x0[- grep(z, x0)] # values > > > > > On Sun, Jan 18, 2009 at 1:35 PM, Rau, Roland wrote: >> Dear all, >> >> let's assume I have a vector of character strings: >> >> x <- c("abcdef", "defabc", "qwerty") >> >> What I would like to find is the following: all elements where the word >> 'abc' does not appear (i.e. 3 in this case of 'x'). >> >> Since I am not really experienced with regular expressions, I started >> slowly and thought I find all word were 'abc' actually does appear: >> >>> grep(pattern="abc", x=x) >> [1] 1 2 >> >> So far, so good. Now I read that ^ is the negation operator. But it can >> also denote the beginning of a string as in: >> >>> grep(pattern="^abc", x=x) >> [1] 1 >> >> Of course, we need to put it inside square brackets to negate the >> expression [1] >>> grep(pattern="[^abc]", x=x) >> [1] 1 2 3 >> >> But this is not what I want either. >> >> I'd appreciate any help. I assume this is rather easy and >> straightforward. >> >> Thanks, >> Roland >> >> >> [1] http://www.zytrax.com/tech/web/regex.htm: The ^ (circumflex or >> caret) inside square brackets negates the expression >> >> -- >> This mail has been sent through the MPI for Demographic Research. Should >> you receive a mail that is apparently from a MPI user without this text >> displayed, then the address has most likely been faked. If you are uncertain >> about the validity of this message, please check the mail header or ask your >> system administrator for assistance. >> >> __ >> R-help@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. >> > > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Formatting the axis of plot() to shown our own values.
Hi -Original Message- From: r-help-boun...@r-project.org on behalf of saurabh_koparkar Sent: Sun 1/18/2009 5:12 PM To: r-help@r-project.org Subject: [R] Formatting the axis of plot() to shown our own values. Part 1: I want to plot the CO2 concentration vs. year, but extending the x-axis using the xlim parameter to include the year 2006 (x axis range of values are from -41210 to 0), and adjusting the ylim parameter to go up to 400 when the range of y axis values are from 150 to 300. How do I do this? Using axis function? I am confused about the syntax here. Try this: data(co2) plot(co2, xlim=c(1958,2007), ylim=c(300,400), xlab="Time", ylab=expression(CO[2]), col="blue", axes=FALSE) axis(side=1, at=seq(1960, 2000, by=10), pos=300) axis(side=2, at=c(300,333,350,400), pos=1958) Part 2: I also want to use the points() function to add the data points from years 1958-2006 on X axis to the above plot, but in a different color. Not sure what you want exactly, but I hope this is what you want: data(co2) plot(co2, xlim=c(1958,2007), ylim=c(300,400), xlab="Time", ylab=expression(CO[2]), col="blue", axes=FALSE) axis(side=1, at=seq(1960, 2000, by=10), pos=300) axis(side=2, at=c(300,333,350,400), pos=1958) points(co2, col="red") Hope this helps, Roland -- This mail has been sent through the MPI for Demographic ...{{dropped:10}} __ R-help@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.
Re: [R] regex -> negate a word
Thank you very much to all of you for your fast and excellent help. Since the "-grep(...)" solution seems to be favored by most of the answers, I just wonder if there is really no regular expression which does the job?!? Thanks again, Roland -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Sun 1/18/2009 8:28 PM To: Rau, Roland Cc: r-help@r-project.org Subject: Re: [R] regex -> negate a word Try this: # indexes setdiff(seq_along(x), grep("abc", x)) # values setdiff(x, grep("abc", x, value = TRUE)) Another possibility is: z <- "abc" x0 <- c(x, z) # to handle no match case x0[- grep(z, x0)] # values On Sun, Jan 18, 2009 at 1:35 PM, Rau, Roland wrote: > Dear all, > > let's assume I have a vector of character strings: > > x <- c("abcdef", "defabc", "qwerty") > > What I would like to find is the following: all elements where the word > 'abc' does not appear (i.e. 3 in this case of 'x'). > > Since I am not really experienced with regular expressions, I started > slowly and thought I find all word were 'abc' actually does appear: > >> grep(pattern="abc", x=x) > [1] 1 2 > > So far, so good. Now I read that ^ is the negation operator. But it can > also denote the beginning of a string as in: > >> grep(pattern="^abc", x=x) > [1] 1 > > Of course, we need to put it inside square brackets to negate the > expression [1] >> grep(pattern="[^abc]", x=x) > [1] 1 2 3 > > But this is not what I want either. > > I'd appreciate any help. I assume this is rather easy and > straightforward. > > Thanks, > Roland > > > [1] http://www.zytrax.com/tech/web/regex.htm: The ^ (circumflex or > caret) inside square brackets negates the expression > > -- > This mail has been sent through the MPI for Demographic Research. Should you > receive a mail that is apparently from a MPI user without this text > displayed, then the address has most likely been faked. If you are uncertain > about the validity of this message, please check the mail header or ask your > system administrator for assistance. > > __ > R-help@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. > [[alternative HTML version deleted]] __ R-help@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.
[R] regex -> negate a word
Dear all, let's assume I have a vector of character strings: x <- c("abcdef", "defabc", "qwerty") What I would like to find is the following: all elements where the word 'abc' does not appear (i.e. 3 in this case of 'x'). Since I am not really experienced with regular expressions, I started slowly and thought I find all word were 'abc' actually does appear: > grep(pattern="abc", x=x) [1] 1 2 So far, so good. Now I read that ^ is the negation operator. But it can also denote the beginning of a string as in: > grep(pattern="^abc", x=x) [1] 1 Of course, we need to put it inside square brackets to negate the expression [1] > grep(pattern="[^abc]", x=x) [1] 1 2 3 But this is not what I want either. I'd appreciate any help. I assume this is rather easy and straightforward. Thanks, Roland [1] http://www.zytrax.com/tech/web/regex.htm: The ^ (circumflex or caret) inside square brackets negates the expression -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] Re ad a text file from a directory in which an R script finds itself
Hi, > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of ppaarrkk > Sent: Tuesday, January 13, 2009 12:53 PM > To: r-help@r-project.org > Subject: [R] Re ad a text file from a directory in which an R > script finds itself > > > Is it possible for an R script to read a text file, say, from > the directory > in which the script is located ? > > I don't think I can use setwd(), because I can't specify the > directory. maybe you have to be a bit more specific? What do you mean by "I can't specify..."? - you don't know how to specify the directory -> setwd("c:/mydirectory/anotherdirectoy/") mydata <- read.table(.) - you don't know the directory...hmmm, how do you know then that the script file is there? Does this help? Roland -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] Useful books for learning the R software and the S programminglanguage
Hi, if I may add my 2 cents. - The most important thing is to have a real problem/question you want to solve. Just "trying to learn" is very difficult because you might encounter some problems and if this is not a problem you *have* to solve, I would have the tendency to skip this particular problem. - Have a look at "An Introduction to R". This manual is shipped with every R distribution. Also have a look at the Data Import/Export Manual (also shipped with R). With real problems usually you have already a data-set which you need to read/load. - If you want to buy yourself only one book, I would recommend the Venables & Ripley: Modern Applied Statistics with S ("MASS"). It covers many, many topics such as GLMs, survival analysis, time series analysis, If you know already what kind of statistical analysis you want to perform, this is the ideal book because it summarizes the statistical theory and shows how this is implemented in R. (And in case that R and S-Plus differ, MASS tells you how). Peter Dalgaard's "An Introduction to R" is also an excellent but. It requires less from the reader than MASS. Maybe have a look at both and then decide for yourself (sorry, those are the only two R books I have). - Make yourself familiar with the help functions in R. They might look strange in the beginning, but they are incredibly helpful. Besides the great example section, I consider the "See Also" section to be very helpful: when you are not exactly sure if the current help page is what you are looking for, quite often I found the function I actually needed mentioned there. - Don't try to "translate" from other statistics packages. This might be particularly difficult. When I started with R, I was looking for instance for "what is the equivelant R function of SPSS's 'recode'?". Rather try to formulate the problem in English words and then search for it in the R-Help archives. Furthermore, for me, personally, "S Poetry" by Patrick Burns was a joy to read and it was the best tutorial for subscripting (Chapter 1.3). http://www.burns-stat.com/pages/spoetry.html (I am looking forward to read his "Inferno" as well.) I hope this helps a bit, Roland > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Robert Wilk > Sent: Monday, January 12, 2009 9:36 PM > To: r-help@r-project.org > Subject: [R] Useful books for learning the R software and the > S programminglanguage > > any useful books for learning the R statistical software? > are they pricey? > > and if the books recommended focus on S, how compatible will > they be for > someone learning R? > > thank you in advance for your help. > > > P.S. > specialized survey statistical procedures? Is R good at that? > > [[alternative HTML version deleted]] > > __ > R-help@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. > -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.
Re: [R] Extracting File Basename without Extension
Hi, > [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique > Dallazuanna > > Try this also: > > substr(basename(myfile), 1, nchar(basename(myfile)) - 4) > This, of course, assumes that the extensions are always 3 characters. Sometimes there might be more ("index.html"), sometimes less ("shellscript.sh"). Although my solution is not as compact as the others (I wish I was proficient in 'mastering regular expressions'), I'd like to provide my little code-snippet which does not require any regular expressions (but expects a . in the filename). ## x1 <- "roland.txt" x2 <- "roland.html" x3 <- "roland.sh" no.extension <- function(astring) { if (substr(astring, nchar(astring), nchar(astring))==".") { return(substr(astring, 1, nchar(astring)-1)) } else { no.extension(substr(astring, 1, nchar(astring)-1)) } } no.extension(x1) no.extension(x2) no.extension(x3) ## Hope this helps a bit, Roland P.S. Any suggestions how to become more proficient with regular expressions? The O'Reilly book ("Mastering...")? Whenever I tried anything more complicated than basic usage (things like ^ $ * . ) in R, I was way faster to write a new function (like above) instead of finding a regex solution. By the way: it might be still possible to *write* regular expressions, but what about code re-use? Are there people who can easily *read* complicated regular expressions? -- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance. __ R-help@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.