[R] can R read a binary data block file (.DBL)?
Dear R users, I have been searching thru the documentation of R but did not find anything about reading or manipulating a binary data block file (.DBL).a link to one example https://echange-fichiers.inra.fr/get?k=5Hzw2B1wZDng9ztO34E -- View this message in context: http://r.789695.n4.nabble.com/can-R-read-a-binary-data-block-file-DBL-tp4652654.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] Getting the latex file from R CMD check
Hi list, I'm running R CMD check for a package and I would like to save the .tex file that generates later the pdf documentation. I have only seen it appearing and disappearing quickly in a tmp folder but I have not been able to save it. I could not find any option to the check command to save it. Any idea how I can save this tex file? Thanks Guillaume __ 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] Getting the latex file from R CMD check
On 12-12-10 7:08 AM, Guillaume Chapron wrote: Hi list, I'm running R CMD check for a package and I would like to save the .tex file that generates later the pdf documentation. I have only seen it appearing and disappearing quickly in a tmp folder but I have not been able to save it. I could not find any option to the check command to save it. Any idea how I can save this tex file? Thanks I don't know if check has an option to leave it behind, but you can create it using R CMD Rd2pdf --no-clean pkgname With the --no-clean option this will leave behind a temporary directory with all the intermediate files in it. Duncan Murdoch __ 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] Long equation in documentation
On 12-12-10 12:02 AM, Tyler Rinker wrote: I have a long equation that I need to break in the R documentation of a package or it trails off the right hand side of the page. Here's the formula: \deqn{Cov(r_{ist}, r_{iuv})= [.5\rho_{ist}\rho_{iuv}(\rho_{isu}^2 + \rho_{isv}^2 + \rho_{itu}^2 + \rho_{itv}^2) + \rho_{isu}\rho_{itv}+ \rho_{isv}\rho_{itu}-(\rho_{ist}\rho_{isu}\rho_{isv} + \rho_{its}\rho_{itu}\rho_{itv}) + \rho_{ius}\rho_{iut}\rho_{iuv} + \rho_{ivs}\rho_{ivt}\rho_{ivu}]/n_i} How can I break the formula and optionally indent the second lower piece; though I'd settle for break it right now? Tyler Rinker Note: Cross posted here after no viable answer on stackoverflow: http://stackoverflow.com/questions/13780190/break-long-formula-r-documentation I don't know if there's a simple answer to this, but you would likely receive more answers if you made the question easier to answer, by posting complete code that people could try, not just a fragment. Why not put together a minimal .Rd file and post that? Here are two things to try: Insert \cr where you want a break. Decide what you want to see in the three formats (HTML, Latex, text) and manually handle each of them separately. Duncan Murdoch __ 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] Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
Hi there I'm trying to fit a logistic regression model to data that looks very similar to the data in the sample below. I don't understand why I'm getting this error; none of the data are proportional and the weights are numeric values. Should I be concerned about the warning about non-integer successes in my binomial glm? If I should be, how do I go about addressing it? I'm pretty sure the weights in the data frame are sampling weights. What follows is the result of str() on my data, the series of commands I'm using to fit the model, the responses I'm getting and then some code to reproduce the data and go through the same steps with that code. One last (minor) question. When calling svyglm on the sample data, I actually get some information about the model fitting results as well as the error about non-integer successes. In my real data, you only get the warning. Calling summary(mod1) on the real data does return information about the coefficients and the model fitting. I'm grateful for any help. I'm aware that the topic of non-integer successes has been addressed before, but I could not find my answer to this question. Yours, Simon Kiss ##str() on original data str(mat1) 'data.frame': 1001 obs. of 5 variables: $ prov : Factor w/ 4 levels Ontario,PQ,..: 2 2 2 2 2 2 2 2 2 2 ... $ edu : Factor w/ 2 levels secondary,post-secondary: 2 2 2 1 1 2 2 2 1 1 ... $ gender: Factor w/ 2 levels Male,Female: 1 1 2 2 2 2 1 1 2 2 ... $ weight: num 1.145 1.436 0.954 0.765 0.776 ... $ trust : Factor w/ 2 levels no trust,trust: 2 1 1 1 1 2 1 2 1 2 ... ###Set up survey design des.1-svydesign(~0, weights=~weight, data=mat1) ###model and response to svyglm mod1-svyglm(trust ~ gender+edu+prov, design=des.1, family='binomial') Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! Model Summary summary(mod1) Call: svyglm(formula = trust ~ gender + edu + prov, design = des.1, family = binomial) Survey design: svydesign(~0, weights = ~weight, data = mat1) Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0.625909 0.156560 -3.998 6.87e-05 *** genderFemale 0.013519 0.140574 0.0960.923 edupost-secondary -0.011569 0.141528 -0.0820.935 provPQ-0.006614 0.172105 -0.0380.969 provatl0.335166 0.297860 1.1250.261 provwest -0.053862 0.174826 -0.3080.758 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1.002254) Number of Fisher Scoring iterations: 4 #Attempt To Reproduce The Problem Data mat.test-data.frame(edu=c(rep('secondary', 300), rep('post-secondary', 300)), prov=c(rep('ON', 200), rep('PQ', 200), rep('AB', 200)), trust=c(rep('trust',200), rep('notrust',400)), gender=c(rep('Male', 300), rep('Female', 300)), weight=rnorm(600, mean=1, sd=0.3)) ###Survey Design object test-svydesign(~0, weights=~weight, data=mat.test) #Call To svyglm svyglm(trust ~ edu+prov+gender, design=test, family='binomial') #Reults Independent Sampling design (with replacement) svydesign(~0, weights = ~weight, data = mat.test) Call: svyglm(formula = trust ~ edu + prov + gender, design = test, family = binomial) Coefficients: (Intercept) edusecondaryprovONprovPQgenderMale -2.658e+01-8.454e-04 5.317e+01-1.408e-02NA Degrees of Freedom: 599 Total (i.e. Null); 596 Residual Null Deviance: 759.6 Residual Deviance: 3.406e-09AIC: 8 Warning messages: 1: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! 2: glm.fit: algorithm did not converge * Simon J. Kiss, PhD Assistant Professor, Wilfrid Laurier University 73 George Street Brantford, Ontario, Canada N3T 2C9 __ 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] Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
Please unsubscribe me from this mailing list. Thank you Liz On Mon, Dec 10, 2012 at 8:40 AM, Simon Kiss sjk...@gmail.com wrote: R-help@r-project.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.
Re: [R] defmacro and bwplot incompatibilities?
Perfect, thanks very much. On 10/12/12 02:00, Jeff Newmiller wrote: bwplot is a trellis function. There is something very basic about the way that library works that any intro to trellis/lattice should tell you: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f --- 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. Geoffrey lordgeoff...@optusnet.com.au wrote: My macro doesn't work for bwplot. But is working elsewhere. What changes should i make to fix my macro. Thanks. The complete code sample is: library(gtools) library(lattice) pic - defmacro(fn, plotfunc, expr={png(filename=fn); plotfunc; dev.off()}) # this one fails. pic(bw.png, {bwplot(Species ~ Sepal.Length, data=iris)}) # this one works pic(p.png, {plot(iris$Sepal.Length)} __ 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] Marginal effects of ZINB models
Dear all, I am modeling the incidence of recreational anglers along a stretch of coastline, and with a vary large proportion of zeros (80%) have chosen to use a zero inflated negative binomial (ZINB) distribution. I am using the same variables for both parts of the model, can anyone help me with R code to compute overall marginal effects of each variable? My model is specified as follows: ZINB - zeroinfl(Tot.Anglers ~ Location + Season + Daytype + Holiday.not + CPUE + ShoreType + Access + Source.pop + WindSpeed + offset(beat_length), dist=negbin, data=anglers) Many thanks, Jeremy [[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] Count cell Count by her frequency
Hello togehter, i have a data.frame, with value like this: A B 1 10-1 aaa 2 10-1 bbb 3 10-1 abc 4 10-2 vvv 5 10-3 ggg I want now a evaluation, which character is how often in my data.frame. Like this one: A B 1 10-1 3 2 10-2 1 3 10-3 1 How can i do this? Thank you. Mat -- View this message in context: http://r.789695.n4.nabble.com/Count-cell-Count-by-her-frequency-tp4652650.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] Creating a geographical grid
I would like to create a geographical grid to have a sort of a reference grid for my georeferenced survey data. The grid should be in a xy format, wgs1984 with a 0.025 degree, alternatively 10km, resolution covering -14 to -24 S and 24 to -34 E (Zimbabwe). Additionally I need to be able to export it as a .dbf Hope someone can help an R- novice ! [[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] Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
On 10-12-2012, at 14:48, Elizabeth Fuller Bettini wrote: Please unsubscribe me from this mailing list. Thank you Liz You do that yourself. See the link at the very end of each message. Repeated here for your convenience: https://stat.ethz.ch/mailman/listinfo/r-help And don't hijack a thread for something completely unrelated to the original post. Berend On Mon, Dec 10, 2012 at 8:40 AM, Simon Kiss sjk...@gmail.com wrote: R-help@r-project.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.
[R] equivalent of group command of the egen function in Stata
Dear R listers, I am trying to create a new variable that uniquely identifies groups of observations in a dataset. So far I couldn't figure out how to do this in R. In Stata I would simply type: egen newvar = group(dim1, dim2, dim3) Please, find below a quick example to show what I am dealing with: I have a dataset with 4 variables: var - runif(50) ## a variable that I want to group dim1 - factor(rep(1:3, length.out= 50), labels = c(x,y,z) ) ## 3 variables that should form the groups dim2 - rep(1:2, length.out= 50) dim3 - rep(1:5, length.out= 50) data - data.frame(var, dim1, dim2, dim3) I am trying to build a fifth one (let's say: group_id) to uniquely identify groups of observations as defined by dim1, dim2 and dim3, i.e. 30 groups. can you please help me figuring out how to do it? thanks in advance, f. -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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] equivalent of group command of the egen function in Stata
Hi, On Mon, Dec 10, 2012 at 9:33 AM, Francesco Sarracino f.sarrac...@gmail.com wrote: Dear R listers, I am trying to create a new variable that uniquely identifies groups of observations in a dataset. So far I couldn't figure out how to do this in R. In Stata I would simply type: egen newvar = group(dim1, dim2, dim3) A rough equivalent is dat$group - with(dat, interaction(dim1, dim2, dim3)) The differences between this and the Stata command are that the result in R is a factor rather than numeric, and the default ordering is different. Best, Ista Please, find below a quick example to show what I am dealing with: I have a dataset with 4 variables: var - runif(50) ## a variable that I want to group dim1 - factor(rep(1:3, length.out= 50), labels = c(x,y,z) ) ## 3 variables that should form the groups dim2 - rep(1:2, length.out= 50) dim3 - rep(1:5, length.out= 50) data - data.frame(var, dim1, dim2, dim3) I am trying to build a fifth one (let's say: group_id) to uniquely identify groups of observations as defined by dim1, dim2 and dim3, i.e. 30 groups. can you please help me figuring out how to do it? thanks in advance, f. -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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] Marginal effects of ZINB models
On Mon, 10 Dec 2012, Jeremy Goss wrote: Dear all, I am modeling the incidence of recreational anglers along a stretch of coastline, and with a vary large proportion of zeros (80%) have chosen to use a zero inflated negative binomial (ZINB) distribution. I am using the same variables for both parts of the model, can anyone help me with R code to compute overall marginal effects of each variable? My model is specified as follows: ZINB - zeroinfl(Tot.Anglers ~ Location + Season + Daytype + Holiday.not + CPUE + ShoreType + Access + Source.pop + WindSpeed + offset(beat_length), dist=negbin, data=anglers) We haven't implemented any marginal effects for hurdle/zeroinfl because I rarely find these useful in practice. Also, you probably would need several marginal effects for the same variable because you might want to describe the effect on the zero-inflation, on the count component, and on the mixture of both. But with the building blocks provided by hurdle/zeroinfl you can compute many of the quantities that are potentially of interest by hand. For hurdle models, there is some discussion of this in the following posting: https://stat.ethz.ch/pipermail/r-help/2012-January/300949.html Best, Z Many thanks, Jeremy [[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] Sweep out control
Dear all, Assume that I have the following data structure: d - expand.grid(subj=1:5, time=1:3, treatment=LETTERS[1:3]) d$value - 10 ^ (as.numeric(d$treatment) + 1) + 10 * d$subj + d$time d$value2 - 10 + d$value where d$treatment == C stands for my control group. What I want to achieve now is to subtract the values corresponding to d$treatment == C from all values in order to get the difference between the treatments. If I do that by hand, it will look like: va - rep(d$value[d$treatment == C], 3) # don't need to rep because R would do the recycling for me anyways d$value - va va2 - rep(d$value2[d$treatment == C], 3) d$value2 - va2 This works because the data frame is sorted in the right way and all cases are present. Furthermore, it would be a bit elaborative if you want to that for more than a couple of columns and it is not very error prone nor scalable (what if somebody changes the order of the data frame before, or somebody assumes that the data frame is in a certain order afterwards? If I want to add some columns later, I have to add new lines. What if some cases are missing?) Thus, this approach is clearly not a good one, especially since I don't like solutions which depend on a certain order. So my questions: 1. Is there a ready made solution for that? 2. If not (what I assume), what would be an elegant way of solving this? Is the only way to sort the data? Not that I have any problem with sorting, but I would appreciate any solution which works w/o sorting, because I don't want to run into the risk of having issues downstream with people who assume a certain order in the data (which is of course anyways a no-go, but I assume that the time to find a solution w/o altering the order is shorter than the time it takes to educate these guys [not on the long run though, but this battle has to be fought later] ;) 3. This solution should be easily extendable to an arbitrary set of columns and should work with missing cases for the treatments like d - d[-c(2, 21)] Thanks for your input, I am looking forward to your suggestions. Kind Regards, Thorn Thaler Mathematician Applied Mathematics Nestec Ltd, Nestlé Research Center PO Box 44 CH-1000 Lausanne 26 Phone: +41 21 785 8220 Fax: +41 21 785 9486 __ 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] Count cell Count by her frequency
Hello, Try the following. dat - read.table(text = A B 1 10-1 aaa 2 10-1 bbb 3 10-1 abc 4 10-2 vvv 5 10-3 ggg , header = TRUE) tbl - table(dat$A) data.frame(tbl) Hope this helps, Rui Barradas Em 10-12-2012 08:50, Mat escreveu: Hello togehter, i have a data.frame, with value like this: A B 1 10-1 aaa 2 10-1 bbb 3 10-1 abc 4 10-2 vvv 5 10-3 ggg I want now a evaluation, which character is how often in my data.frame. Like this one: A B 1 10-1 3 2 10-2 1 3 10-3 1 How can i do this? Thank you. Mat -- View this message in context: http://r.789695.n4.nabble.com/Count-cell-Count-by-her-frequency-tp4652650.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] KMP String search
Hello, As a follow-up, I must say that I've implemented the KMP algorithm in C using the .Call interface, to search for a vector in another vector. What do you want to do? Can you describe your problem? Rui Barradas Em 08-12-2012 22:37, Rui Barradas escreveu: Hello, As far as I know, the answer is no, there isn't. Hope this helps, Rui Barradas Em 08-12-2012 17:44, email escreveu: Hi: Is there any Package in R which implements the KMP String search algorithm ? Thanks John [[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] Count cell Count by her frequency
You request is not completely clear. I am assuming you want to count the number of different characters in B for each category in A: A - c(10-1, 10-1, 10-1, 10-2, 10-3) B - c(aaa, bbb, abc, vvv, ggg) dta - data.frame(A, B) dta A B 1 10-1 aaa 2 10-1 bbb 3 10-1 abc 4 10-2 vvv 5 10-3 ggg a1 - tapply(dta$B, dta$A, paste0, collapse=) a2 - strsplit(a1, ) a3 - lapply(a2, unique) a4 - sapply(a3, length) dtanew - data.frame(A=names(a4), B=a4, row.names=1:length(a4)) dtanew A B 1 10-1 3 2 10-2 1 3 10-3 1 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Mat Sent: Monday, December 10, 2012 2:50 AM To: r-help@r-project.org Subject: [R] Count cell Count by her frequency Hello togehter, i have a data.frame, with value like this: A B 1 10-1 aaa 2 10-1 bbb 3 10-1 abc 4 10-2 vvv 5 10-3 ggg I want now a evaluation, which character is how often in my data.frame. Like this one: A B 1 10-1 3 2 10-2 1 3 10-3 1 How can i do this? Thank you. Mat -- View this message in context: http://r.789695.n4.nabble.com/Count-cell- Count-by-her-frequency-tp4652650.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] equivalent of group command of the egen function in Stata
Hi, Try this: #changed data to dat1 list1-split(dat1,list(dat1$dim1,dat1$dim2,dat1$dim3)) names(list1)-1:length(list1) res-do.call(rbind,lapply(list1,function(x) data.frame(x,group=names(list1)[match.call()[[2]][[3]]]))) row.names(res)-1:nrow(res) head(res) # var dim1 dim2 dim3 group #1 0.06896418 x 1 1 1 #2 0.44958942 x 1 1 1 #3 0.08163725 y 1 1 2 #4 0.21945238 y 1 1 2 #5 0.05695142 z 1 1 3 #6 0.36656387 x 2 1 4 A.K. - Original Message - From: Francesco Sarracino f.sarrac...@gmail.com To: r-help@r-project.org Cc: Sent: Monday, December 10, 2012 9:33 AM Subject: [R] equivalent of group command of the egen function in Stata Dear R listers, I am trying to create a new variable that uniquely identifies groups of observations in a dataset. So far I couldn't figure out how to do this in R. In Stata I would simply type: egen newvar = group(dim1, dim2, dim3) Please, find below a quick example to show what I am dealing with: I have a dataset with 4 variables: var - runif(50) ## a variable that I want to group dim1 - factor(rep(1:3, length.out= 50), labels = c(x,y,z) ) ## 3 variables that should form the groups dim2 - rep(1:2, length.out= 50) dim3 - rep(1:5, length.out= 50) data - data.frame(var, dim1, dim2, dim3) I am trying to build a fifth one (let's say: group_id) to uniquely identify groups of observations as defined by dim1, dim2 and dim3, i.e. 30 groups. can you please help me figuring out how to do it? thanks in advance, f. -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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] qplot error -
Dear friends, I'm on windows, R 2.15.1 - library(ggplot2) #compiled under 2.15.2 qplot(mpg, wt, data=mtcars, colour=cyl) # directly from the qplot help Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue Is that due to a .1 lack in R All the best Troels Ring __ 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] Class definition and contains: No definition was found for superclass
On 12/10/2012 07:01 AM, Johannes Graumann wrote: Hi, What goes wrong when the following error shows up: Error in reconcilePropertiesAndPrototype(name, slots, prototype, superClasses, : No definition was found for superclass “sequencesuperclass” in the specification of class “sequences” Has this something to do with recursive class inheritance? sequences contains sequencessuperclass contains rcfpdsuperclass ... Any hint is highly appreciated. Hi Joh -- If I say setClass(B, contains=A) I get Error in reconcilePropertiesAndPrototype(name, slots, prototype, superClasses, : no definition was found for superclass A in the specification of class B whereas if I first define class A everything is fine setClass(A) setClass(B, contains=A) In a package is it important to control the order classes are defined, e.g., by defining them in a file AllClasses.R or by using the Collate: field of the DESCRIPTION file. Hope that helps. Martin Sincerely, Joh __ 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. -- Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ 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] qplot error -
Hello, I couldn't reproduce your error. library(ggplot2) Warning message: package ‘ggplot2’ was built under R version 2.15.2 qplot(mpg, wt, data=mtcars, colour=cyl) # directly from the qplot help #(no error message and the graph shows up) sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Portuguese_Portugal.1252 LC_CTYPE=Portuguese_Portugal.1252 [3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Portugal.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.2.1 loaded via a namespace (and not attached): [1] colorspace_1.2-0 dichromat_1.2-4 digest_0.5.2 fortunes_1.5-0 [5] grid_2.15.1 gtable_0.1.1 labeling_0.1 MASS_7.3-22 [9] memoise_0.1 munsell_0.4 plyr_1.7.1 proto_0.3-9.2 [13] RColorBrewer_1.0-5 reshape2_1.2.1 scales_0.2.2 stringr_0.6.1 What do you mean by a .1 lack in R ? Rui Barradas Em 10-12-2012 16:27, Troels Ring escreveu: Dear friends, I'm on windows, R 2.15.1 - library(ggplot2) #compiled under 2.15.2 qplot(mpg, wt, data=mtcars, colour=cyl) # directly from the qplot help Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue Is that due to a .1 lack in R All the best Troels Ring __ 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] Count cell Count by her frequency
Thank you all, a few ideas worked perfectly for me. I take with(dat1,aggregate(B,by=list(A=A),length)) for my task. Have a nice day. Mat -- View this message in context: http://r.789695.n4.nabble.com/Count-cell-Count-by-her-frequency-tp4652650p4652678.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.
Re: [R] Count cell Count by her frequency
And another way: library(plyr) ddply(dta,A,summarise,B=length(B)) Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx From: David L Carlson dcarl...@tamu.edu To: 'Mat' matthias.we...@fnt.de; r-help@r-project.org Sent: Monday, December 10, 2012 7:43 AM Subject: Re: [R] Count cell Count by her frequency You request is not completely clear. I am assuming you want to count the number of different characters in B for each category in A: A - c(10-1, 10-1, 10-1, 10-2, 10-3) B - c(aaa, bbb, abc, vvv, ggg) dta - data.frame(A, B) dta A B 1 10-1 aaa 2 10-1 bbb 3 10-1 abc 4 10-2 vvv 5 10-3 ggg a1 - tapply(dta$B, dta$A, paste0, collapse=) a2 - strsplit(a1, ) a3 - lapply(a2, unique) a4 - sapply(a3, length) dtanew - data.frame(A=names(a4), B=a4, row.names=1:length(a4)) dtanew A B 1 10-1 3 2 10-2 1 3 10-3 1 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Mat Sent: Monday, December 10, 2012 2:50 AM To: r-help@r-project.org Subject: [R] Count cell Count by her frequency Hello togehter, i have a data.frame, with value like this: A B 1 10-1 aaa 2 10-1 bbb 3 10-1 abc 4 10-2 vvv 5 10-3 ggg I want now a evaluation, which character is how often in my data.frame. Like this one: A B 1 10-1 3 2 10-2 1 3 10-3 1 How can i do this? Thank you. Mat -- View this message in context: http://r.789695.n4.nabble.com/Count-cell- Count-by-her-frequency-tp4652650.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. [[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 compare each row in a matrix with each row in another matrix?
HI Jonathan, Tested your code from Nabble: Looks like your solution is the fastest, but: N - 1000 M - 5 P - 5000 set.seed(15) A - matrix(runif(N,1,1000),nrow=N,ncol=M) set.seed(425) B - matrix(runif(M,1,1000),nrow=P,ncol=M) library(matrixStats) Marius.5.0 - function(A,B) outer(rowMaxs(A),rowMins(B),'') #Jonathan's code system.time(z5.0 - Marius.5.0(A,B)) # user system elapsed # 0.280 0.040 0.321 Marius.4.0 - function(A, B) apply(B, 1, function(x) colSums(x=t(A))==ncol(A)) system.time(z4.0 - Marius.4.0(A,B)) # user system elapsed # 0.460 0.044 0.506 identical(z5.0,z4.0) #[1] TRUE # when I test it with the toy example: A-matrix(c(1:4,6,2),ncol=2,byrow=TRUE) B - matrix(1:10, ncol=2) # (5, 2) matrix Marius.5.0(A,B) # [,1] [,2] [,3] [,4] [,5] #[1,] FALSE FALSE TRUE TRUE TRUE #[2,] FALSE FALSE FALSE FALSE TRUE #[3,] FALSE FALSE FALSE FALSE FALSE Marius.4.0(A,B) # [,1] [,2] [,3] [,4] [,5] #[1,] TRUE TRUE TRUE TRUE TRUE #[2,] FALSE FALSE TRUE TRUE TRUE #[3,] FALSE FALSE FALSE FALSE FALSE identical(Marius.5.0(A,B),Marius.4.0(A,B)) #[1] FALSE A.K. - Original Message - From: Hofert Jan Marius marius.hof...@math.ethz.ch To: arun smartpink...@yahoo.com Cc: Thomas Stewart tgs.public.m...@gmail.com; mailman, r-help r-help@r-project.org Sent: Saturday, December 8, 2012 2:15 PM Subject: RE: [R] How to efficiently compare each row in a matrix with each row in another matrix? The idea is good, but you don't need to create a list of the rows of A first, apply does the job: Marius.4.0 - function(A, B) apply(B, 1, function(x) colSums(x=t(A))==ncol(A)) That was actually a bit faster than your version. This is the fastest version so far. I compared it with C code called via .C: C was 15% faster. Cheers, Marius From: arun [smartpink...@yahoo.com] Sent: Saturday, December 08, 2012 7:43 PM To: Hofert Jan Marius Cc: Thomas Stewart; mailman, r-help Subject: Re: [R] How to efficiently compare each row in a matrix with each row in another matrix? Hi, Just to add: N - 1000 M - 5 P - 5000 set.seed(15) A - matrix(runif(N,1,1000),nrow=N,ncol=M) set.seed(425) B - matrix(runif(M,1,1000),nrow=P,ncol=M) Marius.3.0-function(A,B){do.call(cbind,lapply(split(B,row(B)),function(x) colSums(x=t(A))==ncol(A)))} Marius.2.0 - function(A, B){ nA - nrow(A) nB - nrow(B) C - do.call(rbind, rep(list(B), nA)) = matrix(rep(A, each=nB), ncol=ncol(B)) matrix(rowSums(C) == ncol(A), nA, nB, byrow=TRUE) } system.time(z3.0-Marius.3.0(A,B)) # user system elapsed # 0.524 0.020 0.548 system.time(z2.0-Marius.2.0(A,B)) # user system elapsed # 0.968 0.216 1.189 system.time(z1-perhaps(A,B)) # user system elapsed # 1.264 0.204 1.473 attr(z3.0,dim)-dim(z2.0) identical(z3.0,z2.0) #[1] TRUE identical(z1,z3.0) #[1] TRUE A.K. - Original Message - From: Marius Hofert marius.hof...@math.ethz.ch To: R-help r-help@r-project.org Cc: Sent: Saturday, December 8, 2012 6:28 AM Subject: [R] How to efficiently compare each row in a matrix with each row in another matrix? Dear expeRts, I have two matrices A and B. They have the same number of columns but possibly different number of rows. I would like to compare each row of A with each row of B and check whether all entries in a row of A are less than or equal to all entries in a row of B. Here is a minimal working example: A - rbind(matrix(1:4, ncol=2, byrow=TRUE), c(6, 2)) # (3, 2) matrix B - matrix(1:10, ncol=2) # (5, 2) matrix ( ind - apply(B, 1, function(b) apply(A, 1, function(a) all(a = b))) ) # (3, 5) = (nrow(A), nrow(B)) matrix The question is: How can this be implemented more efficiently in R, that is, in a faster way? Thanks cheers, Marius __ 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] equivalent of group command of the egen function in Stata
Hi, May be this also helps: dat2-within(dat1,{group-as.numeric(factor(paste0(dim1,dim2,dim3)))}) head(dat2) # var dim1 dim2 dim3 group #1 0.5366483 x 1 1 1 #2 0.3081562 y 2 2 17 #3 0.1493687 z 1 3 23 #4 0.3202687 x 2 4 9 #5 0.1177976 y 1 5 15 #6 0.7709756 z 2 1 26 A.K. - Original Message - From: Francesco Sarracino f.sarrac...@gmail.com To: r-help@r-project.org Cc: Sent: Monday, December 10, 2012 9:33 AM Subject: [R] equivalent of group command of the egen function in Stata Dear R listers, I am trying to create a new variable that uniquely identifies groups of observations in a dataset. So far I couldn't figure out how to do this in R. In Stata I would simply type: egen newvar = group(dim1, dim2, dim3) Please, find below a quick example to show what I am dealing with: I have a dataset with 4 variables: var - runif(50) ## a variable that I want to group dim1 - factor(rep(1:3, length.out= 50), labels = c(x,y,z) ) ## 3 variables that should form the groups dim2 - rep(1:2, length.out= 50) dim3 - rep(1:5, length.out= 50) data - data.frame(var, dim1, dim2, dim3) I am trying to build a fifth one (let's say: group_id) to uniquely identify groups of observations as defined by dim1, dim2 and dim3, i.e. 30 groups. can you please help me figuring out how to do it? thanks in advance, f. -- Francesco Sarracino, Ph.D. https://sites.google.com/site/fsarracino/ [[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] Count cell Count by her frequency
And a third way to interpret the question! Rui count rows per category in - A = 3 rows, 1 row, 1 row David count different letters used in B per category in A 3 (a,b,c), 1 (v), 1 (g) Felipe - count different strings in B per category - 3 (aaa, bbb, abc), 1 (vvv), 1 (ggg) Interesting that the sample data provide the same answer to all three questions, but Felipe's interpretation makes more sense than mine. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 From: Felipe Carrillo [mailto:mazatlanmex...@yahoo.com] Sent: Monday, December 10, 2012 10:05 AM To: dcarl...@tamu.edu; 'Mat'; r-help@r-project.org Subject: Re: [R] Count cell Count by her frequency And another way: library(plyr) ddply(dta,A,summarise,B=length(B)) Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx From: David L Carlson dcarl...@tamu.edu To: 'Mat' matthias.we...@fnt.de; r-help@r-project.org Sent: Monday, December 10, 2012 7:43 AM Subject: Re: [R] Count cell Count by her frequency You request is not completely clear. I am assuming you want to count the number of different characters in B for each category in A: A - c(10-1, 10-1, 10-1, 10-2, 10-3) B - c(aaa, bbb, abc, vvv, ggg) dta - data.frame(A, B) dta A B 1 10-1 aaa 2 10-1 bbb 3 10-1 abc 4 10-2 vvv 5 10-3 ggg a1 - tapply(dta$B, dta$A, paste0, collapse=) a2 - strsplit(a1, ) a3 - lapply(a2, unique) a4 - sapply(a3, length) dtanew - data.frame(A=names(a4), B=a4, row.names=1:length(a4)) dtanew A B 1 10-1 3 2 10-2 1 3 10-3 1 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Mat Sent: Monday, December 10, 2012 2:50 AM To: r-help@r-project.org Subject: [R] Count cell Count by her frequency Hello togehter, i have a data.frame, with value like this: A B 1 10-1 aaa 2 10-1 bbb 3 10-1 abc 4 10-2 vvv 5 10-3 ggg I want now a evaluation, which character is how often in my data.frame. Like this one: A B 1 10-1 3 2 10-2 1 3 10-3 1 How can i do this? Thank you. Mat -- View this message in context: http://r.789695.n4.nabble.com/Count-cell- Count-by-her-frequency-tp4652650.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. __ 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] qplot error -
Thanks a lot - here is win 64 bits too library(ggplot2) pakke ‘ggplot2’ blev bygget under R version 2.15.2 qplot(mpg, wt, data=mtcars) Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.3 - well I thought it was due to ggplot being compiled in 2.15.2 while I was running 2.15.1 - but so did you? Best wishes Troels Den 10-12-2012 19:12, Rui Barradas skrev: Hello, I couldn't reproduce your error. library(ggplot2) Warning message: package ‘ggplot2’ was built under R version 2.15.2 qplot(mpg, wt, data=mtcars, colour=cyl) # directly from the qplot help #(no error message and the graph shows up) sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Portuguese_Portugal.1252 LC_CTYPE=Portuguese_Portugal.1252 [3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Portugal.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.2.1 loaded via a namespace (and not attached): [1] colorspace_1.2-0 dichromat_1.2-4 digest_0.5.2 fortunes_1.5-0 [5] grid_2.15.1 gtable_0.1.1 labeling_0.1 MASS_7.3-22 [9] memoise_0.1 munsell_0.4 plyr_1.7.1 proto_0.3-9.2 [13] RColorBrewer_1.0-5 reshape2_1.2.1 scales_0.2.2 stringr_0.6.1 What do you mean by a .1 lack in R ? Rui Barradas Em 10-12-2012 16:27, Troels Ring escreveu: Dear friends, I'm on windows, R 2.15.1 - library(ggplot2) #compiled under 2.15.2 qplot(mpg, wt, data=mtcars, colour=cyl) # directly from the qplot help Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue Is that due to a .1 lack in R All the best Troels Ring __ 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] qplot error -
Please ask the ggplot2 maintainer: this looks like ggplot2 depends on some other package/version that you have not updated yet and ggplot2 does not declare it correctly. So you should 1. update R 2. run update.packages() 3. report to the ggplot2 maintainer about your findings and the probably improperly declared version dependencies. Best, Uwe Ligges On 10.12.2012 19:31, Troels Ring wrote: Thanks a lot - here is win 64 bits too library(ggplot2) pakke ‘ggplot2’ blev bygget under R version 2.15.2 qplot(mpg, wt, data=mtcars) Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.3 - well I thought it was due to ggplot being compiled in 2.15.2 while I was running 2.15.1 - but so did you? Best wishes Troels Den 10-12-2012 19:12, Rui Barradas skrev: Hello, I couldn't reproduce your error. library(ggplot2) Warning message: package ‘ggplot2’ was built under R version 2.15.2 qplot(mpg, wt, data=mtcars, colour=cyl) # directly from the qplot help #(no error message and the graph shows up) sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Portuguese_Portugal.1252 LC_CTYPE=Portuguese_Portugal.1252 [3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Portugal.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.2.1 loaded via a namespace (and not attached): [1] colorspace_1.2-0 dichromat_1.2-4 digest_0.5.2 fortunes_1.5-0 [5] grid_2.15.1 gtable_0.1.1 labeling_0.1 MASS_7.3-22 [9] memoise_0.1 munsell_0.4 plyr_1.7.1 proto_0.3-9.2 [13] RColorBrewer_1.0-5 reshape2_1.2.1 scales_0.2.2 stringr_0.6.1 What do you mean by a .1 lack in R ? Rui Barradas Em 10-12-2012 16:27, Troels Ring escreveu: Dear friends, I'm on windows, R 2.15.1 - library(ggplot2) #compiled under 2.15.2 qplot(mpg, wt, data=mtcars, colour=cyl) # directly from the qplot help Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue Is that due to a .1 lack in R All the best Troels Ring __ 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. __ 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] qplot error -
Make sure you have version 1.8 of plyr installed. With 2.15.1 using update.packages(plyr) does not seem to update from 1.7 to 1.8 (which contains the revalue function). Using install.packages(plyr) should get the current version. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Troels Ring Sent: Monday, December 10, 2012 12:31 PM To: r-help@r-project.org Subject: Re: [R] qplot error - Thanks a lot - here is win 64 bits too library(ggplot2) pakke 'ggplot2' blev bygget under R version 2.15.2 qplot(mpg, wt, data=mtcars) Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.3 - well I thought it was due to ggplot being compiled in 2.15.2 while I was running 2.15.1 - but so did you? Best wishes Troels Den 10-12-2012 19:12, Rui Barradas skrev: Hello, I couldn't reproduce your error. library(ggplot2) Warning message: package 'ggplot2' was built under R version 2.15.2 qplot(mpg, wt, data=mtcars, colour=cyl) # directly from the qplot help #(no error message and the graph shows up) sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Portuguese_Portugal.1252 LC_CTYPE=Portuguese_Portugal.1252 [3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Portugal.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.2.1 loaded via a namespace (and not attached): [1] colorspace_1.2-0 dichromat_1.2-4 digest_0.5.2 fortunes_1.5-0 [5] grid_2.15.1 gtable_0.1.1 labeling_0.1 MASS_7.3-22 [9] memoise_0.1 munsell_0.4 plyr_1.7.1 proto_0.3-9.2 [13] RColorBrewer_1.0-5 reshape2_1.2.1 scales_0.2.2 stringr_0.6.1 What do you mean by a .1 lack in R ? Rui Barradas Em 10-12-2012 16:27, Troels Ring escreveu: Dear friends, I'm on windows, R 2.15.1 - library(ggplot2) #compiled under 2.15.2 qplot(mpg, wt, data=mtcars, colour=cyl) # directly from the qplot help Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue Is that due to a .1 lack in R All the best Troels Ring __ 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. __ 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 POSIXct behaviour
I thought I had solved this problem. But I am still having trouble converting times. I am looking for a way to print out the string versions of times in different time zones. Same time, different zones. I have times stored as seconds since epoch and as text strings in local time. For instance (from an input file): Sat Nov 3 20:25:18 20121351927518 The local time zone is NZDT Browse[3] as.POSIXct(1351927518, origin=1970-01-01, tz=NZDT) [1] 2012-11-03 07:25:18 GMT Damn, that is GMT. But remembering the helpful replies to similar queries Browse[3] Sys.getenv(TZ) [1] GMT So I change the environment variable TZ and ... Browse[3] Sys.setenv(TZ=NZDT) Browse[3] as.POSIXct(1351927518, origin=1970-01-01, tz=NZDT) [1] 2012-11-03 07:25:18 NZDT The labled time zone is set OK but the time is wrong. The date string was generated in Perl as... DB7 p scalar(localtime(1351927518)) Sat Nov 3 20:25:18 2012 Using gmtime in Perl... DB8 p scalar(gmtime(1351927518)) Sat Nov 3 07:25:18 2012 cheers Worik On Fri, Mar 30, 2012 at 3:10 PM, Worik R wor...@gmail.com wrote: On Fri, Mar 30, 2012 at 2:53 PM, Joshua Ulrich josh.m.ulr...@gmail.comwrote: On Thu, Mar 29, 2012 at 3:56 PM, Worik R wor...@gmail.com wrote: I removed the (not so minimal) reproducible example because you can get the same behavior via: (s - Sys.time()) [1] 2012-03-29 20:43:35 CDT as.POSIXct(as.numeric(s),origin=1970-01-01) [1] 2012-03-30 02:43:35 CDT sapply() attempts to simplify to an array. Arrays can only contain an atomic type. POSIXct is not an atomic type, so it gets converted to numeric. The way to get around this is to explicitly set the timezone in your R session (see ?timezone). I can do this on my Ubuntu machine via: Sys.setenv(TZ=GMT) Now if I run the code above again, there is no difference after converting from POSIXct - numeric - POSIXct: (s - Sys.time()) [1] 2012-03-30 01:45:36 GMT as.POSIXct(as.numeric(s),origin=1970-01-01) [1] 2012-03-30 01:45:36 GMT HTH, Bingo! Thaks heaps. I have been working on this and had got as far as realising it was the conversion to numeric. I was trying to set the time zone in the as.POSIXct call but to no avail. But this looks good. cheers W -- Joshua Ulrich | FOSS Trading: www.fosstrading.com R/Finance 2012: Applied Finance with R www.RinFinance.com [[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] the value of the last expression
* Richard M. Heiberger e...@grzcyr.rqh [2012-02-09 21:48:50 -0500]: .Last.value Thanks; it worked for a while, but not anymore: http://stat.ethz.ch/R-manual/R-patched/library/base/html/Last.value.html --8---cut here---start-8--- gamma(1:15) [1] 1 1 2 6 24 120 [7] 7205040 40320 362880 362880039916800 [13] 479001600 6227020800 87178291200 z - .Last.value z NULL --8---cut here---end---8--- could my .Rprofile be at fault? --8---cut here---start-8--- ## breaks ess ## options(error = utils::recover) options(max.print = 100, repos = c(CRAN = http://lib.stat.cmu.edu/R/CRAN/;)) library(compiler) compiler::enableJIT(3) compiler::compilePKGS(1) --8---cut here---end---8--- On Thu, Feb 9, 2012 at 9:44 PM, Sam Steingold s...@gnu.org wrote: Is there an analogue of common lisp * variable which contains the value of the last expression? E.g., in lisp: (+ 1 2) 3 * 3 I wish I could recover the value of the last expression without re-evaluating it. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://mideasttruth.com http://thereligionofpeace.com http://www.memritv.org http://iris.org.il http://americancensorship.org Diplomacy is the art of saying nice doggy until you can find a nice rock. __ 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] sum portions of a vector
How do I sum portions of a vector into another vector? E.g., for --8---cut here---start-8--- vec - 1:10 breaks - c(3,8,10) --8---cut here---end---8--- I want to get a vector of length 3 with content --8---cut here---start-8--- 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 --8---cut here---end---8--- Obviously, I could write a loop, but I would rather have a vectorized version. Thanks! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://palestinefacts.org http://ffii.org http://jihadwatch.org http://www.PetitionOnline.com/tap12009/ One can find Holy Grail or Higgs boson, but not the second sock. __ 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] the value of the last expression
* arun fznegcvax...@lnubb.pbz [2012-12-10 11:22:03 -0800]: It is working for me. I do not claim to have found a bug. I am merely pleading for help figuring out what could have gone wrong. .Last.value word when I first start R under Emacs/ESS. Then it stops working. I can't figure out when or why... --8---cut here---start-8--- sessionInfo() R version 2.15.2 (2012-10-26) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets compiler methods [8] base loaded via a namespace (and not attached): [1] tools_2.15.2 --8---cut here---end---8--- sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] matrixStats_0.6.2 stringr_0.6 reshape_0.8.4 plyr_1.7.1 loaded via a namespace (and not attached): [1] R.methodsS3_1.4.2 tools_2.15.0 A.K. - Original Message - From: Sam Steingold s...@gnu.org To: r-help@r-project.org; Richard M. Heiberger r...@temple.edu Cc: Sent: Monday, December 10, 2012 2:13 PM Subject: Re: [R] the value of the last expression * Richard M. Heiberger e...@grzcyr.rqh [2012-02-09 21:48:50 -0500]: .Last.value Thanks; it worked for a while, but not anymore: http://stat.ethz.ch/R-manual/R-patched/library/base/html/Last.value.html gamma(1:15) [1] 1 1 2 6 24 120 [7] 720 5040 40320 362880 3628800 39916800 [13] 479001600 6227020800 87178291200 z - .Last.value z NULL could my .Rprofile be at fault? ## breaks ess ## options(error = utils::recover) options(max.print = 100, repos = c(CRAN = http://lib.stat.cmu.edu/R/CRAN/;)) library(compiler) compiler::enableJIT(3) compiler::compilePKGS(1) On Thu, Feb 9, 2012 at 9:44 PM, Sam Steingold s...@gnu.org wrote: Is there an analogue of common lisp * variable which contains the value of the last expression? E.g., in lisp: (+ 1 2) 3 * 3 I wish I could recover the value of the last expression without re-evaluating it. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://americancensorship.org http://pmw.org.il http://www.memritv.org http://iris.org.il http://jihadwatch.org http://ffii.org If it has syntax, it isn't user friendly. __ 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] the value of the last expression
On Mon, Dec 10, 2012 at 7:13 PM, Sam Steingold s...@gnu.org wrote: * Richard M. Heiberger e...@grzcyr.rqh [2012-02-09 21:48:50 -0500]: .Last.value Thanks; it worked for a while, but not anymore: http://stat.ethz.ch/R-manual/R-patched/library/base/html/Last.value.html --8---cut here---start-8--- gamma(1:15) [1] 1 1 2 6 24 120 [7] 7205040 40320 362880 362880039916800 [13] 479001600 6227020800 87178291200 z - .Last.value z NULL --8---cut here---end---8--- That's certainly odd I don't see anything in your .Rprofile which raises red flags, but you can confirm by running R --vanilla which will ignore all environment settings, .*(rc|profile), saved sessions etc. I presume you've tested in a fresh session and seen this behavior consistently? If so, could you provide your sessionInfo() and source of the binary you're using. could my .Rprofile be at fault? --8---cut here---start-8--- ## breaks ess ## options(error = utils::recover) options(max.print = 100, repos = c(CRAN = http://lib.stat.cmu.edu/R/CRAN/;)) library(compiler) compiler::enableJIT(3) compiler::compilePKGS(1) --8---cut here---end---8--- __ 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] Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
On Dec 10, 2012, at 5:40 AM, Simon Kiss wrote: Hi there I'm trying to fit a logistic regression model to data that looks very similar to the data in the sample below. I don't understand why I'm getting this error; none of the data are proportional and the weights are numeric values. Should I be concerned about the warning about non-integer successes in my binomial glm? If I should be, how do I go about addressing it? I'm pretty sure the weights in the data frame are sampling weights. What follows is the result of str() on my data, the series of commands I'm using to fit the model, the responses I'm getting and then some code to reproduce the data and go through the same steps with that code. One last (minor) question. When calling svyglm on the sample data, I actually get some information about the model fitting results as well as the error about non-integer successes. In my real data, you only get the warning. Calling summary(mod1) on the real data does return information about the coefficients and the model fitting. I'm grateful for any help. I'm aware that the topic of non-integer successes has been addressed before, but I could not find my answer to this question. Yours, Simon Kiss ##str() on original data str(mat1) 'data.frame': 1001 obs. of 5 variables: $ prov : Factor w/ 4 levels Ontario,PQ,..: 2 2 2 2 2 2 2 2 2 2 ... $ edu : Factor w/ 2 levels secondary,post-secondary: 2 2 2 1 1 2 2 2 1 1 ... $ gender: Factor w/ 2 levels Male,Female: 1 1 2 2 2 2 1 1 2 2 ... $ weight: num 1.145 1.436 0.954 0.765 0.776 ... $ trust : Factor w/ 2 levels no trust,trust: 2 1 1 1 1 2 1 2 1 2 ... ###Set up survey design des.1-svydesign(~0, weights=~weight, data=mat1) ###model and response to svyglm mod1-svyglm(trust ~ gender+edu+prov, design=des.1, family='binomial'). Warning message: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! I also got: 2: glm.fit: algorithm did not converge And the gender coefficient was NA. Your problem is not reproducible because no seed was set. Does this suggest any issues? with(mat.test, table(trust, gender) ) gender trust Female Male notrust300 100 trust0 200 -- David. Model Summary summary(mod1) Call: svyglm(formula = trust ~ gender + edu + prov, design = des.1, family = binomial) Survey design: svydesign(~0, weights = ~weight, data = mat1) Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0.625909 0.156560 -3.998 6.87e-05 *** genderFemale 0.013519 0.140574 0.0960.923 edupost-secondary -0.011569 0.141528 -0.0820.935 provPQ-0.006614 0.172105 -0.0380.969 provatl0.335166 0.297860 1.1250.261 provwest -0.053862 0.174826 -0.3080.758 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1.002254) Number of Fisher Scoring iterations: 4 #Attempt To Reproduce The Problem Data mat.test-data.frame(edu=c(rep('secondary', 300), rep('post- secondary', 300)), prov=c(rep('ON', 200), rep('PQ', 200), rep('AB', 200)), trust=c(rep('trust',200), rep('notrust',400)), gender=c(rep('Male', 300), rep('Female', 300)), weight=rnorm(600, mean=1, sd=0.3)) ###Survey Design object test-svydesign(~0, weights=~weight, data=mat.test) #Call To svyglm svyglm(trust ~ edu+prov+gender, design=test, family='binomial') #Reults Independent Sampling design (with replacement) svydesign(~0, weights = ~weight, data = mat.test) Call: svyglm(formula = trust ~ edu + prov + gender, design = test, family = binomial) Coefficients: (Intercept) edusecondaryprovONprovPQgenderMale -2.658e+01-8.454e-04 5.317e+01-1.408e-02NA Degrees of Freedom: 599 Total (i.e. Null); 596 Residual Null Deviance: 759.6 Residual Deviance: 3.406e-09AIC: 8 Warning messages: 1: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm! 2: glm.fit: algorithm did not converge -- David Winsemius, MD Alameda, CA, 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-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] the value of the last expression
On 10/12/2012 2:37 PM, Sam Steingold wrote: * arun fznegcvax...@lnubb.pbz [2012-12-10 11:22:03 -0800]: It is working for me. I do not claim to have found a bug. I am merely pleading for help figuring out what could have gone wrong. .Last.value word when I first start R under Emacs/ESS. Then it stops working. I can't figure out when or why... Use the usual debugging strategy: simplify things. Do you see the problem when you're running plain R, with no ESS? Do you see the problem when you run R with the --vanilla option? Do you have a script that reliably causes the failure? Simplify it to a minimal script that causes the failure. If you don't have a reproducible script yet to cause the error, then work on creating one. (The next time you see it, save the entire history of the session, and see if re-running that history in a new session will reproduce the error.) Duncan Murdoch --8---cut here---start-8--- sessionInfo() R version 2.15.2 (2012-10-26) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets compiler methods [8] base loaded via a namespace (and not attached): [1] tools_2.15.2 --8---cut here---end---8--- sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] matrixStats_0.6.2 stringr_0.6 reshape_0.8.4 plyr_1.7.1 loaded via a namespace (and not attached): [1] R.methodsS3_1.4.2 tools_2.15.0 A.K. - Original Message - From: Sam Steingold s...@gnu.org To: r-help@r-project.org; Richard M. Heiberger r...@temple.edu Cc: Sent: Monday, December 10, 2012 2:13 PM Subject: Re: [R] the value of the last expression * Richard M. Heiberger e...@grzcyr.rqh [2012-02-09 21:48:50 -0500]: .Last.value Thanks; it worked for a while, but not anymore: http://stat.ethz.ch/R-manual/R-patched/library/base/html/Last.value.html gamma(1:15) [1] 1 1 2 6 24 120 [7] 7205040 40320 362880 362880039916800 [13] 479001600 6227020800 87178291200 z - .Last.value z NULL could my .Rprofile be at fault? ## breaks ess ## options(error = utils::recover) options(max.print = 100, repos = c(CRAN = http://lib.stat.cmu.edu/R/CRAN/;)) library(compiler) compiler::enableJIT(3) compiler::compilePKGS(1) On Thu, Feb 9, 2012 at 9:44 PM, Sam Steingold s...@gnu.org wrote: Is there an analogue of common lisp * variable which contains the value of the last expression? E.g., in lisp: (+ 1 2) 3 * 3 I wish I could recover the value of the last expression without re-evaluating 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] Sweep out control
Hi, Not sure if this helps you: res-do.call(rbind,lapply(split(d,d$treatment),function(x) {x$diff1-x[,4]-(d[,4][d$treatment==C]); x$diff2-x[,5]-(d[,5][d$treatment==C]); return(x)})) A.K. - Original Message - From: Thaler,Thorn,LAUSANNE,Applied Mathematics thorn.tha...@rdls.nestle.com To: R help r-help@r-project.org Cc: Sent: Monday, December 10, 2012 10:29 AM Subject: [R] Sweep out control Dear all, Assume that I have the following data structure: d - expand.grid(subj=1:5, time=1:3, treatment=LETTERS[1:3]) d$value - 10 ^ (as.numeric(d$treatment) + 1) + 10 * d$subj + d$time d$value2 - 10 + d$value where d$treatment == C stands for my control group. What I want to achieve now is to subtract the values corresponding to d$treatment == C from all values in order to get the difference between the treatments. If I do that by hand, it will look like: va - rep(d$value[d$treatment == C], 3) # don't need to rep because R would do the recycling for me anyways d$value - va va2 - rep(d$value2[d$treatment == C], 3) d$value2 - va2 This works because the data frame is sorted in the right way and all cases are present. Furthermore, it would be a bit elaborative if you want to that for more than a couple of columns and it is not very error prone nor scalable (what if somebody changes the order of the data frame before, or somebody assumes that the data frame is in a certain order afterwards? If I want to add some columns later, I have to add new lines. What if some cases are missing?) Thus, this approach is clearly not a good one, especially since I don't like solutions which depend on a certain order. So my questions: 1. Is there a ready made solution for that? 2. If not (what I assume), what would be an elegant way of solving this? Is the only way to sort the data? Not that I have any problem with sorting, but I would appreciate any solution which works w/o sorting, because I don't want to run into the risk of having issues downstream with people who assume a certain order in the data (which is of course anyways a no-go, but I assume that the time to find a solution w/o altering the order is shorter than the time it takes to educate these guys [not on the long run though, but this battle has to be fought later] ;) 3. This solution should be easily extendable to an arbitrary set of columns and should work with missing cases for the treatments like d - d[-c(2, 21)] Thanks for your input, I am looking forward to your suggestions. Kind Regards, Thorn Thaler Mathematician Applied Mathematics Nestec Ltd, Nestlé Research Center PO Box 44 CH-1000 Lausanne 26 Phone: +41 21 785 8220 Fax: +41 21 785 9486 __ 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] the value of the last expression
HI, It is working for me. gamma(1:15) [1] 1 1 2 6 24 120 [7] 720 5040 40320 362880 3628800 39916800 [13] 479001600 6227020800 87178291200 z-.Last.value z # [1] 1 1 2 6 24 120 #[7] 720 5040 40320 362880 3628800 39916800 #[13] 479001600 6227020800 87178291200 sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] matrixStats_0.6.2 stringr_0.6 reshape_0.8.4 plyr_1.7.1 loaded via a namespace (and not attached): [1] R.methodsS3_1.4.2 tools_2.15.0 A.K. - Original Message - From: Sam Steingold s...@gnu.org To: r-help@r-project.org; Richard M. Heiberger r...@temple.edu Cc: Sent: Monday, December 10, 2012 2:13 PM Subject: Re: [R] the value of the last expression * Richard M. Heiberger e...@grzcyr.rqh [2012-02-09 21:48:50 -0500]: .Last.value Thanks; it worked for a while, but not anymore: http://stat.ethz.ch/R-manual/R-patched/library/base/html/Last.value.html --8---cut here---start-8--- gamma(1:15) [1] 1 1 2 6 24 120 [7] 720 5040 40320 362880 3628800 39916800 [13] 479001600 6227020800 87178291200 z - .Last.value z NULL --8---cut here---end---8--- could my .Rprofile be at fault? --8---cut here---start-8--- ## breaks ess ## options(error = utils::recover) options(max.print = 100, repos = c(CRAN = http://lib.stat.cmu.edu/R/CRAN/;)) library(compiler) compiler::enableJIT(3) compiler::compilePKGS(1) --8---cut here---end---8--- On Thu, Feb 9, 2012 at 9:44 PM, Sam Steingold s...@gnu.org wrote: Is there an analogue of common lisp * variable which contains the value of the last expression? E.g., in lisp: (+ 1 2) 3 * 3 I wish I could recover the value of the last expression without re-evaluating it. -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://mideasttruth.com http://thereligionofpeace.com http://www.memritv.org http://iris.org.il http://americancensorship.org Diplomacy is the art of saying nice doggy until you can find a nice rock. __ 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] sum portions of a vector
On Dec 10, 2012, at 11:29 AM, Sam Steingold wrote: How do I sum portions of a vector into another vector? E.g., for --8---cut here---start-8--- vec - 1:10 breaks - c(3,8,10) --8---cut here---end---8--- I want to get a vector of length 3 with content --8---cut here---start-8--- 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 --8---cut here---end---8--- Obviously, I could write a loop, but I would rather have a vectorized version. split(vec, findInterval(seq_along(vec), breaks+.001, right=TRUE) ) $`0` [1] 1 2 3 $`1` [1] 4 5 6 7 8 $`2` [1] 9 10 Needed to push the breaks slightly rightward since findInterval generally returns left-closed interval values. -- David Winsemius Alameda, CA, 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-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum portions of a vector
How about? vec - 1:10 breaks - c(3,8,10) g - cut(vec, c(0, breaks)) sums - aggregate(vec, list(g), sum)$x nums - tapply(vec, g, paste0, collapse=+) results - paste0(sums, = , nums) results [1] 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Sam Steingold Sent: Monday, December 10, 2012 1:29 PM To: r-help@r-project.org Subject: [R] sum portions of a vector How do I sum portions of a vector into another vector? E.g., for --8---cut here---start-8--- vec - 1:10 breaks - c(3,8,10) --8---cut here---end---8--- I want to get a vector of length 3 with content --8---cut here---start-8--- 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 --8---cut here---end---8--- Obviously, I could write a loop, but I would rather have a vectorized version. Thanks! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://palestinefacts.org http://ffii.org http://jihadwatch.org http://www.PetitionOnline.com/tap12009/ One can find Holy Grail or Higgs boson, but not the second sock. __ 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] bootstrap a multinomial regression
Dear friends, does anyone know how I can bootstrap a multinomial regression (say using mlogit or multinom from the nnet package) in a way similar to the one implemented bybootStepAIC? Thanks Dr. Iasonas Lamprianou Department of Social and Political Sciences University of Cyprus [[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] Can somebody suggest how to achieve following data manipulation?
Dear all, Let say I have following data: RawData - matrix(1:101, nr = 1); colnames(RawData) - c(ASD, as.character(as.yearmon(seq(as.Date(2012-03-01), length.out = 100, by = 1 month; rownames(RawData) - XYZ CutOffDate - as.Date(2012-09-01) NewDateSeries - as.character(as.yearmon(seq(CutOffDate, to = as.Date(2025-01-01), by = 1 month))) ResultMat - matrix(NA, 1, length(NewDateSeries)) colnames(ResultMat) - NewDateSeries rownames(ResultMat) - Result RawData ResultMat Now I need to pass the elements of 'RawData' to 'ResultMat' in following way: Consider the column 'Sep 2012' of 'ResultMat' (i.e. the first column). The element for this column will be sum of all elements of columns less than or equal to 'Sep 2012' of 'RawData' and including the column 'ASD'. Therefore, the column 'Sep 2012' of 'ResultMat' will have the element as 1+2+3+4 + 5 + 6 + 7 + 8 = 36. And remaining columns of 'ResultMat'will get the data from the same column names of 'RawData'. Therefore the 2nd column of 'ResultMat' will have the element as 9 and so on. I need to adopt above filling policy for arbitrary 'CutOffDate'. Ofcourse this can be implemented using a 'for' loop. However I believe there is some better R-way to do that. Can somebody help me to achieve that? Thanks and regards, __ 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] sum portions of a vector
On Dec 10, 2012, at 11:29 AM, Sam Steingold wrote: How do I sum portions of a vector into another vector? E.g., for --8---cut here---start-8--- vec - 1:10 breaks - c(3,8,10) --8---cut here---end---8--- I want to get a vector of length 3 with content --8---cut here---start-8--- 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 --8---cut here---end---8--- Obviously, I could write a loop, but I would rather have a vectorized version. tapply(vec, cut(vec, breaks=c(-Inf, breaks), include.lowest=TRUE), sum) [-Inf,3](3,8] (8,10] 6 30 19 -- David Winsemius, MD Alameda, CA, 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-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum portions of a vector
On Dec 10, 2012, at 1:29 PM, Sam Steingold s...@gnu.org wrote: How do I sum portions of a vector into another vector? E.g., for --8---cut here---start-8--- vec - 1:10 breaks - c(3,8,10) --8---cut here---end---8--- I want to get a vector of length 3 with content --8---cut here---start-8--- 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 --8---cut here---end---8--- Obviously, I could write a loop, but I would rather have a vectorized version. Thanks! See ?findInterval. findInterval(seq(along = vec), breaks + 1) [1] 0 0 0 1 1 1 1 1 2 2 as.vector(sapply(split(vec, findInterval(seq(along = vec), breaks + 1)), sum)) [1] 6 30 19 Did you just want the above, or did you really want: as.vector(sapply(split(vec, findInterval(seq(along = vec), breaks + 1)), function(x) paste(sum(x), =, paste(x, collapse = + [1] 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 Regards, Marc Schwartz __ 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] sum portions of a vector
Hi, May be this also helps: do.call(rbind,lapply(split(vec,findInterval(vec,c(4,9))),function(x) paste0(sum(x),=,paste(x,collapse=+ [,1] #0 6=1+2+3 #1 30=4+5+6+7+8 #2 19=9+10 a.K. - Original Message - From: Sam Steingold s...@gnu.org To: r-help@r-project.org Cc: Sent: Monday, December 10, 2012 2:29 PM Subject: [R] sum portions of a vector How do I sum portions of a vector into another vector? E.g., for --8---cut here---start-8--- vec - 1:10 breaks - c(3,8,10) --8---cut here---end---8--- I want to get a vector of length 3 with content --8---cut here---start-8--- 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 --8---cut here---end---8--- Obviously, I could write a loop, but I would rather have a vectorized version. Thanks! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://palestinefacts.org http://ffii.org http://jihadwatch.org http://www.PetitionOnline.com/tap12009/ One can find Holy Grail or Higgs boson, but not the second sock. __ 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] use variable in for loop to name output files
Hi, This question should be simple to answer. I am a new R user. I have a data.frame called appended. I would like to break it into 7 smaller datasets based on the value of a categorical variable dp (which has values 1:7). I would like to name the smaller datasets set1, set2, set3,,set7. I don't know how to refer to the variable in the for loop, when naming the output datasets. In STATA (which I am much more familiar with) each i in the foreach loop would be refered to as `i'. This is the code I've included below. I've also tried set[[i]] and set[i] neither works. for (i in 1:7) { set`i' = appended[which(appended$dp==i appended$sampled==0), ] write.table(set`i', file = output\\set`i'.csv, sep = ,, row.name=F) } I'm assuming I just need to replace `' with something else but I can figure out what that something else is. -- View this message in context: http://r.789695.n4.nabble.com/use-variable-in-for-loop-to-name-output-files-tp4652711.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.
Re: [R] Can somebody suggest how to achieve following data manipulation?
Hi, It's not very clear. Here, the dimensions are different. dim(RawData) #[1] 1 101 dim(ResultMat) #[1] 1 149 ResultMat[,1]-sum(RawData[RawData=RawData[8]]) ResultMat[,2:94]-RawData[RawData=RawData[9]] A.K. - Original Message - From: Christofer Bogaso bogaso.christo...@gmail.com To: r-help@r-project.org Cc: Sent: Monday, December 10, 2012 3:50 PM Subject: [R] Can somebody suggest how to achieve following data manipulation? Dear all, Let say I have following data: RawData - matrix(1:101, nr = 1); colnames(RawData) - c(ASD, as.character(as.yearmon(seq(as.Date(2012-03-01), length.out = 100, by = 1 month; rownames(RawData) - XYZ CutOffDate - as.Date(2012-09-01) NewDateSeries - as.character(as.yearmon(seq(CutOffDate, to = as.Date(2025-01-01), by = 1 month))) ResultMat - matrix(NA, 1, length(NewDateSeries)) colnames(ResultMat) - NewDateSeries rownames(ResultMat) - Result RawData ResultMat Now I need to pass the elements of 'RawData' to 'ResultMat' in following way: Consider the column 'Sep 2012' of 'ResultMat' (i.e. the first column). The element for this column will be sum of all elements of columns less than or equal to 'Sep 2012' of 'RawData' and including the column 'ASD'. Therefore, the column 'Sep 2012' of 'ResultMat' will have the element as 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36. And remaining columns of 'ResultMat'will get the data from the same column names of 'RawData'. Therefore the 2nd column of 'ResultMat' will have the element as 9 and so on. I need to adopt above filling policy for arbitrary 'CutOffDate'. Ofcourse this can be implemented using a 'for' loop. However I believe there is some better R-way to do that. Can somebody help me to achieve that? Thanks and regards, __ 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] sum portions of a vector
On Dec 10, 2012, at 2:52 PM, David Winsemius dwinsem...@comcast.net wrote: On Dec 10, 2012, at 11:29 AM, Sam Steingold wrote: How do I sum portions of a vector into another vector? E.g., for --8---cut here---start-8--- vec - 1:10 breaks - c(3,8,10) --8---cut here---end---8--- I want to get a vector of length 3 with content --8---cut here---start-8--- 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 --8---cut here---end---8--- Obviously, I could write a loop, but I would rather have a vectorized version. tapply(vec, cut(vec, breaks=c(-Inf, breaks), include.lowest=TRUE), sum) [-Inf,3](3,8] (8,10] 6 30 19 One gotcha there David, as I think you were on the right track earlier with findInterval(). The result with this approach, using cut(), takes advantage of the idiosyncrasy of Sam's example, which uses a sorted vector (1:10) that is equivalent to the indices of the same vector (1:10). If Sam really is using 'breaks' as the indices into 'vec' and not as ranges for the values to be summed, as cut() does, then findInterval() works: set.seed(1) vec2 - sample(vec) vec2 [1] 3 4 5 7 2 8 9 6 10 1 [-Inf,3] = 3+2+1 = 6 (3,8] = 4+5+7+8+6 = 30 (8,10] = 9+10 = 19 tapply(vec2, cut(vec2, breaks=c(-Inf, breaks), include.lowest=TRUE), sum) [-Inf,3](3,8] (8,10] 6 30 19 as compared to: 3+4+5 = 12 7+2+8+9+6 = 32 10+1 = 11 as.vector(sapply(split(vec2, findInterval(seq(along = vec), breaks + 1)), sum)) [1] 12 32 11 Regards, Marc __ 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] sum portions of a vector
On Dec 10, 2012, at 3:29 PM, Marc Schwartz marc_schwa...@me.com wrote: On Dec 10, 2012, at 2:52 PM, David Winsemius dwinsem...@comcast.net wrote: On Dec 10, 2012, at 11:29 AM, Sam Steingold wrote: How do I sum portions of a vector into another vector? E.g., for --8---cut here---start-8--- vec - 1:10 breaks - c(3,8,10) --8---cut here---end---8--- I want to get a vector of length 3 with content --8---cut here---start-8--- 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 --8---cut here---end---8--- Obviously, I could write a loop, but I would rather have a vectorized version. tapply(vec, cut(vec, breaks=c(-Inf, breaks), include.lowest=TRUE), sum) [-Inf,3](3,8] (8,10] 6 30 19 One gotcha there David, as I think you were on the right track earlier with findInterval(). The result with this approach, using cut(), takes advantage of the idiosyncrasy of Sam's example, which uses a sorted vector (1:10) that is equivalent to the indices of the same vector (1:10). If Sam really is using 'breaks' as the indices into 'vec' and not as ranges for the values to be summed, as cut() does, then findInterval() works: set.seed(1) vec2 - sample(vec) vec2 [1] 3 4 5 7 2 8 9 6 10 1 [-Inf,3] = 3+2+1 = 6 (3,8] = 4+5+7+8+6 = 30 (8,10] = 9+10 = 19 tapply(vec2, cut(vec2, breaks=c(-Inf, breaks), include.lowest=TRUE), sum) [-Inf,3](3,8] (8,10] 6 30 19 as compared to: 3+4+5 = 12 7+2+8+9+6 = 32 10+1 = 11 as.vector(sapply(split(vec2, findInterval(seq(along = vec), breaks + 1)), sum)) [1] 12 32 11 Ack, copied and pasted the above with a typo. Same result, but should be: as.vector(sapply(split(vec2, findInterval(seq(along = vec2), breaks + 1)), sum)) [1] 12 32 11 Regards, Marc __ 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] Removing named objects using rm(..)
When I import the library timeSeries I get (at least) the variable USDCHF imported too. I would like to delete it, but I cannot. As you can see below. Clearly I am doing something wrong. What is it? library(timeSeries) Loading required package: timeDate class(USDCHF) [1] timeSeries attr(,package) [1] timeSeries rm(list=c(USDCHF)) Warning message: In rm(list = c(USDCHF)) : object 'USDCHF' not found rm(USDCHF) Warning message: In rm(USDCHF) : object 'USDCHF' not found class(USDCHF) [1] timeSeries attr(,package) [1] timeSeries I can assign to it... USDCHF-NULL class(USDCHF) [1] NULL get(USDCHF) NULL 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.
Re: [R] use variable in for loop to name output files
Hello, Try the following. set - list() for (i in 1:7) { set[[i]] - appended[which(appended$dp == i appended$sampled == 0), ] fl - paste0(output/set, i, .csv) write.table(set[[i]], file = fl, sep = ,, row.name=F) } Hope this helps, Rui Barradas Em 10-12-2012 21:03, john-usace escreveu: Hi, This question should be simple to answer. I am a new R user. I have a data.frame called appended. I would like to break it into 7 smaller datasets based on the value of a categorical variable dp (which has values 1:7). I would like to name the smaller datasets set1, set2, set3,,set7. I don't know how to refer to the variable in the for loop, when naming the output datasets. In STATA (which I am much more familiar with) each i in the foreach loop would be refered to as `i'. This is the code I've included below. I've also tried set[[i]] and set[i] neither works. for (i in 1:7) { set`i' = appended[which(appended$dp==i appended$sampled==0), ] write.table(set`i', file = output\\set`i'.csv, sep = ,, row.name=F) } I'm assuming I just need to replace `' with something else but I can figure out what that something else is. -- View this message in context: http://r.789695.n4.nabble.com/use-variable-in-for-loop-to-name-output-files-tp4652711.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] Creating a geographical grid
You can do this with basic R functions: ## create vectors of the longitude and latitude values x - seq(from = 24, to = 34, by = 0.025) y - seq(from = -24, to = -14, by = 0.025) ## create a grid of all pairs of coordinates (as a data.frame) xy - expand.grid(x = x, y = y) ## load the foreign package to write to DBF library(foreign) write.dbf(xy, file = xy.dbf) Note that there's nothing particularly geographical about any of this, and using 10km resolution with longitude / latitude coordinates could only be done with an approximation that was not constant over the area, unless you used an appropriate map projection (i.e. not long/lat). Note that a 0.025 long/lat spacing is more like 2.7 km in this region (and it changes within the region) so you might need to check why you have that number. Also, the coordinates created above are only WGS84 by virtue of the fact that you state that they are, there's no way to store that metadata in DBF. If you need to explore this further the R-Sig-Geo mailing list is appropriate for spatial functions and formats. Cheers, Mike. On Mon, Dec 10, 2012 at 10:08 PM, Ulrik Bo Pedersen u...@sund.ku.dk wrote: I would like to create a geographical grid to have a sort of a reference grid for my georeferenced survey data. The grid should be in a xy format, wgs1984 with a 0.025 degree, alternatively 10km, resolution covering -14 to -24 S and 24 to -34 E (Zimbabwe). Additionally I need to be able to export it as a .dbf Hope someone can help an R- novice ! [[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. -- Michael Sumner Hobart, Australia e-mail: mdsum...@gmail.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.
Re: [R] use variable in for loop to name output files
On Dec 10, 2012, at 1:03 PM, john-usace wrote: Hi, This question should be simple to answer. I am a new R user. I have a data.frame called appended. I would like to break it into 7 smaller datasets based on the value of a categorical variable dp (which has values 1:7). I would like to name the smaller datasets set1, set2, set3,,set7. I don't know how to refer to the variable in the for loop, when naming the output datasets. In STATA (which I am much more familiar with) each i in the foreach loop would be refered to as `i'. This is the code I've included below. I've also tried set[[i]] and set[i] neither works. for (i in 1:7) { set`i' = appended[which(appended$dp==i appended$sampled==0), ] I am not aware of any set function, nor can one append back-ticked characters to unquoted characters and expect anything useful to happen. write.table(set`i', file = output\\set`i'.csv, sep = ,, row.name=F) } I'm assuming I just need to replace `' with something else but I can figure out what that something else is. In R the easy way would be to create a list that holds all of the split dataframes: newlist - split( appended, catvar) names(newlist) - paste0(set, 1:7) If you goal were just to have these in your workspace, you are done. If you goal is to write them out to a file then you can either save it as one object to be later pulled back into a session with the load(.) command using this: save(newlist, newlist.Rdata) Or you can write each individually with lapply(names(newlist) , function(dfrm) { write.table(newlist[[dfrm]], file=paste0( dfrm, .csv, sep=,, rowname=FALSE) } (Untested. You should read the help pages of the various functions mentioned.) -- David Winsemius, MD Alameda, CA, 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-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing named objects using rm(..)
On 12-12-10 4:40 PM, Worik R wrote: When I import the library timeSeries I get (at least) the variable USDCHF imported too. I would like to delete it, but I cannot. As you can see below. You didn't import timeSeries, you attached it. It is on your search list; you can see the full list using search(). The first item on the search list is .GlobalEnv, the user's global environment. You can create and delete items there. You can't easily do so in the other items in the search list, they are essentially read-only. Clearly I am doing something wrong. What is it? You need to learn more about how R does scoping. I don't think the description in the Intro to R is sufficient; you probably need the R Language Definition discussion (or a third party book). Duncan Murdoch library(timeSeries) Loading required package: timeDate class(USDCHF) [1] timeSeries attr(,package) [1] timeSeries rm(list=c(USDCHF)) Warning message: In rm(list = c(USDCHF)) : object 'USDCHF' not found rm(USDCHF) Warning message: In rm(USDCHF) : object 'USDCHF' not found class(USDCHF) [1] timeSeries attr(,package) [1] timeSeries I can assign to it... USDCHF-NULL class(USDCHF) [1] NULL get(USDCHF) NULL 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. __ 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] sum portions of a vector
If you have a large number of small groups the tapply(x, factor, sum) can be sped up by replacing it with Rigroup::igroupSums(x, as.integer(factor)), as in: library(Rigroup) x - 1:1e6 fgroup - factor(c(seq_len(length(x)/2), sample(length(x)/2, size=length(x)/2, replace=TRUE))) # 5*10^5 small groups system.time(v1 - tapply(x, fgroup, sum)) user system elapsed 3.193 0.020 3.220 system.time(v2 - igroupSums(x, as.integer(fgroup))) user system elapsed 0.044 0.000 0.046 all(v1==v2) [1] TRUE (The igroupFUN functions are in S+ and do the fast numerical work for the groupFUN functions. Rigroup looks like it is based on the S+ igroupFUN functions but doesn't not have the Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David L Carlson Sent: Monday, December 10, 2012 12:08 PM To: s...@gnu.org; r-help@r-project.org Subject: Re: [R] sum portions of a vector How about? vec - 1:10 breaks - c(3,8,10) g - cut(vec, c(0, breaks)) sums - aggregate(vec, list(g), sum)$x nums - tapply(vec, g, paste0, collapse=+) results - paste0(sums, = , nums) results [1] 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Sam Steingold Sent: Monday, December 10, 2012 1:29 PM To: r-help@r-project.org Subject: [R] sum portions of a vector How do I sum portions of a vector into another vector? E.g., for --8---cut here---start-8--- vec - 1:10 breaks - c(3,8,10) --8---cut here---end---8--- I want to get a vector of length 3 with content --8---cut here---start-8--- 6 = 1+2+3 30 = 4+5+6+7+8 19 = 9+10 --8---cut here---end---8--- Obviously, I could write a loop, but I would rather have a vectorized version. Thanks! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://palestinefacts.org http://ffii.org http://jihadwatch.org http://www.PetitionOnline.com/tap12009/ One can find Holy Grail or Higgs boson, but not the second sock. __ 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.
[R] splitting dataset based on variable and re-combining
I have a dataset and I wish to use two different models to predict. Both models are SVM. The reason for two different models is based on the sex of the observation. I wish to be able to make predictions and have the results be in the same order as my original dataset. To illustrate I will use iris: # Take Iris and create a dataframe of just two Species, setosa and versicolor, shuffle them data(iris) iris - iris[(iris$Species==setosa | iris$Species==versicolor),] irisindex - sample(1:nrow(iris), nrow(iris)) iris - iris[irisindex,] # Make predictions on setosa using the mySetosaModel model, and on versicolor using the myVersicolorModel: predict(mySetosaModel, iris[iris$Species==setosa,]) predict(myVersicolorModel, iris[iris$Species==versicolor,]) The problem is this will give me a vector of just the setosa results, and then one of just the versicolor results. I wish to take the results and have them be in the same order as the original dataset. So if the original dataset had: Species setosa setosa versicolor setosa versicolor setosa I wish for my results to have: prediction for setosa prediction for setosa prediction for versicolor prediction for setosa prediction for versicolor prediction for setosa But instead, what I am ending up with is two result sets, and no way I can think of to combine them. I am sure this comes up alot where you have a factor you wish to split your models on, say sex (male vs. female), and you need to present the results back so it matches to the order of the orignal dataset. I have tried to think of ways to use an index, to try to keep things in order, but I can't figure it out. Any help is greatly appreciated. Brian __ 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] splitting dataset based on variable and re-combining
Package plyr is designed for this sort of thing, but functions split() and unsplit() will work as well. This example just uses a simple lm() model: data(iris) iris - iris[(iris$Species==setosa | iris$Species==versicolor),] set.seed(42) irisindex - sample(1:nrow(iris), nrow(iris)) iris - iris[irisindex,] iris$Species - factor(iris$Species) # Eliminate empty level virginica iris2 - split(iris, iris$Species) # List with two data.frames results - lapply(iris2, function(x) lm(Sepal.Length ~ Sepal.Width + + Petal.Length + Petal.Width, x)) fit - lapply(results, predict) iris3 - lapply(names(iris2), function(x) data.frame(iris2[[x]], fitted=fit[[x]])) iris4 - unsplit(iris3, iris$Species) head(iris4) Sepal.Length Sepal.Width Petal.Length Petal.WidthSpecies fitted 92 6.1 3.0 4.6 1.4 versicolor 6.283549 93 5.8 2.6 4.0 1.2 versicolor 5.719649 29 5.2 3.4 1.4 0.2 setosa 4.961338 81 5.5 2.4 3.8 1.1 versicolor 5.528532 62 5.9 3.0 4.2 1.5 versicolor 5.852292 50 5.0 3.3 1.4 0.2 setosa 4.895855 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Brian Feeny Sent: Monday, December 10, 2012 4:41 PM To: r-help@r-project.org Subject: [R] splitting dataset based on variable and re-combining I have a dataset and I wish to use two different models to predict. Both models are SVM. The reason for two different models is based on the sex of the observation. I wish to be able to make predictions and have the results be in the same order as my original dataset. To illustrate I will use iris: # Take Iris and create a dataframe of just two Species, setosa and versicolor, shuffle them data(iris) iris - iris[(iris$Species==setosa | iris$Species==versicolor),] irisindex - sample(1:nrow(iris), nrow(iris)) iris - iris[irisindex,] # Make predictions on setosa using the mySetosaModel model, and on versicolor using the myVersicolorModel: predict(mySetosaModel, iris[iris$Species==setosa,]) predict(myVersicolorModel, iris[iris$Species==versicolor,]) The problem is this will give me a vector of just the setosa results, and then one of just the versicolor results. I wish to take the results and have them be in the same order as the original dataset. So if the original dataset had: Species setosa setosa versicolor setosa versicolor setosa I wish for my results to have: prediction for setosa prediction for setosa prediction for versicolor prediction for setosa prediction for versicolor prediction for setosa But instead, what I am ending up with is two result sets, and no way I can think of to combine them. I am sure this comes up alot where you have a factor you wish to split your models on, say sex (male vs. female), and you need to present the results back so it matches to the order of the orignal dataset. I have tried to think of ways to use an index, to try to keep things in order, but I can't figure it out. Any help is greatly appreciated. Brian __ 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] Removing named objects using rm(..)
Let me restate my question. Is there a straightforward way of ensuring I can use the variable name USDCHF? Is there a straight forward way of ensuring that when I delete a variable by name I delete all copies in scope? Worik On Tue, Dec 11, 2012 at 11:08 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 12-12-10 4:40 PM, Worik R wrote: When I import the library timeSeries I get (at least) the variable USDCHF imported too. I would like to delete it, but I cannot. As you can see below. You didn't import timeSeries, you attached it. It is on your search list; you can see the full list using search(). The first item on the search list is .GlobalEnv, the user's global environment. You can create and delete items there. You can't easily do so in the other items in the search list, they are essentially read-only. Clearly I am doing something wrong. What is it? You need to learn more about how R does scoping. I don't think the description in the Intro to R is sufficient; you probably need the R Language Definition discussion (or a third party book). Duncan Murdoch library(timeSeries) Loading required package: timeDate class(USDCHF) [1] timeSeries attr(,package) [1] timeSeries rm(list=c(USDCHF)) Warning message: In rm(list = c(USDCHF)) : object 'USDCHF' not found rm(USDCHF) Warning message: In rm(USDCHF) : object 'USDCHF' not found class(USDCHF) [1] timeSeries attr(,package) [1] timeSeries I can assign to it... USDCHF-NULL class(USDCHF) [1] NULL get(USDCHF) NULL Worik [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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] Two statement logical dealing with NAs
Hello. I have a two statement logical that if NA is returned for the second statement I want to rely on result of the first statement. I still would like to use both when I can though. x - c(1:5) y - c(1,2,NA,4,5) x 5 x-y == 0 How can I trick R to refer back to (x 5) where it is NA on the third value? Thanks. [[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 compare each row in a matrix with each row in another matrix?
HI Jonathan, Thanks for the email. I crosschecked my output with the output generated from the initial solution (ind). perhaps - function(A,B){ nA - nrow(A) nB - nrow(B) C - kronecker(matrix(1,nrow=nA,ncol=1),B) = kronecker(A,matrix(1,nrow=nB,ncol=1)) matrix(rowSums(C) == ncol(A), nA, nB, byrow=TRUE) } Marius.5.0.Prev - function(A,B) outer(rowMaxs(A),rowMins(B),'') #Jonathan function Marius.5.0 - function(A,B) outer(rowMaxs(A),rowMins(B),'=') #updated Jonathan function Marius.4.0-function(A,B){apply(B,1,function(x) colSums(x=t(A)))==ncol(A)} A - rbind(matrix(1:4, ncol=2, byrow=TRUE), c(6, 2)) # (3, 2) matrix B - matrix(1:10, ncol=2) # (5, 2 ind - apply(B, 1, function(b) apply(A, 1, function(a) all(a = b))) #original function ind # [,1] [,2] [,3] [,4] [,5] #[1,] TRUE TRUE TRUE TRUE TRUE #[2,] FALSE FALSE TRUE TRUE TRUE #[3,] FALSE FALSE FALSE FALSE FALSE Marius.4.0(A,B) # [,1] [,2] [,3] [,4] [,5] #[1,] TRUE TRUE TRUE TRUE TRUE #[2,] FALSE FALSE TRUE TRUE TRUE #[3,] FALSE FALSE FALSE FALSE FALSE perhaps(A,B) # [,1] [,2] [,3] [,4] [,5] #[1,] TRUE TRUE TRUE TRUE TRUE #[2,] FALSE FALSE TRUE TRUE TRUE #[3,] FALSE FALSE FALSE FALSE FALSE Marius.5.0(A,B) # [,1] [,2] [,3] [,4] [,5] #[1,] FALSE TRUE TRUE TRUE TRUE #[2,] FALSE FALSE FALSE TRUE TRUE #[3,] FALSE FALSE FALSE FALSE FALSE Marius.5.0.Prev(A,B) # [,1] [,2] [,3] [,4] [,5] #[1,] FALSE FALSE TRUE TRUE TRUE #[2,] FALSE FALSE FALSE FALSE TRUE #[3,] FALSE FALSE FALSE FALSE FALSE A.K. - Original Message - From: j2ken...@gmail.com j2ken...@gmail.com To: smartpink...@yahoo.com Cc: Sent: Monday, December 10, 2012 5:39 PM Subject: Re: How to efficiently compare each row in a matrix with each row in another matrix? Hello Arun, I saw your message. For some reason it doesn't let me post on the help site. It looks like I forgot an equal sign. It wasn't a problem with the random numbers because there was little chance a number would be repeated. It should be: Marius.5.0 - function(A,B) outer(rowMaxs(A),rowMins(B),'=') #Jonathan's code However, if you manually look at the example you provided, Marius.4.0 doesn't provide the correct answer either. There is one too many TRUE values (location [2,3]). The updated Marius.5.0 gives the correct result. -Jonathan __ 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] questions on French characters in plot
Dear all, I have imported a dataset from Stata using the foreign package. The original data contain French characters such as è and ç . After importing, string variables containing names of French departments have changed. E.g. Ardèche became Ard\x8fche. I would like to ask how I could plot these changed strings, since now the strings with special characters fail to be printed in the plot (either using plot() or ggplot2()). I have googled for solutions, but actually find it hard to determine whether I should change my R setup or should read in the data in a different way. Since I work on a mac I changed my local according to the R for Mac OS X FAQ, chapter 9. Below is some info on my setup and code and output on what works for me and what does not. Thank you in advance for you comments. Best, Richard #-- rm(list=ls()) sessionInfo() # R version 2.15.2 (2012-10-26) # Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) # # locale: # [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 # creating variables department - c(Nord,Paris,Ard\x8fche) department2 - c(Nord, Paris, Ardèche) n - c(2,4,1) # creating dataframes df - data.frame(department,n) df2 - data.frame(department2,n) department # [1] Nord Paris Ard\x8fche department2 # [1] NordParis Ardèche plot(df) # fails to show the text Ardèche plot(df2) # shows text Ardèche # EOF [[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] Removing named objects using rm(..)
On 12-12-10 7:33 PM, Worik R wrote: Let me restate my question. Is there a straightforward way of ensuring I can use the variable name USDCHF? You can use any legal variable name. The only risk is that you will overwrite some other variable that you created. You can't overwrite variables from packages. (You might mask them, but they are still accessible using the :: notation. E.g. after you set USDCHF - NULL you can still access the one in timeSeries using timeSeries::USDCHF Is there a straight forward way of ensuring that when I delete a variable by name I delete all copies in scope? No. It is not straightforward to delete any variables other than the ones that you created in the global environment. Duncan Murdoch Worik On Tue, Dec 11, 2012 at 11:08 AM, Duncan Murdoch murdoch.dun...@gmail.com mailto:murdoch.dun...@gmail.com wrote: On 12-12-10 4:40 PM, Worik R wrote: When I import the library timeSeries I get (at least) the variable USDCHF imported too. I would like to delete it, but I cannot. As you can see below. You didn't import timeSeries, you attached it. It is on your search list; you can see the full list using search(). The first item on the search list is .GlobalEnv, the user's global environment. You can create and delete items there. You can't easily do so in the other items in the search list, they are essentially read-only. Clearly I am doing something wrong. What is it? You need to learn more about how R does scoping. I don't think the description in the Intro to R is sufficient; you probably need the R Language Definition discussion (or a third party book). Duncan Murdoch library(timeSeries) Loading required package: timeDate class(USDCHF) [1] timeSeries attr(,package) [1] timeSeries rm(list=c(USDCHF)) Warning message: In rm(list = c(USDCHF)) : object 'USDCHF' not found rm(USDCHF) Warning message: In rm(USDCHF) : object 'USDCHF' not found class(USDCHF) [1] timeSeries attr(,package) [1] timeSeries I can assign to it... USDCHF-NULL class(USDCHF) [1] NULL get(USDCHF) NULL Worik [[alternative HTML version deleted]] R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/__listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/__posting-guide.html 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] Two statement logical dealing with NAs
On 12-12-10 7:55 PM, Hans Thompson wrote: Hello. I have a two statement logical that if NA is returned for the second statement I want to rely on result of the first statement. I still would like to use both when I can though. x - c(1:5) y - c(1,2,NA,4,5) x 5 x-y == 0 How can I trick R to refer back to (x 5) where it is NA on the third value? Use is.na() to test for NA. I think this does what you want: x 5 (is.na(x-y == 0) | x-y == 0) Duncan Murdoch __ 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] Two statement logical dealing with NAs
On Dec 10, 2012, at 4:55 PM, Hans Thompson wrote: Hello. I have a two statement logical that if NA is returned for the second statement I want to rely on result of the first statement. I still would like to use both when I can though. x - c(1:5) y - c(1,2,NA,4,5) x 5 x-y == 0 How can I trick R to refer back to (x 5) where it is NA on the third value? If you program so that you trick your tool, you will fail to progress in understanding it Since NA | TRUE returns TRUE (and is clearly documented as such) this is not trickery: x 5 (is.na(y) | x-y == 0) [1] TRUE TRUE TRUE TRUE FALSE -- David Winsemius, MD Alameda, CA, 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-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing named objects using rm(..)
On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 12-12-10 7:33 PM, Worik R wrote: Let me restate my question. Is there a straightforward way of ensuring I can use the variable name USDCHF? You can use any legal variable name. The only risk is that you will overwrite some other variable that you created. You can't overwrite variables from packages. (You might mask them, but they are still accessible using the :: notation. E.g. after you set USDCHF - NULL Exactly. I got around this by assigning NULL to the variable names that I would have deleted. Then instead of testing for existence I tested for NULL. you can still access the one in timeSeries using timeSeries::USDCHF Christ. That is what I wanted to delete. I read the scoping section of R-Lang (again) and nothing I could see prepared me for the shock of... library(timeSeries) nrow(USDCHF) [1] 62496 rm(USDCHF) Warning message: In rm(USDCHF) : object 'USDCHF' not found nrow(USDCHF) [1] 62496 The message from rm was that USDCHF did not exist. But I can still access its properties with nrow. This is very broken. I would not have believed I would see that in the 21st century with a modern language. (Oh wait, there is Javascript and PHP, so in comparison R is not that broken) I am not new to R, I have been (mis)using it for 5 years. I love aspects of R, but this and a few other things (lack of debugging support and ignoring the principle of least surprise are two biggies) are very frustrating. Without debugging support or more help from the compiler (like a cannot rm EURCHF message instead of a lie) R causes as many problems as it solves. Sigh. Thanks for the help. 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.
Re: [R] Removing named objects using rm(..)
Exactly. I got around this by assigning NULL to the variable names that I would have deleted. Then instead of testing for existence I tested for NULL. You may find it more reliable to define an environment in which you will be storing your data (perhaps globalenv(), perhaps something created by new.env()) and then testing for existence of a dataset by a given name in that environment. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Worik R Sent: Monday, December 10, 2012 5:47 PM To: Duncan Murdoch Cc: r-help Subject: Re: [R] Removing named objects using rm(..) On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 12-12-10 7:33 PM, Worik R wrote: Let me restate my question. Is there a straightforward way of ensuring I can use the variable name USDCHF? You can use any legal variable name. The only risk is that you will overwrite some other variable that you created. You can't overwrite variables from packages. (You might mask them, but they are still accessible using the :: notation. E.g. after you set USDCHF - NULL Exactly. I got around this by assigning NULL to the variable names that I would have deleted. Then instead of testing for existence I tested for NULL. you can still access the one in timeSeries using timeSeries::USDCHF Christ. That is what I wanted to delete. I read the scoping section of R-Lang (again) and nothing I could see prepared me for the shock of... library(timeSeries) nrow(USDCHF) [1] 62496 rm(USDCHF) Warning message: In rm(USDCHF) : object 'USDCHF' not found nrow(USDCHF) [1] 62496 The message from rm was that USDCHF did not exist. But I can still access its properties with nrow. This is very broken. I would not have believed I would see that in the 21st century with a modern language. (Oh wait, there is Javascript and PHP, so in comparison R is not that broken) I am not new to R, I have been (mis)using it for 5 years. I love aspects of R, but this and a few other things (lack of debugging support and ignoring the principle of least surprise are two biggies) are very frustrating. Without debugging support or more help from the compiler (like a cannot rm EURCHF message instead of a lie) R causes as many problems as it solves. Sigh. Thanks for the help. 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. __ 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 - predict logistic regression - entering the betas manually.
Dear All, I know this may be a trivial question. In the past I have used glm to make logistic regressions on data. The output creates an object with the results of the logistic regression. This object can then be used to make predictions. Great. I have a different problem. I need to make predictions from a logistic regression taken from a paper. Thus I need to (by hand) enter the reported odds ratios, compute the betas and enter these into an object in order to use the predict. Sure, I can write a function myself (the logit function) to make these predictions. But I was wondering how one can do this by creating a glm output object by entering this manually and then use the predict. I couldn't find any helpful site. Thanks. RAff. [[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] lattice question: how to change the dot on boxplot to line
Hi, How does one change the dot for the median in a boxplot drawn using lattice? I have been looking at names(trellis.par.get()) [1] grid.pars fontsize background [4] panel.background clip add.line [7] add.text plot.polygon box.dot [10] box.rectangle box.umbrella dot.line [13] dot.symbolplot.line plot.symbol [16] reference.linestrip.background strip.shingle [19] strip.border superpose.linesuperpose.symbol [22] superpose.polygon regions shade.colors [25] axis.line axis.text axis.components [28] layout.heightslayout.widths box.3d [31] par.xlab.text par.ylab.text par.zlab.text [34] par.main.text par.sub.text I tried playing around with dot.line and dot.symbol but could not figure out what to do. Is there anything else I could try. As a reproducible example, we can consider: library(lattice) bwplot(voice.part ~ height, data=singer, xlab=Height (inches)) I want the dots for the medians to be replaced by a line through the median. Any suggestions? Many thanks, Ranjan PS; Also, how do I get the rectangles to be filled? I tried the following: box.rectangle - trellis.par.get(box.rectangle) box.rectangle$fill-opaque (also tried filled, shaded, etc. to no avail) trellis.par.set(box.rectangle, box.rectangle) but get errors in plotting. Many thanks again and best wishes, Ranjan FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ 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] splitting dataset based on variable and re-combining
I will look into that, thanks. I am afraid I don't quite understand what is going on there with the multiplication, so I will need to read up. What I ended up doing was like so: For train data, its easy, as I can subset to have the model only work off the data I want: rbfSVM_setosa - train(Sepal.Length~., data = trainset, subset = trainset$Species==setosa, ...) rbfSVM_versicolor - train(Sepal.Length~., data = trainset, subset = trainset$Species==versicolor, ...) For my test data (testset), I ended up doing like so which appears to work: index_setosa- which(testset$Species == setosa) svmPred - as.vector(rep(NA,nrow(testset))) svmPred[index_setosa] - predict(rbfSVM_setosa, testset[testset$Species == setosa,]) svmPred[is.na(svmPred)] - predict(rbfSVM_versicolor, testset[testset$Species == versicolor,]) The above works when there are just two classes. I am going to read on some of these other ways suggested and give them a try. Brian On Dec 10, 2012, at 10:38 PM, Thomas Stewart tgs.public.m...@gmail.com wrote: Why not use an indicator variable? P1 - ... # prediction from model 1 (Setosa) for entire dataset P2 - ... # prediction from model 2 for entire dataset I - Species==setosa # Predictions - P1 * I + P2 * ( 1 - I ) On Monday, December 10, 2012, Brian Feeny wrote: I have a dataset and I wish to use two different models to predict. Both models are SVM. The reason for two different models is based on the sex of the observation. I wish to be able to make predictions and have the results be in the same order as my original dataset. To illustrate I will use iris: # Take Iris and create a dataframe of just two Species, setosa and versicolor, shuffle them data(iris) iris - iris[(iris$Species==setosa | iris$Species==versicolor),] irisindex - sample(1:nrow(iris), nrow(iris)) iris - iris[irisindex,] # Make predictions on setosa using the mySetosaModel model, and on versicolor using the myVersicolorModel: predict(mySetosaModel, iris[iris$Species==setosa,]) predict(myVersicolorModel, iris[iris$Species==versicolor,]) The problem is this will give me a vector of just the setosa results, and then one of just the versicolor results. I wish to take the results and have them be in the same order as the original dataset. So if the original dataset had: Species setosa setosa versicolor setosa versicolor setosa I wish for my results to have: prediction for setosa prediction for setosa prediction for versicolor prediction for setosa prediction for versicolor prediction for setosa But instead, what I am ending up with is two result sets, and no way I can think of to combine them. I am sure this comes up alot where you have a factor you wish to split your models on, say sex (male vs. female), and you need to present the results back so it matches to the order of the orignal dataset. I have tried to think of ways to use an index, to try to keep things in order, but I can't figure it out. Any help is greatly appreciated. Brian __ 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] lattice question: how to change the dot on boxplot to line
On 11 Dec 2012, at 03:05, Ranjan Maitra maitra.mbox.igno...@inbox.commailto:maitra.mbox.igno...@inbox.com wrote: How does one change the dot for the median in a boxplot drawn using lattice? Check your ?panel.bwplot help page. The online version at http://stat.ethz.ch/R-manual/R-devel/library/lattice/html/panel.bwplot.html says pch=| is treated specially, by replacing the dot with a line ... S Ellison *** This email and any attachments are confidential. Any use, copying or disclosure other than by the intended recipient is unauthorised. If you have received this message in error, please notify the sender immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com and delete this message and any copies from your computer and network. LGC Limited. Registered in England 2991879. Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK [[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] splitting dataset based on variable and re-combining
Why not use an indicator variable? P1 - ... # prediction from model 1 (Setosa) for entire dataset P2 - ... # prediction from model 2 for entire dataset I - Species==setosa # Predictions - P1 * I + P2 * ( 1 - I ) On Monday, December 10, 2012, Brian Feeny wrote: I have a dataset and I wish to use two different models to predict. Both models are SVM. The reason for two different models is based on the sex of the observation. I wish to be able to make predictions and have the results be in the same order as my original dataset. To illustrate I will use iris: # Take Iris and create a dataframe of just two Species, setosa and versicolor, shuffle them data(iris) iris - iris[(iris$Species==setosa | iris$Species==versicolor),] irisindex - sample(1:nrow(iris), nrow(iris)) iris - iris[irisindex,] # Make predictions on setosa using the mySetosaModel model, and on versicolor using the myVersicolorModel: predict(mySetosaModel, iris[iris$Species==setosa,]) predict(myVersicolorModel, iris[iris$Species==versicolor,]) The problem is this will give me a vector of just the setosa results, and then one of just the versicolor results. I wish to take the results and have them be in the same order as the original dataset. So if the original dataset had: Species setosa setosa versicolor setosa versicolor setosa I wish for my results to have: prediction for setosa prediction for setosa prediction for versicolor prediction for setosa prediction for versicolor prediction for setosa But instead, what I am ending up with is two result sets, and no way I can think of to combine them. I am sure this comes up alot where you have a factor you wish to split your models on, say sex (male vs. female), and you need to present the results back so it matches to the order of the orignal dataset. I have tried to think of ways to use an index, to try to keep things in order, but I can't figure it out. Any help is greatly appreciated. Brian __ R-help@r-project.org javascript:; 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] lattice question: how to change the dot on boxplot to line
Hi Try this (Deepayan gave me this in reply to a similar question several years ago) bwplot(voice.part ~ height, data=singer, xlab=Height (inches),pch = |, panel = function(x, y, ...) { panel.bwplot(x, y, ...) meds - tapply(x, y, median) ylocs - seq_along(meds) panel.segments(meds, ylocs - 1/4, meds, ylocs + 1/4, lwd = 2, col = red) }) I have made the colour red as one of the lines overlays the box. It gets a bit more involved with panel functions and horizontal - try this DF - data.frame(site = factor(rep(1:5, each = 20)), height = rnorm(100)) bwplot(height~ site,DF, pch = |, panel = function(x, y, ..., horizontal) { panel.bwplot(x, y, ..., horizontal = horizontal) if (horizontal) { meds - tapply(x, y, median) ylocs - seq_along(meds) panel.segments(meds, ylocs - 1/4, meds, ylocs + 1/4, lwd = 2, col = red) } else { meds - tapply(y, x, median) xlocs - seq_along(meds) panel.segments(xlocs - 1/4, meds, xlocs + 1/4, meds, lwd = 2, col = red) } ## if (horizontal) } ## panel function ) ## bwplot Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 13:03 11/12/2012, you wrote: Hi, How does one change the dot for the median in a boxplot drawn using lattice? I have been looking at names(trellis.par.get()) [1] grid.pars fontsize background [4] panel.background clip add.line [7] add.text plot.polygon box.dot [10] box.rectangle box.umbrella dot.line [13] dot.symbolplot.line plot.symbol [16] reference.linestrip.background strip.shingle [19] strip.border superpose.linesuperpose.symbol [22] superpose.polygon regions shade.colors [25] axis.line axis.text axis.components [28] layout.heightslayout.widths box.3d [31] par.xlab.text par.ylab.text par.zlab.text [34] par.main.text par.sub.text I tried playing around with dot.line and dot.symbol but could not figure out what to do. Is there anything else I could try. As a reproducible example, we can consider: library(lattice) bwplot(voice.part ~ height, data=singer, xlab=Height (inches)) I want the dots for the medians to be replaced by a line through the median. Any suggestions? Many thanks, Ranjan PS; Also, how do I get the rectangles to be filled? I tried the following: box.rectangle - trellis.par.get(box.rectangle) box.rectangle$fill-opaque (also tried filled, shaded, etc. to no avail) trellis.par.set(box.rectangle, box.rectangle) but get errors in plotting. Many thanks again and best wishes, Ranjan FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ 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] Writing escaped unicode
I'd like to write unicode strings using the \u escape syntax. According to the documentation, print.default or encodeString will escape unicode using the \u convention. In practice, I can't make it work. b=Unicode character: \ufffd print.default(b) [1] Unicode character: � encodeString(b) [1] Unicode character: � I want to write the string back out in the same escape formatting as I read it in. This is because I'm interfacing with some Ruby code that requires unicode to be in this escaped format. Thanks in advance! __ 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] Removing named objects using rm(..)
You may find it more reliable to define an environment in which you will be storing your data (perhaps globalenv(), perhaps something created by new.env()) and then testing for existence of a dataset by a given name in that environment. I did that. PAIR.ENV - new.env() get(USDCHF, env=PAIR.ENV) returns trhe USDCHF defined in timeSeries This is very hard! Worik Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Worik R Sent: Monday, December 10, 2012 5:47 PM To: Duncan Murdoch Cc: r-help Subject: Re: [R] Removing named objects using rm(..) On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 12-12-10 7:33 PM, Worik R wrote: Let me restate my question. Is there a straightforward way of ensuring I can use the variable name USDCHF? You can use any legal variable name. The only risk is that you will overwrite some other variable that you created. You can't overwrite variables from packages. (You might mask them, but they are still accessible using the :: notation. E.g. after you set USDCHF - NULL Exactly. I got around this by assigning NULL to the variable names that I would have deleted. Then instead of testing for existence I tested for NULL. you can still access the one in timeSeries using timeSeries::USDCHF Christ. That is what I wanted to delete. I read the scoping section of R-Lang (again) and nothing I could see prepared me for the shock of... library(timeSeries) nrow(USDCHF) [1] 62496 rm(USDCHF) Warning message: In rm(USDCHF) : object 'USDCHF' not found nrow(USDCHF) [1] 62496 The message from rm was that USDCHF did not exist. But I can still access its properties with nrow. This is very broken. I would not have believed I would see that in the 21st century with a modern language. (Oh wait, there is Javascript and PHP, so in comparison R is not that broken) I am not new to R, I have been (mis)using it for 5 years. I love aspects of R, but this and a few other things (lack of debugging support and ignoring the principle of least surprise are two biggies) are very frustrating. Without debugging support or more help from the compiler (like a cannot rm EURCHF message instead of a lie) R causes as many problems as it solves. Sigh. Thanks for the help. 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] Removing named objects using rm(..)
What about putting your objects in a list, which does not have the search through parents semantics? --- 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. Worik R wor...@gmail.com wrote: You may find it more reliable to define an environment in which you will be storing your data (perhaps globalenv(), perhaps something created by new.env()) and then testing for existence of a dataset by a given name in that environment. I did that. PAIR.ENV - new.env() get(USDCHF, env=PAIR.ENV) returns trhe USDCHF defined in timeSeries This is very hard! Worik Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Worik R Sent: Monday, December 10, 2012 5:47 PM To: Duncan Murdoch Cc: r-help Subject: Re: [R] Removing named objects using rm(..) On Tue, Dec 11, 2012 at 2:27 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 12-12-10 7:33 PM, Worik R wrote: Let me restate my question. Is there a straightforward way of ensuring I can use the variable name USDCHF? You can use any legal variable name. The only risk is that you will overwrite some other variable that you created. You can't overwrite variables from packages. (You might mask them, but they are still accessible using the :: notation. E.g. after you set USDCHF - NULL Exactly. I got around this by assigning NULL to the variable names that I would have deleted. Then instead of testing for existence I tested for NULL. you can still access the one in timeSeries using timeSeries::USDCHF Christ. That is what I wanted to delete. I read the scoping section of R-Lang (again) and nothing I could see prepared me for the shock of... library(timeSeries) nrow(USDCHF) [1] 62496 rm(USDCHF) Warning message: In rm(USDCHF) : object 'USDCHF' not found nrow(USDCHF) [1] 62496 The message from rm was that USDCHF did not exist. But I can still access its properties with nrow. This is very broken. I would not have believed I would see that in the 21st century with a modern language. (Oh wait, there is Javascript and PHP, so in comparison R is not that broken) I am not new to R, I have been (mis)using it for 5 years. I love aspects of R, but this and a few other things (lack of debugging support and ignoring the principle of least surprise are two biggies) are very frustrating. Without debugging support or more help from the compiler (like a cannot rm EURCHF message instead of a lie) R causes as many problems as it solves. Sigh. Thanks for the help. 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. __ 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] Removing named objects using rm(..)
On Tue, Dec 11, 2012 at 7:49 PM, Jeff Newmiller jdnew...@dcn.davis.ca.uswrote: What about putting your objects in a list, which does not have the search through parents semantics? --- You may find it more reliable to define an environment in which you will be storing your data (perhaps globalenv(), perhaps something created by new.env()) and then testing for existence of a dataset by a given name in that environment. Both interesting ideas. Turns out I can remove 'timeSeries' so that solves my problem but does not answer my questions. thanks for your help 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.
[R] Bayes weighted regression?
Dear List, Just wondering, is there a Bayesian version of weighted regression available in the literature (to handle survey weights, say)? If yes, could you suggest me a reference? Does MCMCregress handle weights? cheers, Ehsan __ 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] How do you use agrep inside a loop
Hi all. This is my first message at R-help...so I'm hoping I have some beginner's luck and get some good help for my problem! FYI I have just started using R recently so my knowledge of R is pretty preliminary. Okay here is what I need help with - I need to know how to use agrep in a for loop. I need to compare elements of a vector of names with other elements of the same vector. However if I use something like this: for(i in 1:length(test1)-1) { for(j in i+1:length(test1)) { result[[i]][j] - agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE, max.distance = 0.1) } } I get an error message saying - invalid 'pattern' argument. -* Error in agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE, max.distance = 0.1) : * * invalid 'pattern' argument* Test 1 being - c(Vashi, Vashi,navi Mumbai, Thane, Vashi,new Mumbai, Thana, Surekha, Thane(w), surekhaN) This is the first time I'm using agrep, I do not understand how it works fully... Kindly help... Thank you. Su. [[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 do you use agrep inside a loop
Hi, There is a mistake in the first line. It should be: for(i in 1:(length(test1)-1)) Regards, Pascal Le 11/12/2012 16:01, surekha nagabhushan a écrit : Hi all. This is my first message at R-help...so I'm hoping I have some beginner's luck and get some good help for my problem! FYI I have just started using R recently so my knowledge of R is pretty preliminary. Okay here is what I need help with - I need to know how to use agrep in a for loop. I need to compare elements of a vector of names with other elements of the same vector. However if I use something like this: for(i in 1:length(test1)-1) { for(j in i+1:length(test1)) { result[[i]][j] - agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE, max.distance = 0.1) } } I get an error message saying - invalid 'pattern' argument. -* Error in agrep(test1[i], test1[j], ignore.case = TRUE, value = TRUE, max.distance = 0.1) : * * invalid 'pattern' argument* Test 1 being - c(Vashi, Vashi,navi Mumbai, Thane, Vashi,new Mumbai, Thana, Surekha, Thane(w), surekhaN) This is the first time I'm using agrep, I do not understand how it works fully... Kindly help... Thank you. Su. [[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.