Re: [R] Opposite color in R
I wonder if the hcl colour space is useful? Varying hue while keeping chroma and luminosity constant should give varying colours of perceptually the same colourness and brightness. ?hcl pie(rep(1,12),col=hcl((1:12)*30,c=70),border=NA) -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Atte Tenkanen Sent: Sunday, 26 July 2015 7:50a To: r-help@r-project.org Subject: [R] Opposite color in R Hi, I have tried to find a way to find opposite or complementary colors in R. I would like to form a color circle with R like this one: http://nobetty.net/dandls/colorwheel/complementary_colors.jpg If you just make a basic color wheel in R, the colors do not form complementary color circle: palette(rainbow(24)) Colors=palette() pie(rep(1, 24), col = Colors) There is a package ”colortools” where you can find function opposite(), but it doesn’t work as is said. I tried library(colortools) opposite(violet) and got green instead of yellow and opposite(blue) and got yellow instead of orange. Do you know any solutions? Atte Tenkanen __ 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] valid LRT between MASS::polr and nnet::multinom
Dear R-helpers, Does anyone know if the likelihoods calculated by these two packages are comparable in this way? That is, is this a valid likelihood ratio test? # Reproducable example: library(MASS) library(nnet) data(housing) polr1 = MASS::polr(Sat ~ Infl + Type + Cont, weights=Freq, data=housing) mnom1 = nnet::multinom(Sat ~ Infl + Type + Cont, weights=Freq, data=housing) pll = logLik(polr1) mll = logLik(mnom1) res = data.frame( model = c('Proportional odds','Multinomial'), Function = c('MASS::polr','nnet::multinom'), nobs = c(attr(pll, 'nobs'), attr(mll, 'nobs')), df = c(attr(pll, 'df'), attr(mll, 'df')), logLik = c(pll,mll), deviance = c(deviance(polr1), deviance(mnom1)), AIC = c(AIC(polr1), AIC(mnom1)), stringsAsFactors = FALSE ) res[3,1:2] = c(Difference,) res[3,3:7] = apply(res[,3:7],2,diff)[1,] print(res) mytest = structure( list( statistic = setNames(res$logLik[3], X-squared), parameter = setNames(res$df[3],df), p.value = pchisq(res$logLik[3], res$df[3], lower.tail = FALSE), method = Likelihood ratio test, data.name = housing ), class='htest' ) print(mytest) # If you want to see the fitted results: library(effects) plot(allEffects(polr1), layout=c(3,1), ylim=0:1) plot(allEffects(mnom1), layout=c(3,1), ylim=0:1) many thanks, Steve __ 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] Subset() within function: logical error
Using return() within a for loop makes no sense: only the first one will be returned. How about: alldf.B = subset(alldf, stream=='B') # etc... Also, have a look at unique(alldf$stream) or levels(alldf$stream) if you want to use a for loop on each unique value. cheers, Steve -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rich Shepard Sent: Tuesday, 30 June 2015 12:04p To: r-help@r-project.org Subject: [R] Subset() within function: logical error Moving from interactive use of R to scripts and functions and have bumped into what I believe is a problem with variable names. Did not see a solution in the two R programming books I have or from my Web searches. Inexperience with ess-tracebug keeps me from refining my bug tracking. Here's a test data set (cleverly called 'testset.dput'): structure(list(stream = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c(B, J, S), class = factor), sampdate = structure(c(8121, 8121, 8121, 8155, 8155, 8155, 8185, 8185, 8185, 8205, 8205, 8205, 8236, 8236, 8236, 8257, 8257, 8257, 8308, 8785, 8785, 8785, 8785, 8785, 8785, 8785, 8847, 8847, 8847, 8847, 8847, 8847, 8847, 8875, 8875, 8875, 8875, 8875, 8875, 8875, 8121, 8121, 8121, 8155, 8155, 8155, 8185, 8185, 8185, 8205, 8205, 8205, 8236, 8236, 8236, 8257, 8257, 8257, 8301, 8301, 8301), class = Date), param = structure(c(2L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L, 2L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L, 2L, 6L, 7L ), .Label = c(Ca, Cl, K, Mg, Na, SO4, pH), class = factor), quant = c(4, 33, 8.43, 4, 32, 8.46, 4, 31, 8.43, 6, 33, 8.32, 5, 33, 8.5, 5, 32, 8.5, 5, 59.9, 3.46, 1.48, 29, 7.54, 64.6, 7.36, 46, 2.95, 1.34, 21.8, 5.76, 48.8, 7.72, 74.2, 5.36, 2.33, 38.4, 8.27, 141, 7.8, 3, 76, 6.64, 4, 74, 7.46, 2, 82, 7.58, 5, 106, 7.91, 3, 56, 7.83, 3, 51, 7.6, 6, 149, 7.73)), .Names = c(stream, sampdate, param, quant ), row.names = c(NA, -61L), class = data.frame) I want to subset that data.frame on each of the stream names: B, J, and S. This is the function that has the naming error (eda.R): extstream = function(alldf) { sname = alldf$stream sdate = alldf$sampdate comp = alldf$param value = alldf$quant for (i in sname) { sname - subset(alldf, alldf$stream, select = c(sdate, comp, value)) return(sname) } } This is the result of running source('eda.R') followed by extstream(testset) Error in subset.data.frame(alldf, alldf$stream, select = c(sdate, comp, : 'subset' must be logical I've tried using sname for the rows to select, but that produces a different error of trying to select undefined columns. A pointer to the correct syntax for subset() is needed. Rich __ 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] Call to a function
Note that objects can have more than one class, in which case your == and %in% might not work as expected. Better to use inherits(). cheers, Steve -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Steven Yen Sent: Wednesday, 24 June 2015 11:37a To: boB Rudis Cc: r-help mailing list Subject: Re: [R] Call to a function Thanks! From this I learn the much needed class statement if (class(wt)==character) wt - x[, wt] which serves my need in a bigger project. Steven Yen On 6/23/2015 6:20 PM, boB Rudis wrote: You can do something like: aaa - function(data, w=w) { if (class(w) %in% c(integer, numeric, double)) { out - mean(w) } else { out - mean(data[, w]) } return(out) } (there are some typos in your function you may want to double check, too) On Tue, Jun 23, 2015 at 5:39 PM, Steven Yen sye...@gmail.com wrote: mydata-data.frame(matrix(1:20,ncol=2)) colnames(mydata) -c(v1,v2) summary(mydata) aaa-function(data,w=w){ if(is.vector(w)){ out-mean(w) } else { out-mean(data[wt]) } return(out) } aaa(mydata,mydata$v1) aaa(mydata,v1) # want this call to work -- Steven Yen My e-mail alert: https://youtu.be/9UwEAruhyhY?list=PLpwR3gb9OGHP1BzgVuO9iIDdogVOijCtO __ 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] Plotting Confidence Intervals
Have you tried: library(effects) plot(allEffects(ines),ylim=c(460,550)) -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Andre Roldao Sent: Saturday, 2 May 2015 2:50p To: r-help@r-project.org Subject: [R] Plotting Confidence Intervals Hi Guys, It's the first time i use R-Help and i hope you can help me. How can i plot conffidence intervals? with the data bellow: #Package Austria library(car) #head(States) States1=data.frame(States) ines=lm(SATM ~ log2(pop) + SATV , data=States1) summary(ines) NJ=as.data.frame(States[NJ,c(4,2,3)]) #Identificação do estado NJ p_conf- predict(ines,interval=confidence,NJ,level=0.95) p_conf #Intervalo de confiança para o estado NJ e para um nivel de 95% round(p_conf, digits=3) p_conf1- predict(ines,interval=confidence,NJ,level=0.99) p_conf1 #Intervalo de confiança para o estado NJ e para um nivel de 99% round(p_conf, digits=3) p_pred2- predict(ines,interval=prediction,NJ,level=0.95) p_pred2 #Intervalo de perdição para o estado NJ e para um nivel de 95% round(p_pred2,digits=3) p_pred3- predict(ines,interval=prediction,NJ,level=0.99) p_pred3 #Intervalo de perdição para o estado NJ e para um nivel de 99% round(p_pred3,digits=3) Thanks [[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] cbind question, please
This works for me... get0 = function(x) get(x,pos=1) sapply(big.char, get0) The extra step seems necessary because without it, get() gets base::cat() instead of cat. cheers, Steve -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess Sent: Friday, 24 April 2015 10:41a To: R help Subject: [R] cbind question, please Hello! I have a cbind type question, please: Suppose I have the following: dog - 1:3 cat - 2:4 tree - 5:7 and a character vector big.char - c(dog,cat,tree) I want to end up with a matrix that is a cbind of dog, cat, and tree. This is a toy example. There will be a bunch of variables. I experimented with do.call, but all I got was 1 2 3 Any suggestions would be much appreciated. I still think that do.call might be the key, but I'm not sure. R Version 3-1.3, Windows 7. Thanks, Erin -- Erin Hodgess Associate Professor Department of Mathematical and Statistics University of Houston - Downtown mailto: erinm.hodg...@gmail.com [[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] regex find anything which is not a number
How about letting a standard function decide which are numbers: which(!is.na(suppressWarnings(as.numeric(myvector Also works with numbers in scientific notation and (presumably) different decimal characters, e.g. comma if that's what the locale uses. -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Adrian Du?a Sent: Thursday, 12 March 2015 8:27a To: r-help@r-project.org Subject: [R] regex find anything which is not a number Hi everyone, I need a regular expression to find those positions in a character vector which contain something which is not a number (either positive or negative, having decimals or not). myvector - c(a3, N.A, 1.2, -3, 3-2, 2.) In this vector, only positions 3 and 4 are numbers, the rest should be captured. So far I am able to detect anything which is not a number, excluding - and . grep([^-0-9.], myvector) [1] 1 2 I still need to capture positions 5 and 6, which in human language would mean to detect anything which contains a - or a . anywhere else except at the beginning of a number. Thanks very much in advance, Adrian -- Adrian Dusa University of Bucharest Romanian Social Data Archive Soseaua Panduri nr.90 050663 Bucharest sector 5 Romania __ 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] Using dates in R
today - as.Date(2015-03-04) # default format Better is: today - Sys.Date() S -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of William Dunlap Sent: Thursday, 5 March 2015 7:47a To: Brian Hamel Cc: r-help@r-project.org Subject: Re: [R] Using dates in R You will need to convert strings like 2/15/15 into one of the time/date classes available in R and then it is easy to do comparisons. E.g., if you have no interest in the time of day you can use the Date class: d - as.Date(c(12/2/79, 4/15/15), format=%m/%d/%y) today - as.Date(2015-03-04) # default format d [1] 1979-12-02 2015-04-15 today [1] 2015-03-04 d today [1] TRUE FALSE The lubridate package contains a bunch of handy functions for manipulating dates and times. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Mar 4, 2015 at 6:54 AM, Brian Hamel bh16...@student.american.edu wrote: Hi all, I have a dataset that includes a date variable. Each observation includes a date in the form of 2/15/15, for example. I'm looking to create a new indicator variable that is based on the date variable. So, for example, if the date is earlier than today, I would need a 0 in the new column, and a 1 otherwise. Note that my dataset includes dates from 1979-2012, so it is not one-year (this means I can't easily create a new variable 1-365). How does R handle dates? My hunch is not well, but perhaps there is a package that can help me with this. Let me know if you have any recommendations as to how this can be done relatively easily. Thanks! Appreciate it. Best, Brian [[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. [[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] the less-than-minus gotcha
Responding to several messages in this thread... All the more reason to use = instead of - Definitely not! Martin and Rolf are right, it's not a reason for that; I wrote that quickly without thinking it through. An = user might be more likely to fall for the gotcha, if not spacing their code nicely. So the lesson learned from the gotcha is that it's good to space your code nicely, as others have siad, not which assignment symbol to use. However, I continue to use = for assignment on a daily basis without any problems, as I have done for many years. I remain unconvinced by any and all of these arguments against it in favour of -. People telling me that I should use the arrow need better agruments than what I've seen so far. I find - ugly and - useless/pointless, whereas = is simpler and also nicely familiar from my experience in other languages. It doesn't matter to me that = is not commutative because I don't need it to be. Further it can be nicely marked up by a real left arrow by e.g. the listings LaTeX 'listings' package... Now that's just silly, turning R code into graphical characters that are not part of the R language. foo(x = y) and foo(x - y) I'm well aware of this distinction and it never causes me any problems. The latter is an example of bad (obfuscated) coding, IMHO; it should be done in two lines for clarity as follows: x = y foo(x) Using = has it's problems too. Same goes for apostrophes. Shall we discuss putting else at the start of line next? cheers, Steve __ 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] the less-than-minus gotcha
I disagree. Assignments in my code are all lines that look like this: variable = expression They are easy to find and easy to read. -Original Message- From: Ista Zahn [mailto:istaz...@gmail.com] Sent: Tuesday, 3 February 2015 3:36p To: Steve Taylor Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] the less-than-minus gotcha On Mon, Feb 2, 2015 at 8:57 PM, Steve Taylor steve.tay...@aut.ac.nz wrote: Fair enough, but you skipped right past the most important one: it makes code easier to read. It's very nice to be able to visually scan through the code and easily see where assignment happens. __ 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] the less-than-minus gotcha
Nobody would write x=x or indeed x-x; both are silly. If I found myself writing f(x=x) I might smirk at the coincidence, but it wouldn't bother me. I certainly wouldn't confuse it with assigning x to itself. By the way, here's another assignment operator we can use: `:=` = `-` # this is going in my .Rprofile x := 1 -Original Message- From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] Sent: Tuesday, 3 February 2015 3:54p To: Steve Taylor; r-h...@stat.math.ethz.ch Subject: Re: [R] the less-than-minus gotcha I did not start out liking -, but I am quite attached to it now, and even Rcpp feels weird to me now. This may seem like yet another variation on a theme that you don't find compelling, but I find that f(x=x) makes sense when scope is considered, but x=x on its own is silly. That is why I prefer to reserve = for assigning parameters... I use it to clarify that I am crossing scope boundaries, while - never does. (- is a dangerous animal, though... to be used only locally in nested function definitions). In my view, this is similar to preferring == from C-derived syntaxes over the overloaded = from, say, Basic. I am sure you can get by with the syntactic overloading, but if you have the option of reducing ambiguity, why not use it? --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 2, 2015 5:57:05 PM PST, Steve Taylor steve.tay...@aut.ac.nz wrote: Responding to several messages in this thread... All the more reason to use = instead of - Definitely not! Martin and Rolf are right, it's not a reason for that; I wrote that quickly without thinking it through. An = user might be more likely to fall for the gotcha, if not spacing their code nicely. So the lesson learned from the gotcha is that it's good to space your code nicely, as others have siad, not which assignment symbol to use. However, I continue to use = for assignment on a daily basis without any problems, as I have done for many years. I remain unconvinced by any and all of these arguments against it in favour of -. People telling me that I should use the arrow need better agruments than what I've seen so far. I find - ugly and - useless/pointless, whereas = is simpler and also nicely familiar from my experience in other languages. It doesn't matter to me that = is not commutative because I don't need it to be. Further it can be nicely marked up by a real left arrow by e.g. the listings LaTeX 'listings' package... Now that's just silly, turning R code into graphical characters that are not part of the R language. foo(x = y) and foo(x - y) I'm well aware of this distinction and it never causes me any problems. The latter is an example of bad (obfuscated) coding, IMHO; it should be done in two lines for clarity as follows: x = y foo(x) Using = has it's problems too. Same goes for apostrophes. Shall we discuss putting else at the start of line next? cheers, Steve __ 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] the less-than-minus gotcha
All the more reason to use = instead of - -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ben Bolker Sent: Monday, 2 February 2015 2:07p To: r-h...@stat.math.ethz.ch Subject: Re: [R] the less-than-minus gotcha Mike Miller mbmiller+l at gmail.com writes: I've got to remember to use more spaces. Here's the basic problem: These are the same: v 1 v1 But these are extremely different: v -1 v-1 This is indeed documented, in passing, in one of the pages you listed: http://tim-smith.us/arrgh/syntax.html Whitespace is meaningless, unless it isn't. Some parsing ambiguities are resolved by considering whitespace around operators. See and despair: x-y (assignment) is parsed differently than x -y (comparison)! __ 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] Webdings font on pdf device
Dear R-helpers Has anyone successfully used the Webdings font on a pdf or postscript device? I'm tearing my hair out trying to figure out how to make it work. # It works on a png() device: windowsFonts(Webdings = windowsFont(Webdings)) png('Webdings.png', family = 'Webdings') plot(-3:3,-3:3,type='n',xlab='',ylab='',axes=FALSE) text (rnorm(26),rnorm(26),LETTERS,cex=2) graphics.off() I have tried to set up the Webdings font using the extrafont package but it gives warnings. The output file says it has Webdings in it, but the characters do not show. R library(extrafont) Registering fonts with R R loadfonts(device = pdf, quiet=TRUE) R pdf('Webdings.pdf', family='Webdings') Warning messages: 1: In pdf(Webdings.pdf, family = Webdings) : unknown AFM entity encountered 2: In pdf(Webdings.pdf, family = Webdings) : unknown AFM entity encountered 3: In pdf(Webdings.pdf, family = Webdings) : unknown AFM entity encountered 4: In pdf(Webdings.pdf, family = Webdings) : unknown AFM entity encountered R plot(-3:3,-3:3,type='n',xlab='',ylab='',axes=FALSE) R text (rnorm(26),rnorm(26),LETTERS,cex=2) There were 27 warnings (use warnings() to see them) R graphics.off() R warnings()[1] Warning message: In text.default(rnorm(26), rnorm(26), LETTERS, cex = 2) : font width unknown for character 0x41 Any assistance would be much appreciated. cheers, Steve __ 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] Exporting R graphics into Word without losing graph quality
Unfortunately the win.metafile() device does not support semi-transparent colours, which I like using. In my experience, the best way to get R graphics into Word is to use compressed high-resolution tiff, like this: word.tif = function(filename=Word_Figure_%03d.tif, zoom=4, width=17, height=10, pointsize=10, ...) { if (!grepl([.]ti[f]+$, filename, ignore.case=TRUE)) filename = paste0(filename,.tif) tiff(filename=filename, compression=lzw, res=96*zoom, width=width, height=height, units='cm', pointsize=pointsize, ...) } word.tif('test') plot(rnorm(100)) dev.off() Now drag the file test.tif into your Word document. Sure, it's a bitmap format rather than a vector format, but the quality is excellent and the file sizes are still quite small. None of the vector formats works as well as this. cheers, Steve __ 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] Exporting R graphics into Word without losing graph quality
From: Duncan Murdoch... Don't use a bitmap format (png). I disagree. Each vector format comes with its own problems. Don't produce your graph in one format (screen display), then convert to another (png). Open the device in the format you want for the final file. Agreed. Use a vector format for output. Why? Sure, that's good advice in the ideal (pdflatex) world, but not necessarily the best of advice for Word users. I don't know what kinds Word supports, but EPS or PDF would likely be best; if it can't read those, then Windows metafile (via windows() to open the device) would be best. None of these works well, if at all, in my experience with Word. Don't use Word. Some of us don't really have a choice. __ 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] How can I create a data.table with 1000 variables (Var1:Var1000)
How about this: df1000cols = setNames(as.data.frame(matrix(numeric(0),ncol=1000)),paste0(V,1:1000)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Pooya Lalehzari Sent: Friday, 16 August 2013 8:27a To: Bert Gunter Cc: r-help@r-project.org Subject: Re: [R] How can I create a data.table with 1000 variables (Var1:Var1000) Sorry. data.table or even data.frame (as they are related). My question is, if there is a short form to refer to all 1000 of them similar to what exists in SAS. Thank you, Pooya Lalehzari. -Original Message- From: Bert Gunter [mailto:gunter.ber...@gene.com] Sent: Thursday, August 15, 2013 4:24 PM To: Pooya Lalehzari Cc: r-help@r-project.org Subject: Re: [R] How can I create a data_table with 1000 variables (Var1:Var1000) Please: 1. Define data_table (??) 2. Follow the advice from the posting guide link below to post a coherent question. -- Bert On Thu, Aug 15, 2013 at 1:16 PM, Pooya Lalehzari plalehz...@platinumlp.com wrote: Hello everyone, How can I create a data_table with 1000 variables (Var1:Var1000)? Thank you, Pooya Lalehzari THIS E-MAIL IS FOR THE SOLE USE OF THE INTENDED RECIPIENT(S) AND MAY CONTAIN CONFIDENTIAL AND PRIVILEGED INFORMATION.ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE CONTACT THE SENDER BY REPLY E-MAIL AND DESTROY ALL COPIES OF THE ORIGINAL E-MAIL. [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm THIS E-MAIL IS FOR THE SOLE USE OF THE INTENDED RECIPIENT(S) AND MAY CONTAIN CONFIDENTIAL AND PRIVILEGED INFORMATION.ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE CONTACT THE SENDER BY REPLY E-MAIL AND DESTROY ALL COPIES OF THE ORIGINAL E-MAIL. __ 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-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] Matrix Multiplication using R.
The function crossprod() might be useful? crossprod(X) is a more efficient way of producing t(X) %*% X -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Praveen Surendran Sent: Thursday, 15 August 2013 10:30p To: r-help@r-project.org Subject: Re: [R] Matrix Multiplication using R. Dear Doran, Bert and Roger, Thank you for attending my query and for your valuable responses. The task is slightly more complex. Here's the real case... I have genetic variation data (40,000 single nucleotide polymorphisms) from 90,000 individuals. This makes the 90,000 (samples) rows/columns of the matrix and 40,000 (SNPs) rows/columns of the matrix. Matrix data are genetic variations with values 0,1,2 or 3 where 0 is missing. There will be very few individuals with missing data. The task is to identify the relatedness between these 90,000 individuals using their genetic data (0,1,2 or 3). These values needs to be standardised before matrix multiplication. This will make the matrix much larger compared to the 0/1/2/3 matrix and most of these will be real numbers with decimals. Bert, I will not be doing a 90,000 x 40,000 %*% 40,000 x 90,000. The plan is to load this 9 x 4 matrix into R, then standardise and multiply this in batches of 90,000 samples against 500 samples using these 40,000 variants and process these in parallel to get 90,000 x 90,000 comparisons. Does that sort of clarifies the situation? I tried loading a 90,000 x 40,000 matrix as a matrix in R this morning on the cluster with specifications described in my previous e-mail. This crashed due to memory overflow. I am trying for possibilities Any comments or thoughts will be greatly appreciated. Regards, Praveen. -Original Message- From: Roger Koenker [mailto:rkoen...@illinois.edu] Sent: 14 August 2013 23:06 To: Praveen Surendran Cc: r-help@r-project.org Subject: Re: [R] Matrix Multiplication using R. In the event that these are moderately sparse matrices, you could try Matrix or SparseM. Roger Koenker rkoen...@illinois.edu On Aug 14, 2013, at 10:40 AM, Praveen Surendran wrote: Dear all, I am exploring ways to perform multiplication of a 9 x 4 matrix with it's transpose. As expected even a 4 x 100 %*% 100x4 didn't work on my desktop... giving the error Error: cannot allocate vector of length 16 However I am trying to run this on one node (64GB RAM; 2.60 GHz processor) of a high performance computing cluster. Appreciate if anyone has any comments on whether it's advisable to perform a matrix multiplication of this size using R and also on any better ways to handle this task. Kind Regards, Praveen. [[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-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-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] Boundaries of consecutive integers
How's this: big.gap = diff(test) 1 cbind(test[c(TRUE, big.gap)], test[c(big.gap, TRUE)]) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Lizzy Wilbanks Sent: Tuesday, 14 May 2013 1:18p To: r-help@r-project.org Subject: [R] Boundaries of consecutive integers Hi folks, I'm trying to accomplish something that seems like it should be straightforward, but I've gotten tied in knots trying to figure it out. A toy example of my issue is below. I've played with diff and can't seem to figure out a systematic solution that will give me the two column output independent of the number of breakpoints in the vector... test-c(1:5, 22:29,33:40) example.output-matrix(c(1,5,22,29,33,40),nrow=3,ncol=2,byrow=TRUE) Any ideas? Thanks! Lizzy -- The obvious goal of any bacterium is to become bacteria. Lizzy Wilbanks Graduate Student, Eisen and Facciotti Labs UC Davis, Microbiology Graduate Group __ 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-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] using a personal template for new R scripts
Does anyone know if there's an easy facility to create and specify a template file to be used for new R scripts? I found myself creating this function which works well (in RStudio on Windows). newR = function(filename=tempfile(tmpdir='.',fileext='.R'), open=TRUE) { template = paste(Sys.getenv('R_USER'), 'R_template.R', sep='/') lines = readLines(template) lines = sub('Sys.time', format(Sys.time(), '%A, %d %B %Y'), lines) lines = sub('getwd', getwd(), lines) lines = sub('R.version.string', R.version.string, lines) writeLines(lines, filename) if (open) shell.exec(filename) filename } Rather than the default of an empty file, it would be good practice to start with a structured template script. Such a template might contain opening comments (author, date, project folder, aims, inputs, outputs etc.) and section comment headings for the various components of what a script does (load packages, get data, process data, produce outputs). cheers, Steve __ 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] Any R package to do the harmonic analysis
Have a look thru the Time Series task view... http://cran.r-project.org/web/views/TimeSeries.html -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Janesh Devkota Sent: Wednesday, 20 February 2013 5:52a To: r-help@r-project.org Subject: [R] Any R package to do the harmonic analysis Hi R Users, I was wondering if there is any R package available to do the harmonic analysis of tide. Any suggestion is highly appreciated. Janesh [[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-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] how to use ...
From: Duncan Murdoch Maybe we just need a manual on how to use the existing help system. But I suspect people who won't read the existing manuals won't read that one, either. Duncan, I assume you're being facetious. Every R user soon learns to use help() and help.search() or their equivalents. We don't need a manual to teach that. Rolf Turner wrote: The help facility is applicable to functions and data sets. It is not designed or intended to give help with respect to R syntax (with the exception of the basic syntax of the operators --- unary and binary --- and the associated rules of precedence). Then why are there help pages ?:::, ?for, ?NA_character_, ?.C and ??? but not ?... ?! __ 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] how to use ...
On 13-01-20 2:28 PM, Steve Taylor wrote: From: Duncan Murdoch Maybe we just need a manual on how to use the existing help system. But I suspect people who won't read the existing manuals won't read that one, either. Duncan, I assume you're being facetious. Every R user soon learns to use help() and help.search() or their equivalents. We don't need a manual to teach that. There are other parts of the help system that you don't appear to know about. Run help.start() for the main index page. help() is kind of a shortcut to the section labelled Packages. help.search() gets you to Search Engine Keywords. There are 15 other headings to explore as well. I know about them even tho I didn't mention them. Rolf Turner wrote: The help facility is applicable to functions and data sets. It is not designed or intended to give help with respect to R syntax (with the exception of the basic syntax of the operators --- unary and binary --- and the associated rules of precedence). Then why are there help pages ?:::, ?for, ?NA_character_, ?.C and ??? but not ?... ?! Those are all functions or other objects, while ... is not. There are examples of topic aliases that are not objects, e.g. ?Syntax, but mostly Rolf is right. Most discussion of the syntax is in the manuals. Nevertheless, help(...) is a reasonable thing for a user to do and expect some help. __ 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] sem package, suppress warnings
Have you tried suppressWarnings(sem(mod, S = as.matrix(dataset), N = 1000, maxiter = 1, warn = FALSE)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dustin Fife Sent: Saturday, 19 January 2013 5:32a To: r-help Subject: [R] sem package, suppress warnings Hi, I'm using the sem package under conditions where I know beforehand that several models will be problematic. Because of that, I want to suppress warnings. I've used the following code sem(mod, S = as.matrix(dataset), N = 1000, maxiter = 1, warn = FALSE) But I still get warnings. I've also tried adding check.analytic = FALSE, debug = FALSE, and that doesn't seem to do it either. Any ideas why it's not working? It may be important to note that the command above is wrapped within a function and I'm using try() to avoid errors. Thanks in advance! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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-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] how to use ...
The ellipsis object is not listed in the base help pages! help(`+`) # this works - help on arithmetic operators help(+) # also works help(`...`) # fails with Error: '...' used in an incorrect context help(...) # fails also with No documentation for '...' in specified packages and libraries: you could try '??...' -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Friday, 18 January 2013 4:43a To: R. Michael Weylandt Cc: R list Subject: Re: [R] how to use ... Do you know where I can find some documentation about it? __ 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] how to use ...
Here's a link (on my local CRAN)... http://cran.stat.auckland.ac.nz/doc/manuals/r-release/R-intro.html#The-three-dots-argument -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter Sent: Friday, 18 January 2013 4:54a To: ivan.calan...@u-bourgogne.fr Cc: R list Subject: Re: [R] how to use ... Well.. On Thu, Jan 17, 2013 at 7:42 AM, Ivan Calandra ivan.calan...@u-bourgogne.fr wrote: Ok, it is that simple... Actually I had tried it but messed up so that it didn't work. Do you know where I can find some documentation about it? The R language definition manual would be the logical place to look, no? And sure enough, it's there! The Introduction to R tutorial also contains info in the writing functions section. A very good, though now dated, exposition can be found in VR's S Programming book. Although a little care is needed due to age, it's still my favorite. -- Bert Regarding return(), I know that it's not necessary, but when the function gets more complicated, I like to have it because it becomes clearer to me. Thanks all! Ivan -- Ivan CALANDRA Université de Bourgogne UMR CNRS/uB 6282 Biogéosciences 6 Boulevard Gabriel 21000 Dijon, FRANCE +33(0)3.80.39.63.06 ivan.calan...@u-bourgogne.fr http://biogeosciences.u-bourgogne.fr/calandra Le 17/01/13 15:55, R. Michael Weylandt a écrit : On Thu, Jan 17, 2013 at 2:36 PM, Ivan Calandra ivan.calan...@u-bourgogne.fr wrote: Dear users, I'm trying to learn how to use the I have written a function (simplified here) that uses doBy::summaryBy(): # 'dat' is a data.frame from which the aggregation is computed # 'vec_cat' is a integer vector defining which columns of the data.frame should be use on the right side of the formula # 'stat_fun' is the function that will be run to aggregate stat.group - function(dat, vec_cat, stat_fun){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun) return(df) } [SNIP EXAMPLE -- THANK YOU FOR IT] Now summaryBy() has an ... argument and I would like to use it. For example, I would like to be able to add the trim argument to my call like this: stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2) Thanks for the great working examples! It's actually not too hard here -- just pass ... down as if it were an argument and let summaryBy() do the hard work of actually handling the dots: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) return(df) } Also, note that as a matter of style, you can actually clean this up a little bit: R follows the trend of many functional languages in automatically returning the value of the last expression evaluated: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) } Cheers, Michael __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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-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] Setting Number of Displayed Digits
Have you tried: options(digits=9) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Rich Shepard Sent: Wednesday, 8 August 2012 5:51a To: r-help@r-project.org Subject: [R] Setting Number of Displayed Digits Some chemicals have concentrations at or below the method detection limit (MDL; 'less-thans') of 0.005 mg/L. When I look at the data frame that is how the concentration is displayed. But, when I ask for a summary() of that data frame column only 0 is displayed. How can I adjust the number of digits displayed by functions such as summary()? Rich __ 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-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] Package 'nlme' linear mixed effects model error unexpected symbol
This will work: model2007 - You can't start an identifier with a digit. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of msherwood Sent: Thursday, 26 July 2012 9:44a To: r-help@r-project.org Subject: [R] Package 'nlme' linear mixed effects model error unexpected symbol I am trying the following code with the 'nlme' package: 2007modellme(Rank~Age*Mass+method='ML',random=~1|ID,na.action=na.exclude) I've also tried all kinds of variations of the above that I could think of. It gives me the error unexpected symbol in '2007model' . I'm not sure if this 'unexpected symbol' refers to the code I enter or the data table I am using. I haven't found any useful information in a Google search or in the R help files. Any suggestions of what the problem may be? -- View this message in context: http://r.789695.n4.nabble.com/Package-nlme-linear-mixed-effects-model-error-unexpected-symbol-tp4637842.html Sent from the R help mailing list archive at Nabble.com. __ 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-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] Boxplot with Log10 and base-exponent axis
This (and William's solution) is so good, I must ask: Is there a good reason why this is not the default functionality in the graphics package? The default displays the number 1 as 1+e00 which is hideous! -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Maechler Sent: Saturday, 23 June 2012 4:57a To: Luigi; William Dunlap Cc: r-help@r-project.org Subject: Re: [R] Boxplot with Log10 and base-exponent axis The key is to supply an expression, not text, to the labels argument to axis. See help(plotmath) for details. Here is an example: x - list(One=10^(sin(1:10)+5), Two=10^(cos(1:30)*2)) boxplot(x, log=y, yaxt=n) ylim - par(usr)[3:4] log10AtY - seq(ceiling(ylim[1]), floor(ylim[2])) axis(side=2, at=10^log10AtY, lab=as.expression(lapply(log10AtY, function(y)bquote(10^.(y) Yes, that's nice, and exactly the basic idea. For a few years now, the eaxis() function in package sfsmisc does (something like) this (and a bit more) even more nicely : install.packages(sfsmisc) require(sfsmisc) x - list(One=10^(sin(1:10)+5), Two=10^(cos(1:30)*2)) boxplot(x, log=y, yaxt=n) eaxis(2) -- Martin Maechler, ETH Zurich __ 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] glm(weights) and standard errors
Thanks Peter for your clarifications. Yes, the definition I'm looking for is: - I have 0.1 observations identical to this one, i.e. this row and nine others similar (but not identical) to it together represent a single observation. in lm/glm ... the weights are really only relative This is the problem I would like to get around. do we get the extra variability of the variance right? The Wood et al paper suggests modifications to the weights to adjust for the varying amount of missingness in covariates. I know Thomas (we're both in Auckland) so I'll ask him about the survey package. -Original Message- From: peter dalgaard [mailto:pda...@gmail.com] Sent: Friday, 25 May 2012 9:37p To: ilai Cc: Steve Taylor; r-help@r-project.org Subject: Re: [R] glm(weights) and standard errors Weighting can be confusing: There are three standard forms of weighting which you need to be careful not to mix up, and I suspect that the imputation weights are really a 4th version. First, there is case (replication) vs. precision weighting. A weight of 10 means one of - I have 10 observations identical to this one - This observation has a variance of sigma^2/10 as if it were the average of 10 observations. There are also sampling weights: - For each observation like this, I have 10 similar observations in the population (and I want to estimate a population parameter like the national average income or the percentage of votes at a hypothetical general election). What R does in lm/glm is precision weights. Notice that when the variance is estimated from data, the weights are really only relative: if all observations are weighted equally (all 10, say), you get a 10-fold increase in the estimated sigma^2 and a tenfold decrease in the unscaled variance-covariance matrix. So the net result is that the standard errors are the same (but they won't be if the weights are unequal). The three weighting schemes share the same formula for the estimates, but differ both in the estimated variance and df, and in the formula for the standard errors. Sampling weights are the domain of the survey package, but I don't think it does replication weights (someone called Thomas may chime in and educate me otherwise). I'm not quite sure, but I think you can get from a precision-weighted analysis to a case-weighted one just by adjusting the DF for error (changing the residual df to df+sum(w)-n, and sigma^2 proportionally). Imputation weights look like the opposite of case weights: You give 10 observations when in fact you have only one. An educated guess would be that you could do something similar as for case weights -- in this case sum(w) will be much less than n, so you will decrease the residual rather than increase it. I get this nagging feeling that it might still not be quite right, though -- in the cases where the imputations actually differ, do we get the extra variability of the variance right? Or maybe we don't need to care. There is a literature on the subject On May 25, 2012, at 09:21 , ilai wrote: I'm confused (I bet David is too). First and last models are the same, what do SE's have to do with anything ? naive - glm(extra ~ group, data=sleep) imputWrong - glm(extra ~ group, data=sleep10) imput - glm(extra ~ group, data=sleep10,weights=rep(0.1,nrow(sleep10))) lapply(list(naive,imputWrong,imput),anova) sapply(list(naive,imuptWrong,imput),function(x) vcov(x)[1,1]/vcov(x)[2,2]) # or another way to see it (adjust for the DF) coef(summary(naive))[2,2] - sqrt(198)/sqrt(18) * coef(summary(imput))[2,2] coef(summary(naive))[2,2] - sqrt(198)/sqrt(18) * coef(summary(imputWrong))[2,2] Are you sure you are interpreting Wood et al. correctly ? (I haven't read it, this is not rhetorical) On Wed, May 23, 2012 at 7:49 PM, Steve Taylor steve.tay...@aut.ac.nz wrote: Re: coef(summary(glm(extra ~ group, data=sleep[ rep(1:nrow(sleep), 10L), ] ))) Your (corrected) suggestion is the same as one of mine, and doesn't do what I'm looking for. -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Tuesday, 22 May 2012 3:37p To: Steve Taylor Cc: r-help@r-project.org Subject: Re: [R] glm(weights) and standard errors On May 21, 2012, at 10:58 PM, Steve Taylor wrote: Is there a way to tell glm() that rows in the data represent a certain number of observations other than one? Perhaps even fractional values? Using the weights argument has no effect on the standard errors. Compare the following; is there a way to get the first and last models to produce the same results? data(sleep) coef(summary(glm(extra ~ group, data=sleep))) coef(summary(glm(extra ~ group, data=sleep, weights=rep(10L,nrow(sleep) Here's a reasonably simple way to do it: coef(summary(glm(extra ~ group, data=sleep[ rep(10L,nrow(sleep)), ] ))) -- David. sleep10 = sleep[rep(1:nrow(sleep),10),] coef(summary(glm(extra ~ group, data=sleep10
Re: [R] How to open a file with a name changed?
You probably want to use paste or paste0 instead of cat. paste0(cit,dia,extension) Also, this might work: tail(dir(C:/Bonos/,patt=csv$),1) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Minerva Mora Sent: Friday, 25 May 2012 11:45a To: r-help@r-project.org Subject: [R] How to open a file with a name changed? Hi, I apologize for my english. I´m trying to read a file, but the name of this file changes every day, for example: today is May 24, 2012 bonos- read.table(C:/Bonos/*20120524*.csv, header=TRUE, sep=\t) So, tomorrow I want to read the file again, but i don´t want to put the date by myself, i want this automatically. I know that if a put day() this instruccion gives me the date. My problem is, I don´t know how to concatenate these: -C:/Bonos/ -the date -.csv I tried this: bonos- read.table(cat(cit,dia,extension), header=TRUE, sep=\t) where --cit is *\C:/Bonos/* --dia is *dia-format(today, %Y%m%d)* --extension is *extension-.csv\* but i have this problem: C:/Bonos/ 20120524 .csv*Error in read.table(cat(cit, dia, extension), header = TRUE, sep = \t) : * * 'file' must be a character string or connection* What can i do? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/How-to-open-a-file-with-a-name-changed-tp4631261.html Sent from the R help mailing list archive at Nabble.com. __ 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-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] glm(weights) and standard errors
Re: coef(summary(glm(extra ~ group, data=sleep[ rep(1:nrow(sleep), 10L), ] ))) Your (corrected) suggestion is the same as one of mine, and doesn't do what I'm looking for. -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Tuesday, 22 May 2012 3:37p To: Steve Taylor Cc: r-help@r-project.org Subject: Re: [R] glm(weights) and standard errors On May 21, 2012, at 10:58 PM, Steve Taylor wrote: Is there a way to tell glm() that rows in the data represent a certain number of observations other than one? Perhaps even fractional values? Using the weights argument has no effect on the standard errors. Compare the following; is there a way to get the first and last models to produce the same results? data(sleep) coef(summary(glm(extra ~ group, data=sleep))) coef(summary(glm(extra ~ group, data=sleep, weights=rep(10L,nrow(sleep) Here's a reasonably simple way to do it: coef(summary(glm(extra ~ group, data=sleep[ rep(10L,nrow(sleep)), ] ))) -- David. sleep10 = sleep[rep(1:nrow(sleep),10),] coef(summary(glm(extra ~ group, data=sleep10))) coef(summary(glm(extra ~ group, data=sleep10, weights=rep(0.1,nrow(sleep10) My reason for asking is so that I can fit a model to a stacked multiple imputation data set, as suggested by: Wood, A. M., White, I. R. and Royston, P. (2008), How should variable selection be performed with multiply imputed data?. Statist. Med., 27: 3227-3246. doi: 10.1002/sim.3177 Other suggestions would be most welcome. __ 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] glm(weights) and standard errors
Is there a way to tell glm() that rows in the data represent a certain number of observations other than one? Perhaps even fractional values? Using the weights argument has no effect on the standard errors. Compare the following; is there a way to get the first and last models to produce the same results? data(sleep) coef(summary(glm(extra ~ group, data=sleep))) coef(summary(glm(extra ~ group, data=sleep, weights=rep(10L,nrow(sleep) sleep10 = sleep[rep(1:nrow(sleep),10),] coef(summary(glm(extra ~ group, data=sleep10))) coef(summary(glm(extra ~ group, data=sleep10, weights=rep(0.1,nrow(sleep10) My reason for asking is so that I can fit a model to a stacked multiple imputation data set, as suggested by: Wood, A. M., White, I. R. and Royston, P. (2008), How should variable selection be performed with multiply imputed data?. Statist. Med., 27: 3227-3246. doi: 10.1002/sim.3177 Other suggestions would be most welcome. ___ Steve Taylor Biostatistician Pacific Islands Families Study Faculty of Health and Environmental Sciences AUT University __ 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] Export a plot/figure to excel or word?
I have found the TIF format (with lossless compression) most suitable for inclusion in Word documents. Here's my function for producing a tif plot... word.tif - function(filename=Word_Figure.tif, zoom=5, res=96*zoom, width=17, height=10, pointsize=10, bg='white') { if (!filename %like% [.]ti[f]+$) filename = paste(filename,tif,sep='.') tiff(filename=filename, res=res, width=width, height=height, units='cm', pointsize=pointsize, bg=bg, compression=lzw) } # usage... word.tif('random normals', width=10, height=10) # centimetres plot(rnorm(100)) dev.off() -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Aurelie Cosandey Godin Sent: Thursday, 15 March 2012 8:50a To: r-help@r-project.org Subject: [R] Export a plot/figure to excel or word? Hi all, I have created forest plots using the package meta that I submitted as pdf for publication. I just received an email from the editor asking me if I could send these files in an Excel or MS Word format such that they can treat them as tables with box plots. I am not sure if I can do this... Is this possible? I've tried the capture.output command, but I get a blank MS Word document. Thank you very much in advance, Best, Aurelie Aurelie Cosandey-Godin Ph.D. student, Department of Biology Industrial Graduate Fellow, WWF-Canada Dalhousie University | Biology Dept. | 1459 Oxford Street |Halifax, NS | Canada B3H 4R2 Phone: 1-902-494-2146 | cell: 1-902-412-3404 |Fax: 1-902-494-3736 Email: god...@dal.ca | Skype: aureliegodinco | Web: wormlab.biology.dal.ca Want to learn more about sharks in Atlantic Canada? Visit ShARCC! www.atlanticsharks.org [[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-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] Export a plot/figure to excel or word?
Oops, this uses one of my own functions %like% %like% - function(x,y) grepl(y,x,ignore=TRUE) Here's an improved version of word.tif ... word.tif - function(filename=Word_Figure_%03d.tif, zoom=5, width=17, height=10, pointsize=10, ...) { if (!grepl([.]ti[f]+$, filename,ignore.case=TRUE) filename = paste(filename,tif,sep='.') tiff(filename=filename, res=96*zoom, width=width, height=height, units='cm', pointsize=pointsize, compression=lzw, ...) } Note the zoom, which creates high quality images by default. S -Original Message- From: Steve Taylor Sent: Thursday, 15 March 2012 9:01a To: 'Aurelie Cosandey Godin'; r-help@r-project.org Subject: RE: [R] Export a plot/figure to excel or word? I have found the TIF format (with lossless compression) most suitable for inclusion in Word documents. Here's my function for producing a tif plot... word.tif - function(filename=Word_Figure.tif, zoom=5, res=96*zoom, width=17, height=10, pointsize=10, bg='white') { if (!filename %like% [.]ti[f]+$) filename = paste(filename,tif,sep='.') tiff(filename=filename, res=res, width=width, height=height, units='cm', pointsize=pointsize, bg=bg, compression=lzw) } # usage... word.tif('random normals', width=10, height=10) # centimetres plot(rnorm(100)) dev.off() -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Aurelie Cosandey Godin Sent: Thursday, 15 March 2012 8:50a To: r-help@r-project.org Subject: [R] Export a plot/figure to excel or word? Hi all, I have created forest plots using the package meta that I submitted as pdf for publication. I just received an email from the editor asking me if I could send these files in an Excel or MS Word format such that they can treat them as tables with box plots. I am not sure if I can do this... Is this possible? I've tried the capture.output command, but I get a blank MS Word document. Thank you very much in advance, Best, Aurelie Aurelie Cosandey-Godin Ph.D. student, Department of Biology Industrial Graduate Fellow, WWF-Canada Dalhousie University | Biology Dept. | 1459 Oxford Street |Halifax, NS | Canada B3H 4R2 Phone: 1-902-494-2146 | cell: 1-902-412-3404 |Fax: 1-902-494-3736 Email: god...@dal.ca | Skype: aureliegodinco | Web: wormlab.biology.dal.ca Want to learn more about sharks in Atlantic Canada? Visit ShARCC! www.atlanticsharks.org [[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-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] Reading spss files into R - warnings
suppressWarnings() will get rid of them for you. Note that in R a factor cannot have duplicate levels. Compare the results with use.value.labels turned on or off, to see which you prefer. I also get the unknown type warnings, but I ignore them as my data seems to arrive into R intact. Hope that helps. cheers, Steve -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Marion Wenty Sent: Friday, 17 February 2012 1:00a To: r-help@r-project.org Subject: [R] Reading spss files into R - warnings Hello people, I have got a question concerning reading spss files into R: I used the package foreign and the following command: read.spss(C:/Eigene Dateien/myspssfile.sav,to.data.frame=T) I have read two different files into R (several times) and always got the following two warning messages: first file: Warnmeldungen:1: In `levels-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste(labels, : doppelt auftretende Faktorstufen werden nicht mehr zulässig sein2: In `levels-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste(labels, : doppelt auftretende Faktorstufen werden nicht mehr zulässig sein3: In `levels-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste(labels, : doppelt auftretende Faktorstufen werden nicht mehr zulässig sein4: In `levels-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste(labels, : doppelt auftretende Faktorstufen werden nicht mehr zulässig sein5: In `levels-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste(labels, : doppelt auftretende Faktorstufen werden nicht mehr zulässig sein second file: Warnmeldungen: 1: Unerkannter Datensatztyp 7, Untertyp 14 in Systemdatei vorgefunden2: Unerkannter Datensatztyp 7, Untertyp 18 in Systemdatei vorgefunden I couldn't find out how to get rid of these. Does anyone know how to do this? Thank you very much in advance, Marion [[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] Why does length() == 1?
is a character vector with one element in it. ?nchar ?length From: Worik R wor...@gmail.com To:r-help r-help@r-project.org Date: 11/Nov/2011 1:21p Subject: [R] Why does length() == 1? It seems obvious to me that the empty string is length 0. cheers Worik [[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. [[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] Urgent help needed for honours project - breaks between races in one year
This might help: if x is a vector of the race days then max(diff(sort(x))) finds the biggest gap between consecutive values. From: Jana.K borjana.kra...@gmail.com To:r-help@r-project.org Date: 7/Oct/2011 4:47a Subject: [R] Urgent help needed for honours project - breaks between races in one year Hi to anyone who is willing to help, I have a csv. file which has 1999 horses as the rows and the age(in years) of the horse at each race as columns. Ive read this file into R and called it 'horses'. Im trying to find the longest break between each race in the horse's first year of racing. I already have a numeric called 'age.first' which is the age at which each horse had its first race. I understand if i want to look at the breaks a year from the first race i have to add +1. But i am not sure how to write the code into R. Can anyone help me get the longest break in the first year of racing for each horse? Jana. -- View this message in context: http://r.789695.n4.nabble.com/Urgent-help-needed-for-honours-project-breaks-between-races-in-one-year-tp3878187p3878187.html Sent from the R help mailing list archive at Nabble.com. __ 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] Storing and managing custom R functions for re-use
My solution to the clutter problem is this: at start-up time, create a list of functions, attach the list and then delete the list. I haven't delved into making packages yet. if (any(search()==MyFunctions)) detach(MyFunctions) MyFunctions - list() MyFunctions$ %like% - function(x,y) { seq_along(x) %in% grep(y,x,ignore=TRUE) } MyFunctions$ trim - function(txt) { gsub(^ +| +$, , txt) } # You can also put data into the list: MyFunctions$ tau = 2 * pi # etc... attach(MyFunctions) rm(MyFunctions) All that is in MyFunctions.R which I can source() again when I update it. From: Abhijit Dasgupta, PhD aikidasgu...@gmail.com To:s.chamai...@yahoo.fr CC:r-help@r-project.org Date: 10/Jul/2011 1:40a Subject: Re: [R] Storing and managing custom R functions for re-use I think most of us are in a similar situation. I've usually kept mine in a file which is sourced when I start R. The main problem I have with this is that it clutters up my environment with a lot of stuff I don't need all the time. I'm in the process of creating a custom package which will be lazy-loaded. I believe a previous discussion of this topic suggested this as the preferred method. [[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] Export R dataframes to excel
You can copy it with the following function and then paste into Excel... copy = function (df, buffer.kb=256) { write.table(df, file=paste(clipboard-,buffer.kb,sep=), sep=\t, na='', quote=FALSE, row.names=FALSE) } From: maxsilva mmsil...@uc.cl To:r-help@r-project.org Date: 2/Mar/2011 8:50a Subject: [R] Export R dataframes to excel I'm trying to do this in several ways but havent had any result. Im asked to install python, or perl etc. Can anybody suggest a direct, easy and understandable way? Every help would be appreciated. Thx. -- View this message in context: http://r.789695.n4.nabble.com/Export-R-dataframes-to-excel-tp3330399p3330399.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] Change a value in a matrix randomly
A=matrix(0,nr=3,nc=4) A[sample(prod(dim(A)),1)]=1 From: Barroso, Judit judit.barr...@exchange.montana.edu To:r-help@r-project.org r-help@r-project.org Date: 10/Nov/2010 11:12a Subject: [R] Change a value in a matrix randomly I have a matrix of ceros, for example: 0 0 0 0 0 0 0 0 0 0 0 0 And I would like that one of these values turn into 1, for example if one condition is got, but not in a concrete position if not randomly. Could you indicate me the code to can get it? Thanks in advance, Judit Barroso [[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 ( 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] Trouble accessing cov function from stats library
Note that R is case sensitive, so cov and Cov are different. From: Barth B. Riley bbri...@chestnut.org To:r-help@r-project.org r-help@r-project.org Date: 12/Oct/2010 3:31a Subject: [R] Trouble accessing cov function from stats library Dear all I am trying to use the cov function in the stats library. I have no problem using this function from the console. However, in my R script I received a function not found message. Then I called stats::cov(...) and received an error message that the function was not exported. Then I tried stats:::cov (three colons) and received the error Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : object 'Cov' not found I am also importing the ltm library, though I'm not aware of a cov function in ltm that could be causing a conflict. Any suggestions? Thanks Barth PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. [[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 ( 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] Line Type Specification: lty=onoff but lty=offon?
You might have to use segments() to place the line segments precisely. ?segments From: Henrik Bengtsson h...@stat.berkeley.edu To:Peter Alspach peter.alsp...@plantandfood.co.nz CC:r-help r-help@r-project.org Date: 11/Oct/2010 1:23p Subject: Re: [R] Line Type Specification: lty=onoff but lty=offon? Thanks both, but unfortunately not. Here is a better illustration on what I want to achieve; xs - c(0,1,2,3); ys - c(-1,0,0,1); lty - c(FF11, 1FF1); plot(NA, xlim=c(0,3), ylim=c(-1,1)); lines(xs, ys, col=red, lwd=2, lty=lty[1]); lines(xs, -ys, col=blue, lwd=2, lty=lty[2]); except that I don't want those short 1:s pieces. Ideally I'd like to use: lty - c(FF00, 0FF0); and dashes of any lengths, e.g. lty - c(2200, 0220); /Henrik [[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] weird to me interaction between time() and %%, %/%
Yes it is a floating point problem. January 2005 is slightly less than 2005, although the gap is somewhat bigger than .Machine$double.eps time(junk) - 2005 # shows the gap is -2.2737e-13 for my machine Try something this: floor(time(junk) + 1e-10) â â â â â â â â â â â â â â â â â Steve Taylor Biostatistician Pacific Islands Families Study Faculty of Health and Environmental Sciences Auckland University of Technology â â â â â â â â â â â â â â â â â [[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] logos and goodies
Would this be suitable? http://en.wikipedia.org/wiki/File:Rlogo.png [[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] findInterval and data resolution
How about this: these = which(vec2 x1[1] | vec2 x1[2]) vec2[these] # Or using logical indexation directly: vec2[vec2 x1[1] | vec2 x1[2]] From: Bryan Hanson han...@depauw.edu To:R Help r-h...@stat.math.ethz.ch Date: 13/Jul/2010 9:28a Subject: [R] findInterval and data resolution Hello Wise Ones... I need a clever way around a problem with findInterval. Consider: vec1 - 1:10 vec2 - seq(1, 10, by = 0.1) x1 - c(2:3) a1 - findInterval(x1, vec1); a1 # example 1 a2 - findInterval(x1, vec2); a2 # example 2 In the problem I'm working on, vec* may be either integer or numeric, like vec1 and vec2. I need to remove one or more sections of this vector; for instance if I ask to remove values 2:3 I want to remove all values between 2 and 3 regardless of the resolution of the data (in my thinking, vec2 is more dense or has better resolution than vec1). So example 1 above works fine because the values 2 and 3 are the end points of a range that includes no values in-between (a1). But, in example 2 the answer is, correctly, also the end points, but now there are values in between these end points. Hence a2 doesn't include the indices of the values in-between the end points. I have looked at cut, but it doesn't quite behave the way I want since if I set x1 - c(2:4) I get more intervals than I really want and cleaning it up will be laborious. I think I can construct the full set of indices I want with a2[1]:a2[2] but is there a more clever way to do this? I'm thinking there might be a function out there that I am not aware of. TIA, Bryan * Bryan Hanson Acting Chair Professor of Chemistry Biochemistry DePauw University, Greencastle IN USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] do the standard R analysis functions handle spatial grid data?
Have a look at the Task View for spatial data... http://cran.ms.unimelb.edu.au/web/views/Spatial.html From: chris howden tall.chr...@yahoo.com.au To:r-help@r-project.org, r-sig-ecology-requ...@r-project.org Date: 13/Jul/2010 2:01p Subject: [R] do the standard R analysis functions handle spatial grid data? Hi everyone, I'm doing a resource function analysis with radio collared dingos and GIS info. The ecologist I'm working with wants to send me the data in a 'grid format'...straight out of ARCVIEW GIS. I want to model the data using a GLM and maybe a LOGISTIC model as well. And I was planning on using the glm and logistic functions in R. Now I'm pretty sure that these functions require the data to be in a 2-D spreadsheet format. And for me to call the responses and predictors as columns from a data.frame (or 2-D matrix) However I'm being told they can handle the data in a 'grid' format. So I'm pretty sure this would mean I would be calling the responses and predictors as 2-d matrices...and I don't think these functions can do that? Can anyone enlighten me? Am I right in thinking these function cannot handle data in a 3-D 'grid' format and require data to be entered as a 2-d data.frame or matrix? Are there other special functions out there that can handle this type of data, and I should be using these instead? Thanks for your help Chris Howden Founding Partner Tricky Solutions Tricky Solutions 4 Tricky Problems Evidence Based Strategic Development, IP development, Data Analysis, Modelling, and Training (mobile) 0410 689 945 (fax / office) (+618) 8952 7878 ch...@trickysolutions.com.au __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] how to efficiently compute set unique?
The original question was about a matrix, not a vector and this is much slower: x - sample(10, size=13584763, replace=T) dim(x) - c(13584763, 1) system.time(unique(x)) So the solution would be: unique(as.vector(x)) From: Duncan Murdoch murdoch.dun...@gmail.com To:G FANG fanggan...@gmail.com CC:r-help@r-project.org Date: 22/Jun/2010 1:20p Subject: Re: [R] how to efficiently compute set unique? On 21/06/2010 9:06 PM, G FANG wrote: Hi, I want to get the unique set from a large numeric k by 1 vector, k is in tens of millions when I used the matlab function unique, it takes less than 10 secs but when I tried to use the unique in R with similar CPU and memory, it is not done in minutes I am wondering, am I using the function in the right way? dim(cntxtn) [1] 135847631 uniqueCntxt = unique(cntxtn);# this is taking really long What type is cntxtn? If I do that sort of thing on a numeric vector, it's quite fast: x - sample(10, size=13584763, replace=T) system.time(unique(x)) user system elapsed 3.610.143.75 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] unexpected result from format(x, digits)
Is this a bug somewhere? The format function, using a specific number of digits, doesn't give sensible results: R set.seed(2);print(x-rexp(5)) [1] 1.86535 0.40475 0.14665 1.73071 0.08953 R format(x,digits=1) [1] 1.87 0.40 0.15 1.73 0.09 R format(x,digits=2) [1] 1.87 0.40 0.15 1.73 0.09 R format(x,digits=3) [1] 1.8654 0.4047 0.1467 1.7307 0.0895 [[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] unexpected result from format(x, digits)
0.08953 to two significant figures is 0.090 not 0.09. Thanks, I'll sprintf instead. From: Duncan Murdoch murdoch.dun...@gmail.com To:Steve Taylor steve.tay...@aut.ac.nz CC:r-help@r-project.org Date: 29/Apr/2010 9:53a Subject: Re: [R] unexpected result from format(x, digits) On 28/04/2010 5:45 PM, Steve Taylor wrote: Is this a bug somewhere? The format function, using a specific number of digits, doesn't give sensible results: I don't see the error. In all examples, the smallest value is 0.08953, and it appears to be rendered to the requested number of significant figures in each case. All the other numbers are rendered to match. If you want to specify decimal places rather than significant digits, you should probably use sprintf() rather than format(). Duncan Murdoch R set.seed(2);print(x-rexp(5)) [1] 1.86535 0.40475 0.14665 1.73071 0.08953 R format(x,digits=1) [1] 1.87 0.40 0.15 1.73 0.09 R format(x,digits=2) [1] 1.87 0.40 0.15 1.73 0.09 R format(x,digits=3) [1] 1.8654 0.4047 0.1467 1.7307 0.0895 [[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] unexpected result from format(x, digits)
Ted wrote: In the second, 0.08953 rounds (to 2 significant digits) to 0.090, which can be printed without further loss of precision as 0.09 while giving the other numbers 2 significant digits. I guess I'm disagreeing with the idea of dropping the trailing zero. It should be retained, since 2 significant figures was what was asked for. [[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] Tinn-R
Thanks Ben. Putting that code into my .Rprofile file helped; then it gets executed whenever R starts up. From: Ben Bolker bol...@ufl.edu To:r-h...@stat.math.ethz.ch Date: 20/Apr/2010 10:05a Subject: Re: [R] Tinn-R Robert Ruser robert.ruser at gmail.com writes: I want to use the free distribution of R (R REvolution 3.2) [this is a little bit funny -- is the standard (CRAN) distribution not free? Or did you mean something else?] and Tinn-R editor as well. Unfortunately they don't cooperate. In Tinn-R commands: send selection, send line etc. don't work. Do you have any idea how to resolve this problem? This is a known () Tinn-R bug, I think. I have found that pasting .trPaths - paste(paste(Sys.getenv('APPDATA'), '\\Tinn-R\\tmp\\', sep=''), c('', 'search.txt', 'objects.txt','file.r', 'selection.r','block.r','lines.r'), sep='') into Tinn-R makes it work (for that Tinn-R session). There are instructions somewhere (???) for adding this to your Tinn-R preferences so that it is executed every time ... good luck Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] can I rotate a matrix
How about this for a more generalised matrix rotation function (works with 1-column and 1-row matrices too) ... rotate = function(mat) t(mat[nrow(mat):1,,drop=FALSE]) From: seeliger.c...@epamail.epa.gov To:r-help@r-project.org Date: 19/Mar/2010 10:15a Subject: Re: [R] can I rotate a matrix Now that *is* neat! Thanks! Unfortunately, it doesn't generalize and it's rather baroque. What is wanted is to make a matrix with row 1 as the last column, row 2 as the second to last column, etc. In otherwords, t(z[r:1,]) works for z - matrix(c(1,2,1,3,2,6,4,5,3), ncol=3, byrow=TRUE) z - matrix(c(1,2,1,3,2,6,4,5), ncol=4, byrow=TRUE) cur [[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] Running script with double-click
You can create a right-mouse menu command to run an R program as follows (although the details may be different for different versions of Windows). In Windows Explorer: 1. Tools / Folder Options / File Types 2. find the extension for R files and push Advanced 3. add a new action called Run with command as follows: C:\Program Files\R\R-2.10.1\bin\Rterm.exe --quiet --no-save --no-restore -f %1 If/when you have a different version of R installed, you'll need to adjust the above command. Steve From: Matt Asher sta...@quo.org To:r-help@r-project.org Date: 5/Mar/2010 12:45p Subject: [R] Running script with double-click Hi, I need to be able to run an R script by double-clicking the file name in Windows. I've tried associating the .r extension with the different R .exe's in /bin but none seems to work. Some open R then close right away, and Rgui.exe gives the message ARGUMENT /my/file.r __ignored__ before opening a new, blank session. I've tried Google and looking in the R for Windows FAQ but didn't see anything. Thanks. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] First. Last. Data row selection
These tell you the first and last row for each plate: !duplicated(df$plate) !duplicated(df$plate, fromLast=TRUE) Hope that helps. Steve From: wookie1976 joe.roesc...@revecorp.com To:r-help@r-project.org Date: 24/Feb/2010 6:54 a.m. Subject: [R] First. Last. Data row selection I am in the process of switching from SAS over to R. I am working on very large CSV datasets that contain vehicle information. As I am processing the data, I need to select the first (or sometimes the second) record (by date) for any records that have the same license plate number. In SAS, there is a function called 'first.' that can be used on sorted datasets to pull out those first entries for each occurrence of a particular variable (in this case the variable is 'license plate') found in the data. I have spent some time looking around and cannot seem to find an equivalent function in R. Can anyone recommend an efficient technique that would pull this off? I assume the database must first be sorted by vehicle plate and date, and then apply the filter or function. Any help would be greatly appreciated. Thanks, Joe -- View this message in context: http://n4.nabble.com/First-Last-Data-row-selection-tp1566260p1566260.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] First. Last. Data row selection
Ah, those can be used to index the rows: # create a new column with TRUE for the first row of each Vin: ladata2$First - !duplicated(ladata2$Vin) # view only those rows: ladata2[ladata2$First,] From: wookie1976 joe.roesc...@revecorp.com To:r-help@r-project.org Date: 24/Feb/2010 2:53 p.m. Subject: Re: [R] First. Last. Data row selection Steve, Your example seems to work quite well, except I get a summary printout showing all the true and false values. !duplicated(ladata2$Vin) [1] TRUE TRUE TRUE TRUE What I would like to do is have the true/false values appended to a column at the end of my dataset so that when done, I can selectively either keep or drop rows based on whether they are true or false. I have tried to get this done with several variable creation statements with no luck. Any ideas on how I can modify your code to get the following: Plate, Date, True.False Plate1, 013110, true Plate 1, 010110, false Plate 1, 010109, false Plate 2, 020110, true To everyone else, thanks greatly for your examples! I have learned from each of your suggestions. -- View this message in context: http://n4.nabble.com/First-Last-Data-row-selection-tp1566260p1566801.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] Selective load of .First() function just for Rgui.exe
Here's another way to have different behaviour only for interactive sessions: if (interactive()) { winMenuAdd(menuname, NULL, NULL) # etc. } From: Duncan Murdoch murd...@stats.uwo.ca To:jgar...@ija.csic.es CC:r-help@r-project.org Date: 13/Feb/2010 6:15 a.m. Subject: Re: [R] Selective load of .First() function just for Rgui.exe On 12/02/2010 11:22 AM, jgar...@ija.csic.es wrote: Hi all, I have a .First - function() {...} in the Rprofile.site file. Through .First() I'm adding several menus to the GUI to access several functions I've been developing for own use. However, I also need to launch R scripts silently in a batch way, and in this case I get the error message: Error in winMenuAdd(menuname, NULL, NULL): Menu functions can only be used in the GUI Do you know about about a way to selectively read the .First() function just for Rgui.exe, but not for call to R.exe? The .Platform variable contains a list of things that identify the current platform. In Rterm (or R.exe) you'll have .Platform$GUI == RTerm, whereas in Rgui, it will be Rgui. Duncan Murdoch [[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] using step() with package geepack
Is anyone else using the 'geepack' package? From: Steve Taylor steve.tay...@aut.ac.nz To:r-help@r-project.org Date: 11/Feb/2010 11:28 a.m. Subject: [R] using step() with package geepack I'm using the package geepack to fit GEE models. Does anyone know of methods for add1 and drop1 for a 'geeglm' model object, or perhaps a method for extractAIC based on the QIC of Pan 2001? I see there has been some mention of this on R-help a few years ago (RSiteSearch(QIC)). The package does provide an anova method for its model objects, and update() seems to work: library(geepack) data(dietox) # the example from ?geeglm # GEE model, using gaussian instead of poisson: gee1 - geeglm(Weight~1, data=dietox, id=Pig, family=gaussian, corstr=ar1) gee2 - update(gee1, .~.+Time) anova(gee1, gee2) # gives a p-value for adding the Time variable step(gee2, direction=forward) # fails cheers, Steve [[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 ( 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] using step() with package geepack
I'm using the package geepack to fit GEE models. Does anyone know of methods for add1 and drop1 for a 'geeglm' model object, or perhaps a method for extractAIC based on the QIC of Pan 2001? I see there has been some mention of this on R-help a few years ago (RSiteSearch(QIC)). The package does provide an anova method for its model objects, and update() seems to work: library(geepack) data(dietox) # the example from ?geeglm # GEE model, using gaussian instead of poisson: gee1 - geeglm(Weight~1, data=dietox, id=Pig, family=gaussian, corstr=ar1) gee2 - update(gee1, .~.+Time) anova(gee1, gee2) # gives a p-value for adding the Time variable step(gee2, direction=forward) # fails cheers, Steve [[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] Polygons in Windows metafile
Hi all, I'm producing some pie charts (Yes I know!) and plotting them into a Windows metafile. This is for insertion into a Word document. The circles come out rather jagged when you zoom in on them, the cause of which I have perhaps narrowed down to the way polygon() works in the metafile device. The polygon coordinates seem to be quantised to the pixels, which is odd for a vector graphics format. Try this to see what I mean: win.metafile('test.emf') par(mfrow=c(2,2)) for(i in 1:4) pie(sample(5,4,repl=TRUE)) dev.off() Is there a way to get a better quality EMF file of this output? PDF output looks great, but Word doesn't seem to understand inserting a PDF graphics file. Word also did something strange with EPS output. cheers, Steve [[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] a question about deleting rows
yourdataframe = subset(yourdataframe, !(n2==0 n3==0 n4==0 n5==0)) From: karena dr.jz...@gmail.com To:r-help@r-project.org Date: 14/Jan/2010 12:24 p.m. Subject: [R] a question about deleting rows I have a file like this: idn1n2 n3 n4 n5 n6 1 3 47 8 102 2 4 12 4 3 10 3 7 00 0 0 8 4 1010 0 2 3 5 1110 0 0 5 what I want to do is: only if n2=0 and n3=0 and n4=0 and n5=0 then delete the row. how can I do that? thank you, karena -- View this message in context: http://n4.nabble.com/a-question-about-deleting-rows-tp1013403p1013403.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] Drop last numeral
Try this: substr(Data,1,nchar(Data)-1) Steve From: LCOG1 jr...@lcog.org To:r-help@r-project.org Date: 13/Jan/2010 9:15 a.m. Subject: [R] Drop last numeral Hello all, Frustrated and i know you can help I need to drop the last numeral of each of my values in my data set. So for the following i have tried the ?substring but since i have to specify the length, but because my data are of varying lengths it doenst work so well Data-c(1131, 1132, 1731 ,1732 ,1821 ,1822, 2221 ,, 2241 ,2242,414342 ,414371 ,414372) Bldgid-substring(as.character(Data),1,3) returns: 113 113 173 173 182 182 222 222 224 224 414 414 414 but i want 113, 113, 173 ,173 ,182 ,182, 222 ,222, 224 ,224,41434 ,41437 ,41437) The values thats have more than 4 numerals are whats messing things up. Tried ?formatC as well but couldn't get it to coerce things correctly. Thanks for the help JR -- View this message in context: http://n4.nabble.com/Drop-last-numeral-tp1012347p1012347.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R ( 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] how to import data from excel to R
Or copy a rectangle of data in Excel, then grab it from the clipboard in R as follows: my.data - read.table(clipboard,head=TRUE,sep='\t') cheers, Steve [[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.