Re: [R] need help combining two datasets
Adam D. I. Kramer ilovebacon.org> writes: > > You probably want the merge function. > > ?merge > > On Wed, 28 Jan 2009, Somani, Dinesh K wrote: > > > I have two CSV files, one with daily stock returns using method A {date, > > stock, returnA, some uninteresting columns}, and another with method B > > {date, stock, returnB, more columns}. Both have different sets of stocks. > > > > I want to combine the two into a single data table, so that I can run some > > analyses for the overlapping date ranges and stocks. I know how to do > > this using a database but is there an equivalent way to perform a similar > > kind of join in R? I think the merge function will not do it here, because he has different sets of stock. I would suggest the following -- Read in A.CSV and B.CSV into data frames a and b -- Remove uninteresing columns -- a$method = 'a' -- b$method = 'b' -- rename column returnA and return B to "return" -- rbind(a,b) Dieter __ 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] Please Help for Augmented Prediction Plot
Chun-Hao Tu hotmail.com> writes: > Hi R users,I have a question about augmented prediction plot (?augPred). > The covariate of my data set is c(0, 0.01, 0.1, 1, 10, 100, 1000) and I > have fitted a nonlinear mixed effects model. I use > plot(augPred(out.nlme)) to get the augmented prediction plot. However, > because the scale of the covariate is too large thus I am not able to see > the detail difference at c(0,0.01, 0.1, and 1). Could anyone > tell me how to enlarge the plot at that range "c(0,0.01, 0.1, and 1)" ? Very, very likely, if you have such a large range (frequently a drug dose), you should think of doing a (shifted log?) transform of your data initially. Try to do a residual plot plot(result(nlme)) might work first to check for this. Maybe even plotting (0.001,0.01,...) would be more useful. Otherwise, you could always use pred() manually and do a trellis plot with some (log+x) transformed data. Dieter __ 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] Create a vector from matrix.
Hi all, I am trying to create a vector with the information contained in a determined matrix. Let me explain myself. I have a vector like this: q <- c("a","a","c","b","d","d","a","e","b","a") And a matrix like: s1 <- c("a","b","c","d","e","f","g","h","i","j") e <- c("A","B","C","D","E","F","G","H","I","J") s <- cbind( e, s1 ) The matrix s contains the correspondences between vector q and e. And I want a vector of elements of vector e, but in the order of q. The result should be like: q <- c ("a","a","c","b","d","d","a","e","b","a") res<-c ("A","A","C","B","D","E","A","E","B","A") So I have to take the elements of vector e and make a matching with elements in vector q. Any idea?Sorry If I didn't explain myself well. Thanks Patricia _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can I create a timeDate object using only year and week of the year values?
"TB" == Ted Byers on Tue, 27 Jan 2009 11:36:22 -0500 TB> What I have found so far includes: TB> TB> library(Rmetrics) TB> time1 = timeDate(charvec = Sys.Date(), format = %Y-%m-%d, TB> zone = , TB> FinCenter = ) TB> time2 = timeDate(2004-08-30, format = %Y-%m-%d, zone = , TB> FinCenter = TB> ) TB> difftimeDate(time1,time2,units = weeks) TB> TB> TB> Does timeDate use the format strings used by the UNIX date(1) TB> command? If TB> so, then can I safely assume timeDate will accept %Y-%U-%w, TB> and behave TB> correctly? Hi Ted, timeDate uses internally the function 'strptime' to convert the input charvec to the ISO time format. As pointed out in the the manual page of 'strptime', the formats are system-specific but should follow the ISO C / POSIX standard. Have a look at ?strptime. Hope this help, Yohan -- PhD student Swiss Federal Institute of Technology Zurich www.ethz.ch __ 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] Create a vector from matrix.
try this: s1 <- letters[1:10] e <- LETTERS[1:10] q <- c("a","a","c","b","d","d","a","e","b","a") e[match(q, s1)] I hope it helps. Best, Dimitris patricia garcía gonzález wrote: Hi all, I am trying to create a vector with the information contained in a determined matrix. Let me explain myself. I have a vector like this: q <- c("a","a","c","b","d","d","a","e","b","a") And a matrix like: s1 <- c("a","b","c","d","e","f","g","h","i","j") e <- c("A","B","C","D","E","F","G","H","I","J") s <- cbind( e, s1 ) The matrix s contains the correspondences between vector q and e. And I want a vector of elements of vector e, but in the order of q. The result should be like: q <- c ("a","a","c","b","d","d","a","e","b","a") res<-c ("A","A","C","B","D","E","A","E","B","A") So I have to take the elements of vector e and make a matching with elements in vector q. Any idea?Sorry If I didn't explain myself well. Thanks Patricia _ [[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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ 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] Mystery Error in midnightStandard
"TB" == Ted Byers on Tue, 27 Jan 2009 16:00:27 -0500 TB> I wasn't even aware I was using midnightStandard. You won't TB> find it in my TB> script. TB> TB> Here is the relevant loop: TB> TB> date1 = timeDate(charvec = Sys.Date(), format = %Y-%m-%d) TB> date1 TB> dow = 3; TB> for (i in 1:length(V4) ) { TB> x = read.csv(as.character(V4[[i]]), header = FALSE, TB> na.strings=); TB> y = x[,1]; TB> year = V2[[i]]; TB> week = V3[[i]]; TB> dtstr = sprintf(%i-%i-%i,year,week,dow); TB> date2 = timeDate(dtstr, format = %Y-%U-%w); TB> resultsdataframe[[i]] <- difftimeDate(date1,date2,units = TB> weeks); TB> fp = fitdistr(y,exponential); TB> print(c(V1[[i]],V2[[i]],V3[[i]],fp,fp)); TB> print(c(year,week,date2,resultsdataframe[[i]])); TB> resultsdataframe[[i]] <- fp; TB> resultsdataframe[[i]] <- fp; TB> } TB> TB> It fails with a little more than 100 records left in V4. TB> TB> The full error message is: TB> TB> Error in midnightStandard(charvec, format) : TB> 'charvec' has non-NA entries of different number of characters timeDate() uses the midnight standard. The function 'midnightStandard' assumes that all entries in 'charvec' have the same 'format'. Can you please check if this is the case? This is all I can say from the information you provided. Please give us a reproducible example. We can continue this discussion off-list. regards, Yohan TB> TB> Until it fails, date2 and resultsdataframe[[i]] get correct TB> values. TB> TB> str() produces no surprises: TB> TB> > str(resultsdataframe); TB> 'data.frame': 303 obs. of 6 variables: TB> $ mid : int 171 206 206 206 206 206 206 206 206 218 ... TB> $ year : int 2008 2008 2008 2008 2008 2008 2008 2008 2008 TB> 2008 ... TB> $ week : int 16 17 18 19 21 26 31 35 51 40 ... TB> $ dt : num 39.9 38.9 37.9 36.9 34.9 ... TB> $ estimate: num Inf 0.25 Inf 0.0408 0.2 ... TB> $ sd : num Inf 0.1768 Inf 0.0289 0.1414 ... TB> TB> I would assume the error is related to my new code that TB> manipulates dates, TB> as it doesn't occur in the earlier version that did not TB> manipulate dates TB> (the relevant work being done, albeit very slowly, within TB> the DB). TB> TB> FTR: The year and week values are generated by MySQL using TB> the YEAR and WEEK TB> functions applied to timestamps. I do not know if it is TB> relevant, but the TB> week value, at the point of failure, is 0 (a value that does TB> not occur TB> earlier in the dataset, but several times subsequently), TB> and I do not see TB> how a value of 0 for the week (legitimate in posix date TB> formats) could TB> produce the error message I get. TB> TB> Any thoughts on what is really wrong, and how to fix it? TB> TB> Thanks TB> TB> Ted -- PhD student Swiss Federal Institute of Technology Zurich www.ethz.ch __ 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] for/if loop
Hi, it's my first time to write a loop with R for my homework. This loop is part of the function. I wanna assign values for hll according to panel [ii,1]=pp. I didn't get any error message in this part. but then when I further calculate another stuff with hll, the function can't return. I think it must be some problem in my loop. Probably something stupid or easy. But I tried to look for previous posts in forum and read R language help. But none can help.. Thanks! for (ii in 1:100){ for (pp in 1:pp+1){ for (rr in 1:rr+1){ if (panel[ii,1]!=pp) { hll(pp,1)=ColSums(lselb1(rr:ii-1,1)) hll(pp,2)=ColSums(lselb2(rr:ii-1,1)) rr=ii pp=pp+1 } else { hll(pp,1)=ColSums(lselb1(rr:ii,1)) hll(pp,2)=ColSums(lselb2(rr:ii,1)) rr=ii pp=pp+1} } }}} in fact I have the corresponding Gauss code here. But I really don't know how to write such loop in R. rr=1; ii=1; pp=1; do until ii==n+1; if pan[ii,1] ne pp; hll[pp,1]=sumc(lselb1[rr:ii-1,1]); hll[pp,2]=sumc(lselb2[rr:ii-1,1]); rr=ii; pp=pp+1; endif; if ii==n; hll[pp,1]=sumc(lselb1[rr:ii,1]); hll[pp,2]=sumc(lselb2[rr:ii,1]); rr=ii; pp=pp+1; endif; ii=ii+1; endo; -- View this message in context: http://www.nabble.com/for-if-loop-tp21701496p21701496.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] Create a vector from matrix.
Thanks Dimitris, But I wrote the example with letters just for you to understand the problem, actually the elements of matrix and vector contains characters, numbers of whatever. I need an algorithm to work in any case, whatever the elements are. I am not sure If I explained myself, if not, tell me please. Regards Patricia > Date: Wed, 28 Jan 2009 10:56:32 +0100 > From: d.rizopou...@erasmusmc.nl > To: kurtney...@hotmail.com > CC: r-h...@stat.math.ethz.ch > Subject: Re: [R] Create a vector from matrix. > > try this: > > s1 <- letters[1:10] > e <- LETTERS[1:10] > q <- c("a","a","c","b","d","d","a","e","b","a") > > e[match(q, s1)] > > > I hope it helps. > > Best, > Dimitris > > > patricia garcía gonzález wrote: > > Hi all, > > > > I am trying to create a vector with the information contained in a > > determined matrix. Let me explain myself. I have a vector like this: > > > > q <- c("a","a","c","b","d","d","a","e","b","a") > > > > And a matrix like: > > > > s1 <- c("a","b","c","d","e","f","g","h","i","j") > > e <- c("A","B","C","D","E","F","G","H","I","J") > > s <- cbind( e, s1 ) > > > > > > The matrix s contains the correspondences between vector q and e. And I > > want a vector of elements of vector e, but in the order of q. The result > > should be like: > > > > q <- c ("a","a","c","b","d","d","a","e","b","a") > > > > res<-c ("A","A","C","B","D","E","A","E","B","A") > > > > So I have to take the elements of vector e and make a matching with > > elements in vector q. Any idea?Sorry If I didn't explain myself well. > > > > Thanks > > > > Patricia > > > > > > > > _ > > > > > > [[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. > > > > -- > Dimitris Rizopoulos > Assistant Professor > Department of Biostatistics > Erasmus Medical Center > > Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands > Tel: +31/(0)10/7043478 > Fax: +31/(0)10/7043014 > _ [[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] 3-axis Barplots (plus qplot like staked histogram capability)
Hi Jason, lattice, with the help of the latticeExtra package does excellent "business"-like 3D bars. With devices like PDF that handle transparency you can make the facets transparent. library(lattice) library(latticeExtra) ?panel.3dbars ## Example from the help file (modified to show alpha channel capab.) cloud(VADeaths, panel.3d.cloud = panel.3dbars, xbase = 0.4, ybase = 0.4, screen = list(z = 40, x=-60), col.facet="grey", alpha.facet=.5) Regards, Mark. Jason Rupert wrote: > > I very much appreciate the links, especially the one to > http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=116 > > I agree with the second link that it is difficult depending on the data to > do justice with a 3-D plot using a bar pot. The point of the plot is not > to present the full quantitative picture, but just one piece of it. > > If there is something that produces a little bit better graphics than > those from the scatterplot approach that would be great. It would be > great if I could do a "surf" plot from the data, but unfortunately a lot > of it is discrete, e.g. location. > > I guess this may just not be possible, but just thought I would check. > Thanks again. > > > --- On Tue, 1/27/09, Jorge Ivan Velez wrote: > From: Jorge Ivan Velez > Subject: Re: [R] 3-axis Barplots (plus qplot like staked histogram > capability) > To: jasonkrup...@yahoo.com > Date: Tuesday, January 27, 2009, 5:13 PM > > > Dear Jason, > For the 3D barplot take a look at > http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=116 > > but also at > > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/27575.html > > > > HTH, > > Jorge > > > > > > On Tue, Jan 27, 2009 at 6:03 PM, Jason Rupert > wrote: > > Searched my R reference docs*, and the Rseek, but evidently I've > overlooked this capabilty. > > > > Is it possible to produce a 3d Barplot using R? > > > > For example would like to have a three axis bar plot - \ > > x-axis = location(discrete), > > y-axis = data value, > > z-axis = frequency of value occurance (of location and value) > > > > Would also if could also do something like what "qplot" allows, i.e. doing > stacked histograms. I would like the "staked" histogram values to show > age. > > > > Thanks for any feedback and insight that can be provided. > > > > * Amongst many others, thanks to : > > (1) Statistics with R, Vincent Zoonekynd, > > (2) An Introduction to R: Software for StatisticalModelling & Computing > > > > > > > > [[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. > > -- View this message in context: http://www.nabble.com/3-axis-Barplots-%28plus-qplot-like-staked-histogram-capability%29-tp21696521p21702931.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] Create a vector from matrix.
OK Dimitris, you where right. Thank you. Regards > From: kurtney...@hotmail.com > To: d.rizopou...@erasmusmc.nl > Date: Wed, 28 Jan 2009 10:02:06 + > CC: r-h...@stat.math.ethz.ch > Subject: Re: [R] Create a vector from matrix. > > > Thanks Dimitris, > > But I wrote the example with letters just for you to understand the problem, > actually the elements of matrix and vector contains characters, numbers of > whatever. I need an algorithm to work in any case, whatever the elements are. > > I am not sure If I explained myself, if not, tell me please. > > Regards > > Patricia > > > > Date: Wed, 28 Jan 2009 10:56:32 +0100 > > From: d.rizopou...@erasmusmc.nl > > To: kurtney...@hotmail.com > > CC: r-h...@stat.math.ethz.ch > > Subject: Re: [R] Create a vector from matrix. > > > > try this: > > > > s1 <- letters[1:10] > > e <- LETTERS[1:10] > > q <- c("a","a","c","b","d","d","a","e","b","a") > > > > e[match(q, s1)] > > > > > > I hope it helps. > > > > Best, > > Dimitris > > > > > > patricia garcía gonzález wrote: > > > Hi all, > > > > > > I am trying to create a vector with the information contained in a > > > determined matrix. Let me explain myself. I have a vector like this: > > > > > > q <- c("a","a","c","b","d","d","a","e","b","a") > > > > > > And a matrix like: > > > > > > s1 <- c("a","b","c","d","e","f","g","h","i","j") > > > e <- c("A","B","C","D","E","F","G","H","I","J") > > > s <- cbind( e, s1 ) > > > > > > > > > The matrix s contains the correspondences between vector q and e. And I > > > want a vector of elements of vector e, but in the order of q. The result > > > should be like: > > > > > > q <- c ("a","a","c","b","d","d","a","e","b","a") > > > > > > res<-c ("A","A","C","B","D","E","A","E","B","A") > > > > > > So I have to take the elements of vector e and make a matching with > > > elements in vector q. Any idea?Sorry If I didn't explain myself well. > > > > > > Thanks > > > > > > Patricia > > > > > > > > > > > > _ > > > > > > > > > [[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. > > > > > > > -- > > Dimitris Rizopoulos > > Assistant Professor > > Department of Biostatistics > > Erasmus Medical Center > > > > Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands > > Tel: +31/(0)10/7043478 > > Fax: +31/(0)10/7043014 > > > > _ > > > [[alternative HTML version deleted]] > _ [[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] Faced Problems with RODBC package 1.2-5 and 1.2-4 for windows
Hi, I am facing problems with RODBC package 1.2-5 and 1.2-4 built for windows. I am using R 2.8.1 version. I faced some problems when I was trying to execute sql procedure from R with exec/execute statement . Stored procedure contains code/statements : 1) Call to another procedure (R calls one procedure which itself calls another procedure) 2) Iteration (while loop) I created stored procedure in which I used while loop and while loop contains two insert statements.I executed procedure from R. I found that expected results are not matching with the results I got. Also results are not consistent. 3) SET QUOTED_IDENTIFIER OFF statement Please give me a solution regards, Nikhil Ashok Bhide Cell:- +919604848030 Mailto: nikhil.bh...@tcs.com Website: http://www.tcs.com Experience certainty. IT Services Business Solutions Outsourcing ForwardSourceID:NT1B0E =-=-= Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you [[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] evaluation revisited
The argument to eval.parent is evaluated before eval.parent ever sees it. Try issuing this command before you run your code: debug(eval.parent) and look at the value of the arguments as passed to eval.parent in the debugger. On Wed, Jan 28, 2009 at 2:29 AM, wrote: > I'm still going over old emails and trying to get my head around evaluation > so I'm persistent if nothing else. > > A while back , an expert sent me below as an exercise in understanding and > I only got around to it tonight. I understand some of the output but not all > of it and I put "Why not Zero ?" next to the ones that I don't understand > based on my reading of the various functions in the help pages. It's either > my reading comprehension or the evaluation subtleties in R but I just can't > understand some of them. If any of the expeRts has time to explain the ones > that I marked with "WHY NOT ZERO ?", it would be much appreciated. > Obviously, I don't expect a long explanation but I think my problem is that > I keep thinking that eval.parent and eval(whatever, parent.frame) go back to > the function that called with.options so f() and do the evaluation in there > but that doesn't always seem to be the case. I'm also not so clear on the > difference between print(x) and L[[len]]. Thanks a lot in advance to anyone > who can be bothered with below. > > with.options <- function(...) { > L <- as.list(match.call())[-1] > len <- length(L) > print(L) > > eval.parent(L[[len]]) # =0 MAKES SENSE > eval(L[[len]]) # =1 MAKES SENSE > eval(L[[len]],parent.frame()) # =0 MAKES SENSE > eval.parent(print(x)) # =1 WHY NOT ZERO ? Somehow this is different > from eval.parent(L[[len]]) > eval(print(x)) # =1 MAKES SENSE > eval(print(x),parent.frame()) # =1 # WHY NOT ZERO ? Somehow this is > different from eval(L[[len]],parent.frame) > evalq(print(x)) # =1 MAKES SENSE > evalq(print(x),parent.frame()) # =1 MAKES SENSE > print("") > > x <- 2 > > eval.parent(L[[len]]) # =0 MAKES SENSE > eval(L[[len]]) # =2 MAKES SENSE > eval(L[[len]],parent.frame()) # =0 MAKES SENSE > eval.parent(print(x)) # =2 WHY NOT ZERO ? Somehow this is different from > eval.parent(L[[len]]) > eval(print(x)) # 2 MAKES SENSE > eval(print(x),parent.frame()) # 2 WHY NOT ZERO ? Somehow this is different > from eval(L[[len]], parent.frame) > evalq(print(x)) # 2 MAKES SENSE > evalq(print(x),parent.frame()) # 1 WHY NOT ZERO ? > print("") > > } > > x <- 1 > > f <- function() { > x <- 0 > with.options(width = 40, print(x)) > } > > f() > > __ > 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] t.test in a loop
Hi All, I've been having a little trouble with creating a loop that will run a a series of t.tests for inspection, Below is the code i've tried, and some checks i've looked at. I've used the get(paste()) idea as i was told previously that the use of the eval should try and be avoided. I've run a single syntax to check that my systax is correct and works without any problems > t.test(channel.data.train$News~channel.data.train$power) Can anyone offer any advice? Many thanks Mike > str(channel.data.train$power) num [1:9913] 0 0 0 0 0 0 0 0 0 0 ... > summary(channel.data.train$power) Min. 1st Qu. MedianMean 3rd Qu.Max. 0. 0. 0. 0.2368 0. 1. > names(channel.data.train) [1] "News" "Entertainment" "Communicate" [4] "Lifestyle" "Games" "Music" [7] "Money" "Celebrity" "Shopping" [10] "Sport" "Film" "Travel" [13] "Cars" "Property" "Chat" [16] "Bet.Play.Win" "config""exposed" [19] "site" "referrer" "started" [22] "last_viewed" "num_views" "secs_since_viewed" [25] "register" "secs.na" "power" [28] "tt" > for(i in names(channel.data.train[,c(1:16)])){ + t.test(get(paste("channel.data.train$",i,"~channel.data.train$power",sep=""))) + } Error in get(paste("channel.data.train$", i, "~channel.data.train$power", : variable "channel.data.train$News~channel.data.train$power" was not found -- Michael Pearmain Senior Analytics Research Specialist Google UK Ltd Belgrave House 76 Buckingham Palace Road London SW1W 9TQ United Kingdom t +44 (0) 2032191684 mpearm...@google.com If you received this communication by mistake, please don't forward it to anyone else (it may contain confidential or privileged information), please erase all copies of it, including all attachments, and please let the sender know it went to the wrong person. 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] evaluation revisited
Gabor Grothendieck wrote: > The argument to eval.parent is evaluated before eval.parent > ever sees it. really? eval.parent is just a regular r function, a wrapper for eval with envir=parent.frame(). the arguments to eval.parent are passed to eval *unevaluated* (as promises), and are only evaluated when eval needs them. here's a modified eval.parent: my.eval.parent = function(expr, n=1) { print('foo') p = parent.frame(n+1) eval(expr, p) } my.eval.parent({print(1); 2}) # prints 'foo' before printing 1 and returning 2 > Try issuing this command before you run your > code: > > debug(eval.parent) > > and look at the value of the arguments as passed to eval.parent > in the debugger. > well, when you are in the debugger and look at the value of the arguments you actually force the promises, so no wonder you see them evaluated. if you don't look at them, they're not evaluated: trace(eval) trace(parent.frame) eval.parent({print(1);2}) # calling parent.frame # calling eval # printing 1 (after parent.frame and eval have been called) # returning 2 vQ __ 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] evaluation revisited
Wacek Kusnierczyk wrote: > Gabor Grothendieck wrote: > >> The argument to eval.parent is evaluated before eval.parent >> ever sees it. >> > > really? eval.parent is just a regular r function, a wrapper for eval > with envir=parent.frame(). the arguments to eval.parent are passed to > eval *unevaluated* (as promises), and are only evaluated when eval needs > them. to be strict, the argument n to eval.parent is not further passed to eval, and is evaluated before eval is called. the above referred to the 'expr' argument to eval.parent. one more example: my.eval.parent = function(expr, n=1) { print('foo') p = parent.frame(n+1) eval(expr, p) } trace(eval) my.eval.parent({print('expr'); 1}, {print('n'); 1}) # "foo" # "n" # trace eval(expr, p) # "expr" # 1 vQ __ 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] for/if loop
What are you trying to do with > for (pp in 1:pp+1){ ? Also, note that 1:rr+1 and 1:(rr+1) mean different things. Zhou __ 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] t.test in a loop
On Wed, 28 Jan 2009, Michael Pearmain wrote: Hi All, I've been having a little trouble with creating a loop that will run a a series of t.tests for inspection, Below is the code i've tried, and some checks i've looked at. I've used the get(paste()) idea as i was told previously that the use of the eval should try and be avoided. I've run a single syntax to check that my systax is correct and works without any problems t.test(channel.data.train$News~channel.data.train$power) Can anyone offer any advice? There's the additional problem that if your code worked it would do 16 t-tests but only report the last one. Assuming you want them printed for(v in names(channel.data.train)[1:16]) { print(v) print(t.test(channel.data.train[[v]]~channel.data.train$power) } or for(v in names(channel.data.train)[1:16]){ test <- eval(bquote(.(v)~power, data=channel.data.train) print(eval(test)) } This sort of use of eval is fairly harmless. -thomas Many thanks Mike str(channel.data.train$power) num [1:9913] 0 0 0 0 0 0 0 0 0 0 ... summary(channel.data.train$power) Min. 1st Qu. MedianMean 3rd Qu.Max. 0. 0. 0. 0.2368 0. 1. names(channel.data.train) [1] "News" "Entertainment" "Communicate" [4] "Lifestyle" "Games" "Music" [7] "Money" "Celebrity" "Shopping" [10] "Sport" "Film" "Travel" [13] "Cars" "Property" "Chat" [16] "Bet.Play.Win" "config""exposed" [19] "site" "referrer" "started" [22] "last_viewed" "num_views" "secs_since_viewed" [25] "register" "secs.na" "power" [28] "tt" for(i in names(channel.data.train[,c(1:16)])){ + t.test(get(paste("channel.data.train$",i,"~channel.data.train$power",sep=""))) + } Error in get(paste("channel.data.train$", i, "~channel.data.train$power", : variable "channel.data.train$News~channel.data.train$power" was not found -- Michael Pearmain Senior Analytics Research Specialist Google UK Ltd Belgrave House 76 Buckingham Palace Road London SW1W 9TQ United Kingdom t +44 (0) 2032191684 mpearm...@google.com If you received this communication by mistake, please don't forward it to anyone else (it may contain confidential or privileged information), please erase all copies of it, including all attachments, and please let the sender know it went to the wrong person. 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. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ 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] putting match.call to good use
__ 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] for/if loop
Within the loops you are changing the loop variables (pp & rr). Why are you doing this? THis might be causing your problem of what sounds like an infinite loop. You probably want to rethink what you are trying to do in the loop. On Wed, Jan 28, 2009 at 3:21 AM, SnowManPaddington wrote: > > Hi, it's my first time to write a loop with R for my homework. This loop is > part of the function. I wanna assign values for hll according to panel > [ii,1]=pp. I didn't get any error message in this part. but then when I > further calculate another stuff with hll, the function can't return. I think > it must be some problem in my loop. Probably something stupid or easy. But I > tried to look for previous posts in forum and read R language help. But none > can help.. Thanks! > > > > for (ii in 1:100){ >for (pp in 1:pp+1){ >for (rr in 1:rr+1){ >if (panel[ii,1]!=pp) >{ >hll(pp,1)=ColSums(lselb1(rr:ii-1,1)) >hll(pp,2)=ColSums(lselb2(rr:ii-1,1)) >rr=ii >pp=pp+1 >} >else >{ >hll(pp,1)=ColSums(lselb1(rr:ii,1)) >hll(pp,2)=ColSums(lselb2(rr:ii,1)) >rr=ii >pp=pp+1} >} >}}} > > > in fact I have the corresponding Gauss code here. But I really don't know > how to write such loop in R. > > rr=1; > ii=1; > pp=1; > do until ii==n+1; >if pan[ii,1] ne pp; >hll[pp,1]=sumc(lselb1[rr:ii-1,1]); >hll[pp,2]=sumc(lselb2[rr:ii-1,1]); >rr=ii; >pp=pp+1; >endif; >if ii==n; >hll[pp,1]=sumc(lselb1[rr:ii,1]); >hll[pp,2]=sumc(lselb2[rr:ii,1]); >rr=ii; >pp=pp+1; >endif; >ii=ii+1; > endo; > > -- > View this message in context: > http://www.nabble.com/for-if-loop-tp21701496p21701496.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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] evaluation revisited
On Wed, Jan 28, 2009 at 6:26 AM, Wacek Kusnierczyk wrote: > Gabor Grothendieck wrote: >> The argument to eval.parent is evaluated before eval.parent >> ever sees it. > > really? eval.parent is just a regular r function, a wrapper for eval > with envir=parent.frame(). the arguments to eval.parent are passed to > eval *unevaluated* (as promises), and are only evaluated when eval needs > them. here's a modified eval.parent: Yes, you're right about the mechanism although quoting the help page its nevertheless true that it: "evaluates its first argument in the current scope before passing it to the evaluator" __ 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] evaluation revisited
Gabor Grothendieck wrote: > On Wed, Jan 28, 2009 at 6:26 AM, Wacek Kusnierczyk > wrote: > >> Gabor Grothendieck wrote: >> >>> The argument to eval.parent is evaluated before eval.parent >>> ever sees it. >>> >> really? eval.parent is just a regular r function, a wrapper for eval >> with envir=parent.frame(). the arguments to eval.parent are passed to >> eval *unevaluated* (as promises), and are only evaluated when eval needs >> them. here's a modified eval.parent: >> > > Yes, you're right about the mechanism although quoting the > help page its nevertheless true that it: > "evaluates its first argument in the current scope before > passing it to the evaluator" > ... where 'current scope' is as clear as the sky over trondheim right now [1], the issue being: - is 'current scope' the scope in which eval (the above quote refers to eval) is called (as it seems to be meant), or - the scope *within* the call to eval (which would be intuitively obvious, since when eval 'evaluates' it must have already been entered and not yet left, so we're inside the eval-call scope). another example of how quoting an r help page helps provided you already know the answer. must admit that 'eval evaluates its argument before passing it to the evaluator' is quite funny a quote; so eval is able to evaluate without an evaluator? magic! *what* is it that is true, quoting the help page? vQ [1] http://www.yr.no/place/Norway/S%C3%B8r-Tr%C3%B8ndelag/Trondheim/Trondheim/ __ 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] Character SNP data to binary MAF data
Hi I am sure there is a function out there already but I couldn't find it. I have SNP data, that is, a matrix which contains in each row two characters (they are different in each row) and I would like to convert this matrix to a binary one according to the minor allele frequency. For non-geneticists: I want to have a binary matrix for which in each row the 0 stands for the less frequent character and 1 for the more frequent character. Thanks for any suggestions. Hadassa -- Hadassa Brunschwig PhD Student Department of Statistics The Hebrew University of Jerusalem http://www.stat.huji.ac.il __ 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] initial value in 'vmmin' is not finite
Dear r helpers I run the following code for nested logit and got a message that Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite What does this mean? and how can I correct it? Thank you June > yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)> > dim(yogurt)[1] 1278425> choice = yogurt[,2:5]> price=yogurt[,14:17]> > feature=yogurt[,6:9]> n = nrow(yogurt)> constant = rep(1,each=n)> > yop=cbind(constant,feature[,1],price[,1])> > dan=cbind(constant,feature[,2],price[,2])> > hil=cbind(constant,feature[,3],price[,3])> wt=cbind(feature[,4],price[,4])> > > fr <- function(x) { + x1 = x[1]+ x2 = x[2]+ x3 = x[3]+ x4 = x[4]+ x5 = x[5]+ > x6 = x[6]+ x7 = x[7]+ con1 = rbind(x[1],x[5],x[6])+ con2 = > rbind(x[2],x[5],x[6])+ con3 = rbind(x[3],x[5],x[6])+ con4 = rbind(x[5],x[6])+ > rho=exp(x[7])/(1+exp(x[7]))+ ey = exp((yop%*%con1)/rho)+ ed = > exp((dan%*%con2)/rho)+ eh = exp((hil%*%con3)/rho)+ ew = exp((wt%*%con4)/rho)+ > ev = ey+ed+eh+ew+ den=(ey+ed+eh+ew)+ iv = rho*log(den)+ > pp=exp(x[4]+iv)/(1+exp(x[4]+iv))+ pr1 =pp* ey/den+ pr2 =pp* ed/den+ pr3 =pp* > eh/den+ pr4 =pp* ew/den+ pnp=1/(1+exp(x[4]+iv))+ likelihood = > (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt[,! 4])+(pr4*yogurt[,4])+ lsum = log(likelihood)+ return(-colSums(lsum))+ }> p = optim(c(0,0,0,0,0.1,-2,-0.2),fr, hessian = TRUE, method = "BFGS")Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite _ [[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] putting match.call to good use
( I just became aware the mailer enforces html bodies, as such removed by the list handler. Sorry about that. My message was ) I have this function slm <- function(fun=lm, ...) { #ilm <- eval(match.call()[-1]); # no way ilm <- eval(parse(text=sub("^list", deparse(substitute(fun)), deparse(substitute(...()); ... The latter actually does the trick, but recognising how some gurus hate parse, I would like to know if this can anyhow be done with match.call, or any other reasonable solution. The issue here is that lm (and likewise glm, bayesglm, etc.) returns the function call, which needs to show up as the original args to slm of course. ~~harald e __ 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] Mystery Error in midnightStandard
Hi Yohan, Thanks. On Wed, Jan 28, 2009 at 4:57 AM, Yohan Chalabi wrote: > "TB" == Ted Byers > on Tue, 27 Jan 2009 16:00:27 -0500 > > TB> I wasn't even aware I was using midnightStandard. You won't > TB> find it in my > TB> script. > TB> > TB> Here is the relevant loop: > TB> > TB> date1 = timeDate(charvec = Sys.Date(), format = %Y-%m-%d) > TB> date1 > TB> dow = 3; > TB> for (i in 1:length(V4) ) { > TB> x = read.csv(as.character(V4[[i]]), header = FALSE, > TB> na.strings=); > TB> y = x[,1]; > TB> year = V2[[i]]; > TB> week = V3[[i]]; > TB> dtstr = sprintf(%i-%i-%i,year,week,dow); > TB> date2 = timeDate(dtstr, format = %Y-%U-%w); > TB> resultsdataframe[[i]] <- difftimeDate(date1,date2,units = > TB> weeks); > TB> fp = fitdistr(y,exponential); > TB> print(c(V1[[i]],V2[[i]],V3[[i]],fp,fp)); > TB> print(c(year,week,date2,resultsdataframe[[i]])); > TB> resultsdataframe[[i]] <- fp; > TB> resultsdataframe[[i]] <- fp; > TB> } > TB> > TB> It fails with a little more than 100 records left in V4. > TB> > TB> The full error message is: > TB> > TB> Error in midnightStandard(charvec, format) : > TB> 'charvec' has non-NA entries of different number of characters > > timeDate() uses the midnight standard. The function 'midnightStandard' > assumes that all entries in 'charvec' have the same 'format'. Can you > please check if this is the case? > It is certain that all entries have the same format, but I'm starting to think that the error message is something of a red herring. Consider this: > year = 2009 > week = 0 > day = 3 > datestr = sprintf("%i-%i-%i",year,week,day);datestr [1] "2009-0-3" > date1 = timeDate(datestr, format = "%Y-%U-%w"); > date1 GMT [1] [NA] > day = 4 > datestr = sprintf("%i-%i-%i",year,week,day);datestr [1] "2009-0-4" > date1 = timeDate(datestr, format = "%Y-%U-%w"); > date1 GMT [1] [2009-01-01] > > datestr = sprintf("%i-%i-%i",year,week,3);datestr [1] "2009-0-3" > date2 = timeDate(datestr, format = "%Y-%U-%w");date2 GMT [1] [NA] > difftimeDate(date2,date1, units = "weeks") Error in midnightStandard(charvec, format) : 'charvec' has non-NA entries of different number of characters In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf The first values for year, week and day are the values on which my loop dies. It returns 'NA' here. It seems clear that it is returning NA because the date that data corresponds to is 2008-12-31. The error is being produced by difftimeDate rather than timeDate (as shown by the above session). But that represents a flaw in the function design. It should fail when taking the elapsed time between a null and the present, but if I wrote such a function, I'd have it return null (perhaps with a warning) rather than just die. A bigger issue is that timeDate ought never give null here (which is what I assume 'NA' means), since all the data comes from transaction data with real dates, so the elapsed time, measured in weeks, ought to always be a valid real number that is positive semidefinite. I have not yet come to any conclusions as to how it ought to behave (whether to return new years day, along with a warning, or to return the date requested by reinvoking itself with the year and week adjusted so a valid date is returned). On a practical side, how would I test date2 to see if it is null, so I can give it a sensible default value? A more troubling thought is that with this handling of dates in this combination of SQL (my group by clause uses YEAR(transaction_date),WEEK(transaction_date)) to get the data and R to process it, the week containing new years day will ALWAYS be split in two at the first second of the new year. I'm going to have to either figure out a way to correct this, or ignore it (as it doesn't actually make things wrong, but rather it splits a sample into two unequal parts). Thoughts? Thanks Ted [[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] initial value in 'vmmin' is not finite
On Wed, 28 Jan 2009, June Wong wrote: Dear r helpers I run the following code for nested logit and got a message that Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite What does this mean? and how can I correct it? It means that your function at your starting values is evaluating to a non-finite value (+/-Inf, NA, NaN). Your example is unreadable, and we don't have the file so cannot help you debug this. Thank you June yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)> dim(yogurt)[1] 1278425> choice = yogurt[,2:5]> price=yogurt[,14:17]> feature=yogurt[,6:9]> n = nrow(yogurt)> constant = rep(1,each=n)> yop=cbind(constant,feature[,1],price[,1])> dan=cbind(constant,feature[,2],price[,2])> hil=cbind(constant,feature[,3],price[,3])> wt=cbind(feature[,4],price[,4])> > fr <- function(x) { + x1 = x[1]+ x2 = x[2]+ x3 = x[3]+ x4 = x[4]+ x5 = x[5]+ x6 = x[6]+ x7 = x[7]+ con1 = rbind(x[1],x[5],x[6])+ con2 = rbind(x[2],x[5],x[6])+ con3 = rbind(x[3],x[5],x[6])+ con4 = rbind(x[5],x[6])+ rho=exp(x[7])/(1+exp(x[7]))+ ey = exp((yop%*%con1)/rho)+ ed = exp((dan%*%con2)/rho)+ eh = exp((hil%*%con3)/rho)+ ew = exp((wt%*%con4)/rho)+ ev = ey+ed+eh+ew+ den=(ey+ed+eh+ew)+ iv = rho*log(den)+ pp=exp(x[4]+iv)/(1+exp(x[4]+iv))+ pr1 =pp* ey/den+ pr2 =pp* ed/den+ pr3 =pp* eh/den+ pr4 =pp* ew/den+ pnp=1/(1+exp(x[4]+iv))+ likelihood = (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt[! ,! 4])+(pr4*yogurt[,4])+ lsum = log(likelihood)+ return(-colSums(lsum))+ }> p = optim(c(0,0,0,0,0.1,-2,-0.2),fr, hessian = TRUE, method = "BFGS")Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite _ [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plot slideshow
Dear R experts: I've seen that it's possible to make a sort of "slideshow" with several R-plots (each slide is activated by a click on the mouse). How can I put this on a R-script??? Regards. D. [[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] Re : Need help on running Heckman Correction Estimation using R
Hi Kishore and Justin, The sample selection stuff has been separated from the micEcon package about one year ago. It is available in the sampleSelection package [1,2,3] now. The sample selection package is thoroughly described in a (freely available) paper published in the Journal of Statistical Software [4]. We recommend using the "selection" command rather than the "heckit" command, because the former can be used to estimate the model not only by the two-step method but also by ML. [1] http://www.sampleselection.org/ [2] http://r-forge.r-project.org/projects/sampleselection/ [3] http://cran.r-project.org/web/packages/sampleSelection/index.html [4] http://www.jstatsoft.org/v27/i07 Best wishes, Arne On Tuesday 27 January 2009 06:02:46, justin bem wrote: > See the micEcon package. there is and heckit function >  Justin BEM > BP 1917 Yaoundé > Tél (237) 99597295 > (237) 22040246 > > > > > > De : Kishore > à : r-help@r-project.org; r-h...@stat.math.ethz.ch > Envoyé le : Mardi, 27 Janvier 2009, 11h54mn 00s > Objet : [R] Need help on running Heckman Correction Estimation using R > > Team, > > I am trying to resolve the self-selection bias of a sample in an experiment > and would like to run the Heckman Correction Estimation using R. Can > someone help me with the R-Code... I tried searching for the discussion, > but not successful. Thanks in advance, > > Best, > > Kishore/.. > http://kaykayatisb.blogspot.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. > > > > > [[alternative HTML version deleted]] -- Arne Henningsen http://www.arne-henningsen.name/ __ 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] StepAIC with coxph
Hi, i'm trying to apply StepAIC with coxph...but i have the same error: stepAIC(fitBMT) Start: AIC=327.77 Surv(TEMPO,morto==1) VOD + SESSO + ETA + Error in dropterm.default(fit,scope$drop, scale=scale,trace=max(0, : number of rows in use has changed: remove missing values? anybody know this error?? Thanks. Michele [[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] Merge two vectors into one.
Hi all, I have two vectors like this: x <- c( "Y", "H", NA, NA ) y <- c( NA, "H", NA, "B" ) And would like to make one vector with the common elements, and the element available only in one of the vectors. res <- c( "Y", "H", NA, "B" ) Thanks, Patricia > From: neptune...@hotmail.com > To: r-help@r-project.org > Date: Wed, 28 Jan 2009 14:15:20 + > Subject: [R] initial value in 'vmmin' is not finite > > > Dear r helpers > > I run the following code for nested logit and got a message that > > Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = > "BFGS") : initial value in 'vmmin' is not finite > What does this mean? and how can I correct it? > > Thank you > June > > > yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)> > > dim(yogurt)[1] 1278425> choice = yogurt[,2:5]> price=yogurt[,14:17]> > > feature=yogurt[,6:9]> n = nrow(yogurt)> constant = rep(1,each=n)> > > yop=cbind(constant,feature[,1],price[,1])> > > dan=cbind(constant,feature[,2],price[,2])> > > hil=cbind(constant,feature[,3],price[,3])> wt=cbind(feature[,4],price[,4])> > > > fr <- function(x) { + x1 = x[1]+ x2 = x[2]+ x3 = x[3]+ x4 = x[4]+ x5 = > > x[5]+ x6 = x[6]+ x7 = x[7]+ con1 = rbind(x[1],x[5],x[6])+ con2 = > > rbind(x[2],x[5],x[6])+ con3 = rbind(x[3],x[5],x[6])+ con4 = > > rbind(x[5],x[6])+ rho=exp(x[7])/(1+exp(x[7]))+ ey = exp((yop%*%con1)/rho)+ > > ed = exp((dan%*%con2)/rho)+ eh = exp((hil%*%con3)/rho)+ ew = > > exp((wt%*%con4)/rho)+ ev = ey+ed+eh+ew+ den=(ey+ed+eh+ew)+ iv = > > rho*log(den)+ pp=exp(x[4]+iv)/(1+exp(x[4]+iv))+ pr1 =pp* ey/den+ pr2 =pp* > > ed/den+ pr3 =pp* eh/den+ pr4 =pp* ew/den+ pnp=1/(1+exp(x[4]+iv))+ > > likelihood = (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt! [,! > 4])+(pr4*yogurt[,4])+ lsum = log(likelihood)+ return(-colSums(lsum))+ }> p = > optim(c(0,0,0,0,0.1,-2,-0.2),fr, hessian = TRUE, method = "BFGS")Error in > optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : > initial value in 'vmmin' is not finite > > _ > > > > [[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] putting match.call to good use
On Wed, 28 Jan 2009, Harald Eikrem wrote: ( I just became aware the mailer enforces html bodies, as such removed by the list handler. Sorry about that. My message was ) I have this function slm <- function(fun=lm, ...) { #ilm <- eval(match.call()[-1]); # no way ilm <- eval(parse(text=sub("^list", deparse(substitute(fun)), deparse(substitute(...()); ... The latter actually does the trick, but recognising how some gurus hate parse, I would like to know if this can anyhow be done with match.call, or any other reasonable solution. The issue here is that lm (and likewise glm, bayesglm, etc.) returns the function call, which needs to show up as the original args to slm of course. The way to do this is eval(substitute()). E.g. from the new Rd2HTML Rd <- eval(substitute(parse_Rd(f, encoding = enc), list(f = Rd,enc = encoding))) -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merge two vectors into one.
Hi, Sorry, the answers are yes yes yes. And thank you for your idea it works perfectly. Regards Patricia > Date: Wed, 28 Jan 2009 16:01:11 +0100 > Subject: Re: [R] Merge two vectors into one. > From: csa...@rmki.kfki.hu > To: kurtney...@hotmail.com > CC: r-help@r-project.org > > Is position important? The vectors always have the same length? They > always have the same entry if both are not NA? > > If yes, yes and yes, then > > res <- ifelse( is.na(x), y, x) > > does what you want. Otherwise please explain better what you want. > > Gabor > > On Wed, Jan 28, 2009 at 3:54 PM, patricia garcía gonzález > wrote: > > > > Hi all, > > > > I have two vectors like this: > > > > > > x <- c( "Y", "H", NA, NA ) > > > >y <- c( NA, "H", NA, "B" ) > > > > And would like to make one vector with the common elements, and the element > > available only in one of the vectors. > > > > > > res <- c( "Y", "H", NA, "B" ) > > > > > > Thanks, > > > > Patricia > > > > -- > Gabor Csardi UNIL DGM _ [[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] Merge two vectors into one.
Is position important? The vectors always have the same length? They always have the same entry if both are not NA? If yes, yes and yes, then res <- ifelse( is.na(x), y, x) does what you want. Otherwise please explain better what you want. Gabor On Wed, Jan 28, 2009 at 3:54 PM, patricia garcía gonzález wrote: > > Hi all, > > I have two vectors like this: > > > x <- c( "Y", "H", NA, NA ) > >y <- c( NA, "H", NA, "B" ) > > And would like to make one vector with the common elements, and the element > available only in one of the vectors. > > > res <- c( "Y", "H", NA, "B" ) > > > Thanks, > > Patricia > -- Gabor Csardi UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot slideshow
I know you probably want to do this in R, but you could do this in power point or the openoffice variant rather easily. Stephen On Wed, Jan 28, 2009 at 9:44 AM, diego Diego wrote: > Dear R experts: > I've seen that it's possible to make a sort of "slideshow" with several > R-plots (each slide is activated by a click on the mouse). How can I put > this on a R-script??? > > > Regards. > > D. > >[[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. > -- Stephen Sefick Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ 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] Merge two vectors into one.
you could start by something like the following: x <- c("Y", "H", NA, NA) y <- c(NA, "H", NA, "B") ifelse(is.na(x), y, x) I hope it helps. Best, Dimitris patricia garcía gonzález wrote: Hi all, I have two vectors like this: x <- c( "Y", "H", NA, NA ) y <- c( NA, "H", NA, "B" ) And would like to make one vector with the common elements, and the element available only in one of the vectors. res <- c( "Y", "H", NA, "B" ) Thanks, Patricia From: neptune...@hotmail.com To: r-help@r-project.org Date: Wed, 28 Jan 2009 14:15:20 + Subject: [R] initial value in 'vmmin' is not finite Dear r helpers I run the following code for nested logit and got a message that Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite What does this mean? and how can I correct it? Thank you June yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)> dim(yogurt)[1] 1278425> choice = yogurt[,2:5]> price=yogurt[,14:17]> feature=yogurt[,6:9]> n = nrow(yogurt)> constant = rep(1,each=n)> yop=cbind(constant,feature[,1],price[,1])> dan=cbind(constant,feature[,2],price[,2])> hil=cbind(constant,feature[,3],price[,3])> wt=cbind(feature[,4],price[,4])> > fr <- function(x) { + x1 = x[1]+ x2 = x[2]+ x3 = x[3]+ x4 = x[4]+ x5 = x[5]+ x6 = x[6]+ x7 = x[7]+ con1 = rbind(x[1],x[5],x[6])+ con2 = rbind(x[2],x[5],x[6])+ con3 = rbind(x[3],x[5],x[6])+ con4 = rbind(x[5],x[6])+ rho=exp(x[7])/(1+exp(x[7]))+ ey = exp((yop%*%con1)/rho)+ ed = exp((dan%*%con2)/rho)+ eh = exp((hil%*%con3)/rho)+ ew = exp((wt%*%con4)/rho)+ ev = ey+ed+eh+ew+ den=(ey+ed+eh+ew)+ iv = rho*log(den)+ pp=exp(x[4]+iv)/(1+exp(x[4]+iv))+ pr1 =pp* ey/den+ pr2 =pp* ed/den+ pr3 =pp* eh/den+ pr4 =pp* ew/den+ pnp=1/(1+exp(x[4]+iv))+ likelihood = (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt ! [,! 4])+(pr4*yogurt[,4])+ lsum = log(likelihood)+ return(-colSums(lsum))+ }> p = optim(c(0,0,0,0,0.1,-2,-0.2),fr, hessian = TRUE, method = "BFGS")Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite _ [[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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ 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] Mystery Error in midnightStandard
"TB" == Ted Byers on Wed, 28 Jan 2009 09:30:58 -0500 TB> It is certain that all entries have the same format, but I'm TB> starting to TB> think that the error message is something of a red herring. TB> Consider this: TB> TB> > year = 2009 TB> > week = 0 TB> > day = 3 TB> > datestr = sprintf(%i-%i-%i,year,week,day);datestr TB> [1] 2009-0-3 TB> > date1 = timeDate(datestr, format = %Y-%U-%w); TB> > date1 TB> GMT TB> [1] [NA] TB> > day = 4 TB> > datestr = sprintf(%i-%i-%i,year,week,day);datestr TB> [1] 2009-0-4 TB> > date1 = timeDate(datestr, format = %Y-%U-%w); TB> > date1 TB> GMT TB> [1] [2009-01-01] TB> > TB> > datestr = sprintf(%i-%i-%i,year,week,3);datestr TB> [1] 2009-0-3 TB> > date2 = timeDate(datestr, format = %Y-%U-%w);date2 TB> GMT TB> [1] [NA] TB> > difftimeDate(date2,date1, units = weeks) TB> Error in midnightStandard(charvec, format) : TB> 'charvec' has non-NA entries of different number of characters TB> In addition: Warning messages: TB> 1: In min(x) : no non-missing arguments to min; returning Inf TB> 2: In max(x) : no non-missing arguments to max; returning -Inf TB> TB> TB> TB> The first values for year, week and day are the values on TB> which my loop TB> dies. It returns 'NA' here. It seems clear that it is TB> returning NA because TB> the date that data corresponds to is 2008-12-31. TB> TB> The error is being produced by difftimeDate rather than timeDate TB> (as shown TB> by the above session). But that represents a flaw in the TB> function design. This is not a flaw in timeDate. it behaves the same way as 'as.POSIXct' strptime(datestr, format = "%Y-%U-%w") Instead of claiming that there is a flaw in the function you could have suggested an 'is.na' method for 'timeDate'. I will add an 'is.na' method in the dev version of 'timeDate'. regards, Yohan TB> It should fail when taking the elapsed time between a null TB> and the present, TB> but if I wrote such a function, I'd have it return null TB> (perhaps with a TB> warning) rather than just die. TB> TB> A bigger issue is that timeDate ought never give null here TB> (which is what I TB> assume 'NA' means), since all the data comes from transaction TB> data with real TB> dates, so the elapsed time, measured in weeks, ought to always TB> be a valid TB> real number that is positive semidefinite. I have not yet TB> come to any TB> conclusions as to how it ought to behave (whether to return TB> new years day, TB> along with a warning, or to return the date requested by TB> reinvoking itself TB> with the year and week adjusted so a valid date is returned). TB> TB> On a practical side, how would I test date2 to see if it is TB> null, so I can TB> give it a sensible default value? TB> TB> A more troubling thought is that with this handling of dates TB> in this TB> combination of SQL (my group by clause uses TB> YEAR(transaction_date),WEEK(transaction_date)) to get the data TB> and R to TB> process it, the week containing new years day will ALWAYS be TB> split in two at TB> the first second of the new year. I'm going to have to either TB> figure out a TB> way to correct this, or ignore it (as it doesn't actually make TB> things wrong, TB> but rather it splits a sample into two unequal parts). -- PhD student Swiss Federal Institute of Technology Zurich www.ethz.ch __ 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] putting match.call to good use
Prof Brian Ripley stats.ox.ac.uk> writes: > The way to do this is eval(substitute()). E.g. from the new Rd2HTML > What is Rd2HTML? Dieter __ 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] putting match.call to good use
Prof Brian Ripley wrote: > On Wed, 28 Jan 2009, Harald Eikrem wrote: > >> ( I just became aware the mailer enforces html bodies, as such removed >> by the list handler. Sorry about that. My message was ) >> >> I have this function >> >> slm <- function(fun=lm, ...) { >> #ilm <- eval(match.call()[-1]); # no way >> ilm <- eval(parse(text=sub("^list", deparse(substitute(fun)), >> deparse(substitute(...()); >> ... >> >> The latter actually does the trick, but recognising how some gurus >> hate parse, I would like to know if this can anyhow be done with >> match.call, or any other reasonable solution. >> >> The issue here is that lm (and likewise glm, bayesglm, etc.) returns >> the function call, which needs to show up as the original args to slm >> of course. > > The way to do this is eval(substitute()). E.g. from the new Rd2HTML > > Rd <- eval(substitute(parse_Rd(f, encoding = enc), > list(f = Rd,enc = encoding))) > I don't understand the substitute(...()) bit (looks like an unexpected feature), but I suspect that it might also be a good idea to read and understand the first dozen lines or so of the lm function itself. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot slideshow
If you investigate how the call: demo(graphics) ... works, you find that the first interactive event is handled by the code at the end of the demo function, Just type: demo The rest of the interactive events are handled by this single line at the beginning of the graphics.R code that creates an implicit loop: oask <- devAskNewPage(dev.interactive(orNone = TRUE)) You could have found this by looking at the Writing R Extensions documentation and then noting that demos are placed in demo subdirectories of the packages. Going to a package that you knew contained a working demo, in this cases the graphics package, you would find a graphics.R demo script. -- David Winsemius On Jan 28, 2009, at 9:44 AM, diego Diego wrote: Dear R experts: I've seen that it's possible to make a sort of "slideshow" with several R-plots (each slide is activated by a click on the mouse). How can I put this on a R-script??? Regards. D. [[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] OT: Adding verbatim R code text into LaTeX documents: texttt; verb or url?
LaTeX offers a verbatim environment. \begin{verbatim} This is maintained verbatim, Latex commands and environments are typeset as written without any processing. \end{verbatim} Be sure to use the package verbatim. ---Joe "Peter Dunn" Sent by: r-help-boun...@r-project.org 01/28/2009 01:41 AM To "R Help" cc Subject [R] OT: Adding verbatim R code text into LaTeX documents: texttt; verb or url? Hi all I use Sweave extensively to mix R and LaTeX, and often have R code appearing in my LaTeX document. Just a quick question then: What is the best way to add example of R commands into LaTeX in-line? (That is, not using Sweave.) For example, suppose I wish to place in my document this instruction: ...is done in R using the command \verb|lm( y ~ var.one + var.two )| as follows: I used \verb above, but I see three options: \verb, \url (package url), or \texttt; there are probably others. Here are my comments on these three: - Using \texttt is OK, but it disappears my tildes and can hyphenate - Using \verb is good, but it can hyphenate. - Using \url is very good, but it: * disappears my spaces; so for the above example, the spaces added for clarity are gone. * Minor: I like my verbatim text a little smaller (\small size), and change the font size for verbatim using \def\verba...@font{\small\ttfamily} but \url seems to ignore this and appears larger than if I used \text or \verb. Also, using \url often adds line-breaks mid-variable at the dots (for example, splitting var.one to have "var." on one line, and "one" on the next). I'm not sure this is a problem or not; here it is just an observation. Ideally, one would want a LaTeX function, say \rcode{}, that displayed in-text using non-proportional font, kept tildes, kept spacing, uses my verb-font changes, and broke at sensible places for R. (I don't want much, do I?) So two questions: * What do other people do? Maybe there is a solution I have over-looked. * Is there an easy solution? I suppose writing such a command in LaTeX is possible, but there is strong evidence to reject the hypothesis that I would be able to write one. Maybe one of the above choices are easily adopted. If no easy solutions exist or emerge, I'm happy to run with \url. Thanks again. P. Peter Dunn Biostatistician School of Health and Sport Science Faculty of Science, Health and Education University of the Sunshine Coast Tel: +61 7 5456 5085 Fax: +61 7 5430 2896 Email: pdu...@usc.edu.au www.usc.edu.au CRICOS Provider Number: 01595D This communication is intended for the recipient only and should not be forwarded, distributed or otherwise read by others without express permission. The views expressed in this email are not necessarily those of the University of the Sunshine Coast. -- This message has been scanned for viruses and\ dangerous...{{dropped:15}} __ 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] putting match.call to good use
On Wed, 28 Jan 2009, Dieter Menne wrote: Prof Brian Ripley stats.ox.ac.uk> writes: The way to do this is eval(substitute()). E.g. from the new Rd2HTML What is Rd2HTML? A function in the R-devel version of R (is 'new' not rather a hint?). From the NEWS file: o parse_Rd(), an experimental parser for Rd files, and Rd2txt(), Rd2HTML(), Rd2latex() and Rd2ex(), even more experimental converters, have been added to package 'tools'. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Grouping problem
Hi all, I have a problem with grouping like I have to give count of employes in each department like if in one company there is departments like Mechanical, Computer, Fitting, electronics and Chemical hear I have to retreave the number of employes in each department and as well as I have to retreave number of John's in each department is there any function is there which can solve my problem i tried withsubset(); but it is retreaving one department's data only can anyone suggest what I have to do for this thanks in advance [[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] Newbie question about "grouping"
Hi folks: I am a SQL guy who just downloaded and installed R yesterday. I am trying to evaluate some "complex" aggregations we are currently performing with Syncsort (and have tried in Oracle) with R. I have loaded data in a dataframe and have performed some of the simple aggregations on a subset of data. What I do not see how to do though, is to "group" the aggregations on a particular key value (e.g., sum market_value over account_id). If you can point me in the right direction I'd very much appreciate it. 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 with plot layout
It takes a lot of sweat to generate a composite plot with R ... sigh. I though I was almost done when I met the umpteenth hurdle. I cannot place a nice title on the 2nd plot (raw signal) on the layout. I do not have control on where either the "main" option of "plot" function, or "title", place the text string which keeps dysplaying chopped from above. I also tried "text", changing many times the string coordinates, but could not see any text anywhere on the canvas . By the way, since the layout breaks the canvas into 4 parts, are the text coordinates absolute (referred to the canvas) or relative (referred to the part) ? Please, find attached the generated drawing. The generating script is i the following. Thank you so much, Maura ## WavMaxNumCoef <- 30 setwd("C:/Documents and Settings/Monville/SpAn-Tests/16440-Raw-Dir") xx <- read.table("Interp-Amp-PhasePlus16440.txt",header=TRUE, sep=" ") NumCycles <- max(xx[,"cycle"]) TickPos <- vector(length=NumCycles) TickCoord <- vector(length=NumCycles) for(i in 1:NumCycles) { TickPos[i] <- xx[min(which(xx[,"cycle"] == i)),1] } aa <- read.table( "16440-Alpha.txt" ) xaa <- seq(1:length(t(aa))) vv <- read.table("16440-Vanishing-Moments") vvLab <- seq(1,WavMaxNumCoef/2,1) vvCounts <- vector(length=WavMaxNumCoef/2) for(k in 1:(WavMaxNumCoef/2)) { vvCounts[k] <- length(which(vv[] == k)) } yyLab <- seq(1,length(t(vv)),2) bb <- read.table("16440-Length") bbLab <- seq(min(bb),max(bb),1) bb <- sort(t(bb)) bbCounts <- as.numeric(vector(length=(max(bb)-min(bb)+1))) for(k in 1:length(bbCounts)) { bbCounts[k] <- length(which(bb[] == (k +min(bb) -1))) } zzLab <- seq(1,max(bbCounts),1) # DEFINE LAYOUT x11(width=22,height=14) nf <- layout(matrix(c(1,3,2,4),2,2,byrow=TRUE), c(3,1), c(2,2),FALSE) layout.show(nf) # PLOT DONOHO ALPHA par(mar=c(10,4,2,5),xaxt="n",cex.axis=1,pty="m") plot(xaa,t(aa),type="h") par (xaxt="s",xaxp=c(0,95.964,24),xaxs="i") axis(1,at=TickPos,labels=as.character(TickPos),col="red",col.axis="red",font.axis=1) # PLOT RAW SIGNAL par(mar=c(3,4,0,5),xaxt="n",cex.axis=1,pty="m") plot(xx[,1],xx[,2],pch=3,type="l",frame.plot=FALSE,xpd=TRUE) title("Raw Signal 16440",cex.main=1.0,font=2) par (xaxt="s",xaxp=c(0,95.964,24),xaxs="i") axis(1,at=TickPos,labels=as.character(TickPos),col="red",col.axis="red", font.axis=1) # PLOT VANISHING MOMENT DISTRIBUTION par(mar=c(1,0,2,3),xaxt="n",yaxt="n",cex.axis=0.7,pty="m") barplot(vvCounts,width=1,space=0,horiz=TRUE,axes=FALSE) par(xaxt="s",yaxt="s",crt=180,srt=270,adj=1,las=3,xpd=TRUE) text(x=25.5,y=15.3,pos=4,"Wavelet Vanishing Moments Distribution",cex=1.0,font=2) axis(2,at=vvLab-1,labels=as.character(vvLab),col="red",col.axis="red",font.axis=1,xpd=TRUE, cex.lab=1) axis(3,at=yyLab-1,labels=as.character(yyLab),col="red",col.axis="red",font.axis=1,xpd=TRUE, cex.lab=0.8,cex.axis=0.8) # PLOT CYCLES LENGTH par(mar=c(0,0,1,3),xaxt="n",yaxt="n",cex.axis=1) barplot(bbCounts,width=1,axes=FALSE,space=0,horiz=TRUE) par(xaxt="s",yaxt="s",crt=180,srt=270,adj=1,las=3,cex.lab=0.1,xpd=TRUE) text(x=15.5,y=65.3,pos=4,"Cycles Length Distribution",cex=1.0,font=2) axis(2,at=as.numeric(bbLab)-41,labels=bbLab,col="red",col.axis="red",font.axis=1, lab=c(10,10,15),cex.lab=0.7,cex.axis=0.6) axis(3,at=zzLab,labels=as.character(zzLab),col="red",col.axis="red",font.axis=1,xpd=TRUE, cex.lab=1,cex.axis=0.8) # cords <-locator(n=3) e tutti i telefonini TIM! Vai su __ 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] Logical subset of the columns in a dataframe
Hi R-helpers, I've been struggling with a problem for most of the day (!) so am finally resorting to R-help. I would like to subset the columns of my dataframe based on the frequency with which the columns contain non-zero values. For example, let's say that I want to retain only those columns which contain non-zero values in at least 1% of their rows. In Excel I would calculate a row at the bottom of my data sheet and use the following function =countif(range,">0") to identify the number of non-zero cells in each column. Then, I would divide that by the number of rows to obtain the frequency of non-zero values in each column. Then, I would delete those columns with frequencies < 0.01. But, I'd like to do this in R. I think the missing link is an analog to Excel's countif function. Any ideas? Thanks! Mark [[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] Grouping problem
A vague answer is the best you should hope for with such a vague question with no sample data: ?table ?xtabs ?"==" A search on "Frequency tables from factors" should get you to the intro to R section with that name. -- David Winsemius On Jan 28, 2009, at 10:47 AM, venkata kirankumar wrote: Hi all, I have a problem with grouping like I have to give count of employes in each department like if in one company there is departments like Mechanical, Computer, Fitting, electronics and Chemical hear I have to retreave the number of employes in each department and as well as I have to retreave number of John's in each department is there any function is there which can solve my problem i tried withsubset(); but it is retreaving one department's data only can anyone suggest what I have to do for this If you had offered the code that was doing this, there may have been a person who could explain how it could be modified to return a more desirable value. thanks in advance [[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] Grouping problem
You might want to have a look at the plyr package, http://had.co.nz/plyr, which includes tools for performing this sort of grouping. Hadley On Wed, Jan 28, 2009 at 9:47 AM, venkata kirankumar wrote: > Hi all, > I have a problem with grouping like I have to give count of employes in each > department like > > if in one company there is departments like > Mechanical, Computer, Fitting, electronics and Chemical > > hear I have to retreave the number of employes in each department and as > well as > I have to retreave number of John's in each department > > is there any function is there which can solve my problem > i tried withsubset(); > but it is retreaving one department's data only > can anyone suggest what I have to do for this > > > thanks in advance > >[[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. > -- http://had.co.nz/ __ 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] Newbie question about "grouping"
?by ?aggregate ?ave Further specifics might be forthcoming if self-contained example data and desired output were offered. The help pages will have worked examples, of course. -- David Winsemius On Jan 28, 2009, at 9:13 AM, Rixon, John C. wrote: Hi folks: I am a SQL guy who just downloaded and installed R yesterday. I am trying to evaluate some "complex" aggregations we are currently performing with Syncsort (and have tried in Oracle) with R. I have loaded data in a dataframe and have performed some of the simple aggregations on a subset of data. What I do not see how to do though, is to "group" the aggregations on a particular key value (e.g., sum market_value over account_id). If you can point me in the right direction I'd very much appreciate it. 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.
Re: [R] Newbie question about "grouping"
Some useful commands are: by(), aggregate(), ave(), split(). eg by(market_value, account_id, sum) -thomas On Wed, 28 Jan 2009, Rixon, John C. wrote: Hi folks: I am a SQL guy who just downloaded and installed R yesterday. I am trying to evaluate some "complex" aggregations we are currently performing with Syncsort (and have tried in Oracle) with R. I have loaded data in a dataframe and have performed some of the simple aggregations on a subset of data. What I do not see how to do though, is to "group" the aggregations on a particular key value (e.g., sum market_value over account_id). If you can point me in the right direction I'd very much appreciate it. 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. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ 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] Newbie question about "grouping"
On Wed, Jan 28, 2009 at 8:13 AM, Rixon, John C. wrote: > Hi folks: > > I am a SQL guy who just downloaded and installed R yesterday. I am > trying to evaluate some "complex" aggregations we are currently > performing with Syncsort (and have tried in Oracle) with R. I have > loaded data in a dataframe and have performed some of the simple > aggregations on a subset of data. What I do not see how to do though, > is to "group" the aggregations on a particular key value (e.g., sum > market_value over account_id). > > If you can point me in the right direction I'd very much appreciate it. Have a look at the plyr package, http://had.co.nz/plyr, and associated documentation. If you're doing pivot table type aggregations, you might also want to have a look at the reshape package, http://had.co.nz/reshape. Hadley -- http://had.co.nz/ __ 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] Logical subset of the columns in a dataframe
On Wed, 28 Jan 2009, Mark Na wrote: Hi R-helpers, I've been struggling with a problem for most of the day (!) so am finally resorting to R-help. I would like to subset the columns of my dataframe based on the frequency with which the columns contain non-zero values. For example, let's say that I want to retain only those columns which contain non-zero values in at least 1% of their rows. In Excel I would calculate a row at the bottom of my data sheet and use the following function =countif(range,">0") to identify the number of non-zero cells in each column. Then, I would divide that by the number of rows to obtain the frequency of non-zero values in each column. Then, I would delete those columns with frequencies < 0.01. But, I'd like to do this in R. I think the missing link is an analog to Excel's countif function. Any ideas? Use something like DF[sapply(DF, function(x) mean(x) >= 0.01)] Since logical values are converted to 0/1, mean() gives the frequency (and sum() the count). Thanks! Mark [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Mystery Error in midnightStandard
Hi Yohan, On Wed, Jan 28, 2009 at 10:28 AM, Yohan Chalabi wrote: > "TB" == Ted Byers > on Wed, 28 Jan 2009 09:30:58 -0500 > > TB> It is certain that all entries have the same format, but I'm > TB> starting to > TB> think that the error message is something of a red herring. > TB> Consider this: > TB> > TB> > year = 2009 > TB> > week = 0 > TB> > day = 3 > TB> > datestr = sprintf(%i-%i-%i,year,week,day);datestr > TB> [1] 2009-0-3 > TB> > date1 = timeDate(datestr, format = %Y-%U-%w); > TB> > date1 > TB> GMT > TB> [1] [NA] > TB> > day = 4 > TB> > datestr = sprintf(%i-%i-%i,year,week,day);datestr > TB> [1] 2009-0-4 > TB> > date1 = timeDate(datestr, format = %Y-%U-%w); > TB> > date1 > TB> GMT > TB> [1] [2009-01-01] > TB> > > TB> > datestr = sprintf(%i-%i-%i,year,week,3);datestr > TB> [1] 2009-0-3 > TB> > date2 = timeDate(datestr, format = %Y-%U-%w);date2 > TB> GMT > TB> [1] [NA] > TB> > difftimeDate(date2,date1, units = weeks) >TB> Error in midnightStandard(charvec, format) : > TB> 'charvec' has non-NA entries of different number of characters >TB> In addition: Warning messages: > TB> 1: In min(x) : no non-missing arguments to min; returning Inf > TB> 2: In max(x) : no non-missing arguments to max; returning -Inf > TB> > TB> > TB> > TB> The first values for year, week and day are the values on > TB> which my loop > TB> dies. It returns 'NA' here. It seems clear that it is > TB> returning NA because > TB> the date that data corresponds to is 2008-12-31. > TB> > TB> The error is being produced by difftimeDate rather than timeDate > TB> (as shown > TB> by the above session). But that represents a flaw in the > TB> function design. > > This is not a flaw in timeDate. it behaves the same way as > 'as.POSIXct' > That the two behave the same doesn't change the assessment that the design is flawed. That doesn't mean that the function is wrong. It means only that the behaviour can be made more useful. For example, in SQL, if a given calculation returns NULL, and the result is subsequently used in another calculation, the result that returns is also NULL. That is quite useful, and admits algorithms that can react appropriately to NULLs when necessary. That is arguably better than forcing the code to fail the moment a NULL is used in a secondary calculation. In C++, OTOH, one can catch the problem earlier using, e.g., exceptions, again allowing the program to complete even when problems arise for certain values or combinations thereof. As a software engineer, I understand the issues involved in creating libraries. If I want to incorporate the functionality of a given standard suite of functions (e.g. ANSI C standard library functions, or posix functions), my first step would be to ensure I can duplicate how they behave. But I would not stop there. There are, for example, serious design flaws in many ANSI C functions that, ignored, introduce serious security defects in applications that use them. I would therefore refactor them to eliminate the security defects. If they can not be eliminated, I would replace the function in question by a similar function that does not have that security defect. Posix is a useful, but old, standard, and I am merely suggesting that once you have duplicated it, look beyond it to ways it can be improved upon. There is more to the design of a function than whether or not it gives the right result with good input. There is how it behaves when there is a problem with the inputs and whether or not you force the calling code to die when a problem arises or you give the calling code a way to react to such problems. When I add functions to my own C++ or Java libraries, I normally include more bad input data in the unit tests than good data (though the latter is sufficient to ensure correct results are invariably obtained), precisely so I can document how it behaves when there is a problem and give coders who use it a variety of options to use to deal with them. > > strptime(datestr, format = "%Y-%U-%w") > > Instead of claiming that there is a flaw in the function you could have > suggested an 'is.na' method for 'timeDate'. > At the time, I did not know about is.na. I have spent the past hour trying is.na, but to no avail. I guess that is no surprise to you, but that it would fail is not reflected in the R documentation of is.na. That mentions S3, but not S4. As I just recently started using R, I have not yet looked at what S3 and S4 are, so that is a few more hours of study before I get this problem solved. > > I will add an 'is.na' method in the dev version of 'timeDate'. > > Thanks. I'll benefit from that once it makes it into the production release. In the mean time, I need to find a way to make something similar now, in my script. Thanks Ted [[alternative HTML version deleted]] __ R-help@r-project.org maili
Re: [R] Logical subset of the columns in a dataframe
One approach to such a problem would be to use a logical vector inside the function colSums. ?colSums > DF <- data.frame(XX= runif(20), YY=runif(20)) > colSums(DF > 0.5) XX YY 11 9 > colSums(DF > -Inf) XX YY 20 20 > > colSums(DF> 0.5)/colSums(DF > -Inf) #could have used DF >= min(DF) in the denominator XX YY 0.55 0.45 -- David Winsemius On Jan 28, 2009, at 11:11 AM, Mark Na wrote: Hi R-helpers, I've been struggling with a problem for most of the day (!) so am finally resorting to R-help. I would like to subset the columns of my dataframe based on the frequency with which the columns contain non-zero values. For example, let's say that I want to retain only those columns which contain non-zero values in at least 1% of their rows. In Excel I would calculate a row at the bottom of my data sheet and use the following function =countif(range,">0") to identify the number of non-zero cells in each column. Then, I would divide that by the number of rows to obtain the frequency of non- zero values in each column. Then, I would delete those columns with frequencies < 0.01. I don't think that would do what you describe unless you were only working with single column ranges. Functions on ranges in Excel are not calculated by column. But, I'd like to do this in R. I think the missing link is an analog to Excel's countif function. Any ideas? Thanks! Mark [[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] constrainOptim
Dear R helpers I have a question regarding the constrainOptim. I'm coding the nested logit and would like to set a bound of rho to (0,1] as an extreme value distribution where rho = exp(lambda)/1+exp(lambda) I wonder if I can do that directly in optim (say rho > 0 & <= 1) or need to use constrainOptim I read the help but still don't know how to set ui and ci Thanks, June _ [[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] Mystery Error in midnightStandard
"TB" == Ted Byers on Wed, 28 Jan 2009 11:25:55 -0500 TB> That the two behave the same doesn't change the assessment TB> that the design TB> is flawed. That doesn't mean that the function is wrong. TB> It means only TB> that the behaviour can be made more useful. For example, TB> in SQL, if a given TB> calculation returns NULL, and the result is subsequently used TB> in another TB> calculation, the result that returns is also NULL. That is TB> quite useful, TB> and admits algorithms that can react appropriately to NULLs TB> when necessary. TB> That is arguably better than forcing the code to fail the TB> moment a NULL is TB> used in a secondary calculation. In C++, OTOH, one can catch TB> the problem TB> earlier using, e.g., exceptions, again allowing the program TB> to complete even TB> when problems arise for certain values or combinations thereof. TB> TB> As a software engineer, I understand the issues involved TB> in creating TB> libraries. If I want to incorporate the functionality of a TB> given standard TB> suite of functions (e.g. ANSI C standard library functions, TB> or posix TB> functions), my first step would be to ensure I can duplicate TB> how they TB> behave. But I would not stop there. There are, for example, TB> serious design TB> flaws in many ANSI C functions that, ignored, introduce TB> serious security TB> defects in applications that use them. I would therefore TB> refactor them to TB> eliminate the security defects. If they can not be eliminated, TB> I would TB> replace the function in question by a similar function that TB> does not have TB> that security defect. TB> TB> Posix is a useful, but old, standard, and I am merely suggesting TB> that once TB> you have duplicated it, look beyond it to ways it can be TB> improved upon. TB> There is more to the design of a function than whether or not TB> it gives the TB> right result with good input. There is how it behaves when TB> there is a TB> problem with the inputs and whether or not you force the TB> calling code to die TB> when a problem arises or you give the calling code a way to TB> react to such TB> problems. When I add functions to my own C++ or Java libraries, TB> I normally TB> include more bad input data in the unit tests than good data TB> (though the TB> latter is sufficient to ensure correct results are invariably TB> obtained), TB> precisely so I can document how it behaves when there is a TB> problem and give TB> coders who use it a variety of options to use to deal with them. TB> TB> TB> > TB> > strptime(datestr, format = %Y-%U-%w) TB> > TB> > Instead of claiming that there is a flaw in the function TB> you could have TB> > suggested an 'is.na' method for 'timeDate'. TB> > TB> TB> At the time, I did not know about is.na. I have spent the TB> past hour trying TB> is.na, but to no avail. I guess that is no surprise to you, TB> but that it TB> would fail is not reflected in the R documentation of is.na. TB> That mentions TB> S3, but not S4. As I just recently started using R, I have TB> not yet looked TB> at what S3 and S4 are, so that is a few more hours of study TB> before I get TB> this problem solved. TB> TB> TB> > TB> > I will add an 'is.na' method in the dev version of 'timeDate'. TB> > TB> > TB> Thanks. I'll benefit from that once it makes it into the TB> production TB> release. In the mean time, I need to find a way to make TB> something similar TB> now, in my script. setMethod("is.na", "timeDate", function(x) is.na(as.POSIXct(x))) TB> TB> Thanks -- PhD student Swiss Federal Institute of Technology Zurich www.ethz.ch __ 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] constrainOptim
For simple box constraints, i.e. lower and upper limits directly on the parameters themselves, you don't need ConstrOptim. You can get the job done with the "L-BFGS-B" algorithm in optim() or using nlminb() or using the spg() function in the BB package. In this case the feasible region is a hyper-rectangle (could be infinite in some dimensions). ConstrOptim() is useful when you have more general linear inequality constraints, i.e. constraints on linear combinations of parameters. In this case the feasible region is a convex polytope. Best, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: June Wong Date: Wednesday, January 28, 2009 11:57 am Subject: [R] constrainOptim To: r-help@r-project.org > Dear R helpers > > I have a question regarding the constrainOptim. > I'm coding the nested logit and would like to set a bound of rho to > (0,1] as an extreme value distribution where rho = exp(lambda)/1+exp(lambda) > I wonder if I can do that directly in optim (say rho > 0 & <= 1) or > need to use constrainOptim > I read the help but still don't know how to set ui and ci > > Thanks, > June > > _ > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > > PLEASE do read the posting guide > 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] repeated measures design for GAM?
Dear all, I have a question on the use of GAM with repeated measures. My dataset is as follows: - a number of study areas where bird abundance has been determined. Counts have been performed in 3 consecutive years and there were 2 counts per year (i.e. in total 6 counts). - a number of environmental predictors that do not change over year Xi). When using a GLM, a repeated measures design would like: (for example) lme(Bird_abundance = study_area + count + X1 + X2 + X3,random = ~time|cow). However, I have found no analogue design for a GAM. For now, I have averaged my bird abundances but I wondered whether a more subtle and elegant strategy exists...? Many thanks, Diederik Diederik Strubbe Evolutionary Ecology Group Department of Biology, University of Antwerp Universiteitsplein 1 B-2610 Antwerp, Belgium http://webhost.ua.ac.be/deco tel : 32 3 820 23 85 [[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] Repeated measures design for GAM? - corrected question...
Dear all, I have a question on the use of GAM with repeated measures. My dataset is as follows: - a number of study areas where bird abundance has been determined. Counts have been performed in 3 consecutive years and there were 2 counts per year (i.e. in total 6 counts). - a number of environmental predictors that do not change over year Xi). When using a GLM, a repeated measures design would like: (for example) lme(Bird_abundance = study_area + count +year+ X1 + X2 + X3,random = ~count|study_area). However, I have found no analogue design for a GAM. For now, I have averaged my bird abundances but I wondered whether a more subtle and elegant strategy exists...? Many thanks, Diederik Diederik Strubbe Evolutionary Ecology Group Department of Biology, University of Antwerp Universiteitsplein 1 B-2610 Antwerp, Belgium http://webhost.ua.ac.be/deco tel : 32 3 820 23 85 [[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] Sweave problem with greek text
Dear Sweave and R aficionados, I am using R and Latex for many years, writing texts in greek. I tried to combine them with Sweave, but without any success. Could you provide me with any help? Usually my LaTeX files are like this iso-8859-7 encoded .tex file: http://costis.name/0various/lists/R/sweave/successful.greek.tex , which happily produces http://costis.name/0various/lists/R/sweave/successful.greek.pdf . I tried using Sweave on the iso-8859-7 encoded .Rnw file: http://costis.name/0various/lists/R/sweave/unsuccessful.sweave.Rnw , but I am getting misencoded greek text and also misencoded R code as it appears in http://costis.name/0various/lists/R/sweave/unsuccessful.sweave.pdf . The .tex file that Sweave produces is located at http://costis.name/0various/lists/R/sweave/unsuccessful.sweave.tex I am also the latex R error code http://costis.name/0various/lists/R/sweave/unsuccessful.sweave.log In the above example I am not using the kerkis font-package. When I am, I am getting no output at all, and a latex error of "Corrupted NFSS tables". I can understand that the whole problem is an encoding issue, but what should I do in order to use Sweave with greek text flawlessly? One solution is to edit the .tex file produced by Sweave, but this solution is by far counter-productive. Thank you very much in advance, Constantine Tsardounis http://www.costis.name PS.: I am having no problem to run Sweave in 100% English texts. I postscript the following files: * unsuccessful.sweave.Rnw * unsuccessful.sweave.tex * successful.greek.tex unsuccessful.sweave.Rnw \documentclass[a4paper,12pt]{book} \usepackage[greek]{babel} \usepackage[iso-8859-7]{inputenc} % \usepackage{kerkis} \begin{document} \section{\textlatin{Sweave}} \subsection{\textlatin{in Greek}} Γεια σας, τώρα γράφω ελληνικά. <<>>= data(airquality) library(ctest) kruskal.test(Ozone ~ Month, data = airquality) @ \subsection{\textlatin{in English}} \textlatin{Hello to all, now I am writing in English.} \end{document} unsuccessful.sweave.tex \documentclass[a4paper,12pt]{book} \usepackage[greek]{babel} \usepackage[iso-8859-7]{inputenc} % \usepackage{kerkis} \usepackage{/usr/share/R/share/texmf/Sweave} \begin{document} \section{\textlatin{Sweave}} \subsection{\textlatin{in Greek}} ΓΓ�Γ(c)Γ' Γ³Γ'Γ², ôþñΓ' ãñΓΓΆΓΉ Γ�ëëçΓΓ(c)Γ�Γ. \begin{Schunk} \begin{Sinput} > data(airquality) > library(ctest) > kruskal.test(Ozone ~ Month, data = airquality) \end{Sinput} \begin{Soutput} Kruskal-Wallis rank sum test data: Ozone by Month Kruskal-Wallis chi-squared = 29.2666, df = 4, p-value = 6.901e-06 \end{Soutput} \end{Schunk} \subsection{\textlatin{in English}} \textlatin{Hello to all, now I am writing in English.} \end{document} successful.greek.tex \documentclass[a4paper,12pt]{book} \usepackage[greek]{babel} \usepackage[iso-8859-7]{inputenc} \usepackage{kerkis} \begin{document} \section{\textlatin{Sweave}} \subsection{\textlatin{in Greek}} Γεια σας, τώρα γράφω ελληνικά. \subsection{\textlatin{in English}} \textlatin{Hello to all, now I am writing in English.} \end{document} __ 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] StepAIC with coxph
Michele, This error means that some of the variables in your formula have missing values, and hence when these terms or added/dropped you have a different sample size. Hence, the AIC cannot be compared between different models. The solution is to create a compelete-data dataframe for the largest model, i.e none of the variables in the largest model should have any missing values. Then run stepAIC on this dataframe. Best, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Michele Santacatterina Date: Wednesday, January 28, 2009 9:51 am Subject: [R] StepAIC with coxph To: R-help@r-project.org > Hi, > > i'm trying to apply StepAIC with coxph...but i have the same error: > > stepAIC(fitBMT) > Start: AIC=327.77 > Surv(TEMPO,morto==1) VOD + SESSO + ETA + > > Error in dropterm.default(fit,scope$drop, scale=scale,trace=max(0, : > number of rows in use has changed: remove missing values? > > anybody know this error?? > > Thanks. > > Michele > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > > PLEASE do read the posting guide > 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] Repeated measures design for GAM? - corrected question...
`gamm' in package `mgcv' will let you specify random effects as part of a generalized additive mixed model, but I must admit that I'm a bit confused about what `Bird_abundance' is here, and how it differs from `Count'. best, Simon On Wednesday 28 January 2009 17:09, Strubbe Diederik wrote: > Dear all, > > I have a question on the use of GAM with repeated measures. My dataset is > as follows: - a number of study areas where bird abundance has been > determined. Counts have been performed in 3 consecutive years and there > were 2 counts per year (i.e. in total 6 counts). - a number of > environmental predictors that do not change over year Xi). When using a > GLM, a repeated measures design would like: (for example) > > lme(Bird_abundance = study_area + count +year+ X1 + X2 + X3,random = > ~count|study_area). > > However, I have found no analogue design for a GAM. For now, I have > averaged my bird abundances but I wondered whether a more subtle and > elegant strategy exists...? > > Many thanks, > > > Diederik > > Diederik Strubbe > Evolutionary Ecology Group > Department of Biology, University of Antwerp > Universiteitsplein 1 > B-2610 Antwerp, Belgium > http://webhost.ua.ac.be/deco > tel : 32 3 820 23 85 > > > [[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. -- > Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283 __ 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] gls prediction using the correlation structure in nlme
How does one coerce predict.gls to incorporate the fitted correlation structure from the gls object into predictions? In the example below the AR(1) process with phi=0.545 is not used with predict.gls. Is there another function that does this? I'm going to want to fit a few dozen models varying in order from AR(1) to AR(3) and would like to look at the fits with the correlation structure included. Thanks in advance. -JC PS I am including the package maintainers on this post - does this constitute a maintainer-specific question in r-help etiquette? # example set.seed(123) x <- arima.sim(list(order = c(1,0,0), ar = 0.7), n = 100) y <-x + arima.sim(list(order = c(1,0,0), ar = 0.7), n = 100) x <- c(x) y <- c(y) lm1 <- lm(y~x) ar(residuals(lm1)) # indicates an ar1 model cs1 <- corARMA(p=1) fm1 <- gls(y~x,corr=cs1) summary(fm1) # get fits fits <- predict(fm1) # use coef to get fits fits2 <- coef(fm1)[1] + (coef(fm1)[2] * x) plot(fits,fits2) __ 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] [R-pkgs] AdMit version 1-01.01
Dear all, The new version of AdMit (version 1.01-01) is now available from CRAN. SUMMARY The package provides functions to perform the fitting of an adaptive mixture of Student-t distributions to a target density through its kernel function. The mixture approximation can then be used as the importance density in importance sampling or as the candidate density in the Metropolis-Hastings algorithm to obtain quantities of interest for the target density itself. We believe that this approach may be applicable in many fields of research and hope that the R package AdMit will be fruitful for many researchers like econometricians or applied statisticians. MODIFICATIONS o change in AdMit.R to deal with convergence problems for simple cases. o the documentation file has been improved (thanks to Achim Zeilis for comments). o a package vignette has been added. o a paper describing the package in detail has been published in the Journal of Statistical Software: http://www.jstatsoft.org/v29/i03. Abstract: This paper presents the R package AdMit which provides functions to approximate and sample from a certain target distribution given only a kernel of the target density function. The core algorithm consists in the function AdMit which fits an adaptive mixture of Student-t distributions to the density of interest via its kernel function. Then, importance sampling or the independence chain Metropolis-Hastings algorithm are used to obtain quantities of interest for the target density, using the fitted mixture as the importance or candidate density. The estimation procedure is fully automatic and thus avoids the time-consuming and difficult task of tuning a sampling algorithm. The relevance of the package is shown in two examples. The first aims at illustrating in detail the use of the functions provided by the package in a bivariate bimodal distribution. The second shows the relevance of the adaptive mixture procedure through the Bayesian estimation of a mixture of ARCH model fitted to foreign exchange log-returns data. The methodology is compared to standard cases of importance sampling and the Metropolis-Hastings algorithm using a naive candidate and with the Griddy-Gibbs approach. o creation of /doc folder with AdMitJSS.txt and AdMitRnews.txt files (the R codes used for JSS and Rnews papers). o CITATION file simplified. o 'coda' package is now Suggests REFERENCES Ardia D, Hoogerheide LF, van Dijk HK (2008). AdMit: Adaptive Mixture of Student-t Distributions in R. R package version 1.01-01. URL http://CRAN.R-project.org/package=AdMit. Ardia D, Hoogerheide LF, van Dijk HK (2009). Adaptive Mixture of Student-t Distributions as a Flexible Candidate Distribution for Efficient Simulation: The R Package AdMit. Journal of Statistical Software, 29(3), 1-32. URL http://www.jstatsoft.org/v29/i03/. Hoogerheide LF (2006). Essays on Neural Network Sampling Methods and Instrumental Variables. Ph.D. thesis, Tinbergen Institute, Erasmus University Rotterdam. Book nr. 379 of the Tinbergen Institute Research Series. Hoogerheide LF, Kaashoek JF, van Dijk HK (2007). On the Shape of Posterior Densities and Credible Sets in Instrumental Variable Regression Models with Reduced Rank: An Application of Flexible Sampling Methods using Neural Networks. Journal of Econometrics, 139(1), 154-180. doi:10.1016/j.jeconom.2006.06.009. Hoogerheide LF, van Dijk HK (2008a). Bayesian Forecasting of Value at Risk and Expected Shorfall Using Adaptive Importance Sampling. Technical Report 2008-092/4, Tinbergen Institute, Erasmus University Rotterdam. URL http://www.tinbergen.nl/ discussionpapers/08092.pdf. Hoogerheide LF, van Dijk HK (2008b). Possibly Ill-Behaved Posteriors in Econometric Models: On the Connection Between Model Structures, Non-Elliptical Credible Sets and Neural Network Simulation Techniques." Technical Report 2008-036/4, Tinbergen Institute, Erasmus University Rotterdam. URL http://www.tinbergen.nl/discussionpapers/08036.pdf. Best regards, David Ardia (package's maintainer) Lennart F. Hoogerheide Herman K. van Dijk [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] help with plot layout
We don't have your data, so we cannot reproduce what you are doing and the plot was stripped off before we saw it (only certain types of attachments are allowed, and some e-mail programs don't give the correct information about attachments so even those types can be stripped if it is not clear what they are). Here are some possible hints that may help (if I have guessed correctly about what you are trying to do). Read the help page for par, looking at the information on margins and outer margins, this can be used to give you more room for your titles (also the xpd argument if you are placing things outside the plot area). Also look at the various cex arguments for controlling sizes. Try using mtext instead of text to manually add titles or other text in the margins. Sometimes using the outer margins works better than using the regular margins (sometimes not). The text function uses the user coordinates of the current plot, the functions grconvertX and grconvertY can be used to convert between the different coordinate systems. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of mau...@alice.it > Sent: Wednesday, January 28, 2009 8:52 AM > To: r-h...@stat.math.ethz.ch > Cc: gunter.ber...@gene.com > Subject: [R] help with plot layout > > It takes a lot of sweat to generate a composite plot with R ... sigh. > I though I was almost done when I met the umpteenth hurdle. I cannot > place a nice title on the 2nd plot (raw signal) > on the layout. I do not have control on where either the "main" option > of "plot" function, or "title", place the text > string which keeps dysplaying chopped from above. I also tried "text", > changing many times the string coordinates, but could not see any text > anywhere on the canvas . > By the way, since the layout breaks the canvas into 4 parts, are the > text coordinates absolute (referred to the canvas) or > relative (referred to the part) ? > Please, find attached the generated drawing. The generating script is i > the following. > Thank you so much, > Maura > > ## > WavMaxNumCoef <- 30 > setwd("C:/Documents and Settings/Monville/SpAn-Tests/16440-Raw-Dir") > > xx <- read.table("Interp-Amp-PhasePlus16440.txt",header=TRUE, sep=" ") > NumCycles <- max(xx[,"cycle"]) > TickPos <- vector(length=NumCycles) > TickCoord <- vector(length=NumCycles) > for(i in 1:NumCycles) { > TickPos[i] <- xx[min(which(xx[,"cycle"] == i)),1] > } > > aa <- read.table( "16440-Alpha.txt" ) > xaa <- seq(1:length(t(aa))) > > vv <- read.table("16440-Vanishing-Moments") > vvLab <- seq(1,WavMaxNumCoef/2,1) > vvCounts <- vector(length=WavMaxNumCoef/2) > for(k in 1:(WavMaxNumCoef/2)) { > vvCounts[k] <- length(which(vv[] == k)) > } > yyLab <- seq(1,length(t(vv)),2) > > bb <- read.table("16440-Length") > bbLab <- seq(min(bb),max(bb),1) > bb <- sort(t(bb)) > bbCounts <- as.numeric(vector(length=(max(bb)-min(bb)+1))) > for(k in 1:length(bbCounts)) { > bbCounts[k] <- length(which(bb[] == (k +min(bb) -1))) > } > zzLab <- seq(1,max(bbCounts),1) > > # DEFINE LAYOUT > x11(width=22,height=14) > nf <- layout(matrix(c(1,3,2,4),2,2,byrow=TRUE), c(3,1), c(2,2),FALSE) > layout.show(nf) > > # PLOT DONOHO ALPHA > par(mar=c(10,4,2,5),xaxt="n",cex.axis=1,pty="m") > plot(xaa,t(aa),type="h") > par (xaxt="s",xaxp=c(0,95.964,24),xaxs="i") > > axis(1,at=TickPos,labels=as.character(TickPos),col="red",col.axis="red" > ,font.axis=1) > > # PLOT RAW SIGNAL > par(mar=c(3,4,0,5),xaxt="n",cex.axis=1,pty="m") > plot(xx[,1],xx[,2],pch=3,type="l",frame.plot=FALSE,xpd=TRUE) > title("Raw Signal 16440",cex.main=1.0,font=2) > par (xaxt="s",xaxp=c(0,95.964,24),xaxs="i") > > axis(1,at=TickPos,labels=as.character(TickPos),col="red",col.axis="red" > , font.axis=1) > > # PLOT VANISHING MOMENT DISTRIBUTION > par(mar=c(1,0,2,3),xaxt="n",yaxt="n",cex.axis=0.7,pty="m") > barplot(vvCounts,width=1,space=0,horiz=TRUE,axes=FALSE) > par(xaxt="s",yaxt="s",crt=180,srt=270,adj=1,las=3,xpd=TRUE) > text(x=25.5,y=15.3,pos=4,"Wavelet Vanishing Moments > Distribution",cex=1.0,font=2) > axis(2,at=vvLab- > 1,labels=as.character(vvLab),col="red",col.axis="red",font.axis=1,xpd=T > RUE, > cex.lab=1) > axis(3,at=yyLab- > 1,labels=as.character(yyLab),col="red",col.axis="red",font.axis=1,xpd=T > RUE, > cex.lab=0.8,cex.axis=0.8) > > # PLOT CYCLES LENGTH > par(mar=c(0,0,1,3),xaxt="n",yaxt="n",cex.axis=1) > barplot(bbCounts,width=1,axes=FALSE,space=0,horiz=TRUE) > > par(xaxt="s",yaxt="s",crt=180,srt=270,adj=1,las=3,cex.lab=0.1,xpd=TRUE) > text(x=15.5,y=65.3,pos=4,"Cycles Length Distribution",cex=1.0,font=2) > axis(2,at=as.numeric(bbLab)- > 41,labels=bbLab,col="red",col.axis="red",font.axis=1, > lab=c(10,10,15),cex.l
[R] stack data sets
Hi All, I'm generating 10 different data sets with 1 and 0 in a matrix form and writing the output in separate files. Now I need to stack all these data sets in one vector and I know that stack only operates on list or data frame however I got these data sets by converting list to a matrix so can't go backwards now. Is there a way i can still use Stack? Please see the program: #Importing psych & ltm library for all the simulation related functions library(ltm) library(psych) # Settting the working directory path to C:/NCME path="C:/NCME" setwd(path) #IRT Data Simulation Routine# n.exams = 500 #Sets number of examinees to be generated# n.items = 20 #Sets number of items to be generated# #The following intialize empty (NA) vectors or matrices# beta.values = rep(NA,n.items) resp.prob=matrix(rep(NA, n.exams*n.items), nrow=n.exams, ncol=n.items) Observed_Scores=matrix(rep(NA, n.exams*n.items), nrow=n.exams, ncol=n.items) str(Observed_Scores) for (k in 1:10) { #Setting the starting point for seed set.seed(k) #filling item parameters into beta.values beta.values = runif(n.items,-2,2) #Calculating Threshold thresh.values = .5 * beta.values #Using the function to generate the Parallel Model CTT data GenData <- congeneric.sim(N=500, loads = rep(.5,20), err=NULL, short = FALSE) #Storing Observed Score in a variable Observed_Scores = GenData[[3]] #Exporting Observed scores to output file ObservedScores_Data <- paste("Observed_Scores_",k,".dat") write.table(Observed_Scores,ObservedScores_Data,row.name=FALSE,col.name=FALSE) Zero = 0 One = 1 for (t in 1:20) { for (s in 1:500) { if (Observed_Scores[s,t]<= thresh.values[t]) resp.prob[s,t] = Zero else resp.prob[s,t] = One } } ResponseData <- paste("ResponseMatrix_",k,".dat") ThreshData <- paste("Threshold_",k,".dat") write.table(resp.prob,ResponseData,row.name=FALSE,col.name=FALSE) write.table(thresh.values,ThreshData,row.name=FALSE,col.name=FALSE) #STACKING ALL THE OUTPUTS# CommonFile <- stack(resp.prob) ## #Rounding upto 2 decimal places while showing the correlation matrix round(cor(GenData$observed),2) #Factor Score FactorScore=factor.pa(GenData$observed,1,scores = "TRUE") round(cor(FactorScore$scores,GenData$latent),2) filename_fs <- paste("FactorScore_",k,".dat") #Exporting Factor Scores to Output file write.table(FactorScore$scores,filename_fs,col.name=FALSE, row.name=FALSE) } Thank you Nidhi __ 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] constrainOptim
June Wong hotmail.com> writes: > > > Dear R helpers > > I have a question regarding the constrainOptim. > I'm coding the nested logit and would like to set a bound of rho to (0,1] as an extreme value distribution > where rho = exp(lambda)/1+exp(lambda) > I wonder if I can do that directly in optim (say rho > 0 & <= 1) or need to use constrainOptim > I read the help but still don't know how to set ui and ci > > Thanks, > June > optim() can do box constraints (i.e., independent inequality constraints on parameters): use method="L-BFGS-B" and the lower and upper arguments to set the bounds for each parameter (to -Inf and Inf if there are no bounds). If you want to set bounds on rho you have to use rho as the parameter in your model -- this is tricky if you can't solve for rho, but in your case lambda=log(rho/(1-rho)) Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Saving plot into file without showing it
Hi List, My apologies in advance if question is simplistic, I am quite new to R graphics capabilities and I could not find anything in past threads... I use R 2.8.1 under Mac OS X, but I would preferrably have a cross platform answer as I use also R under Windows I produce plots using R & save them in a file e.g. below: y <- rnorm(1000) x <- rnorm(1000) plot(x,y) dev.copy2pdf() Until there fine, it create a pdf file that is composed of my plot...My "issues" are the following: 1. If I want to produce the plot & save it directly in a pdf file without viewing it, how do I do that? 2. Can I create several plots in a row (without showing them in Quartz or whatever other graphic device) and save them all in separate files after creation? for example a function that would save me in separate files all what is visible through dev.list() Let's keep the example of saving in pdf format here...I do not have target file type for saving the graphics. The point is that I would have another piece of code (HTML I guess, not developed yet) fetching all the charts and presenting it nicely. Any feedback is appreciated Many thanks Julien _ charlas. [[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] Get median of each column
I am new to R. How can I get column median? Thanks.Frank [[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] R compilation
Hi Mates, I have a very long R code that needs to go to production but my portfolio managers do not use R language and the software is not supported by my bank. Is there any way I can compile the code to an executable file and make it usable to my portfolio managers who have no knowledge at all of R? Thanks Mama - Mama Attiglah, PhD Quantitative Strategist Liability Driven Investment State Street Global Advisors 25 Bank Street, London E14 5NU +44(0)20 7698 6290 (Direct Line) +44 (0)207 004 2968 (Direct Fax) Authorised and regulated by the Financial Services Authority. State Street Global Advisors Limited, a company registered in England with company number 2509928 and VAT number 5576591 81 and whose registered office is...{{dropped:12}} __ 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] Get median of each column
?apply > x <- matrix(1:25,5) > x [,1] [,2] [,3] [,4] [,5] [1,]16 11 16 21 [2,]27 12 17 22 [3,]38 13 18 23 [4,]49 14 19 24 [5,]5 10 15 20 25 > apply(x, 2, median) [1] 3 8 13 18 23 > On Wed, Jan 28, 2009 at 11:48 AM, Frank Zhang wrote: > I am new to R. How can I get column median? Thanks.Frank > > > >[[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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Saving plot into file without showing it
Try pdf("foo.pdf") plot(x) dev.off() Other possibilities are jpeg(), tiff(), postscript() etc. HTH, Stephan julien cuisinier schrieb: Hi List, My apologies in advance if question is simplistic, I am quite new to R graphics capabilities and I could not find anything in past threads... I use R 2.8.1 under Mac OS X, but I would preferrably have a cross platform answer as I use also R under Windows I produce plots using R & save them in a file e.g. below: y <- rnorm(1000) x <- rnorm(1000) plot(x,y) dev.copy2pdf() Until there fine, it create a pdf file that is composed of my plot...My "issues" are the following: 1. If I want to produce the plot & save it directly in a pdf file without viewing it, how do I do that? 2. Can I create several plots in a row (without showing them in Quartz or whatever other graphic device) and save them all in separate files after creation? for example a function that would save me in separate files all what is visible through dev.list() Let's keep the example of saving in pdf format here...I do not have target file type for saving the graphics. The point is that I would have another piece of code (HTML I guess, not developed yet) fetching all the charts and presenting it nicely. Any feedback is appreciated Many thanks Julien _ charlas. [[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] Saving plot into file without showing it
pdf("yourFile.pdf") plot(1) plot(2) plot(3) . dev.off() On Wed, Jan 28, 2009 at 12:26 PM, julien cuisinier wrote: > > Hi List, > > > My apologies in advance if question is simplistic, I am quite new to R > graphics capabilities and I could not find anything in past threads... > > I use R 2.8.1 under Mac OS X, but I would preferrably have a cross platform > answer as I use also R under Windows > > I produce plots using R & save them in a file > > e.g. below: > > y <- rnorm(1000) > x <- rnorm(1000) > plot(x,y) > dev.copy2pdf() > > Until there fine, it create a pdf file that is composed of my plot...My > "issues" are the following: > 1. If I want to produce the plot & save it directly in a pdf file without > viewing it, how do I do that? > 2. Can I create several plots in a row (without showing them in Quartz or > whatever other graphic device) and save them all in separate files after > creation? for example a function that would save me in separate files all > what is visible through dev.list() > > Let's keep the example of saving in pdf format here...I do not have target > file type for saving the graphics. The point is that I would have another > piece of code (HTML I guess, not developed yet) fetching all the charts and > presenting it nicely. > > > Any feedback is appreciated > > Many thanks > Julien > > _ > > charlas. > >[[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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Get median of each column
Assuming your data are in a data.frame called dataset, apply(dataset,2,median) should work. Look at ?apply HTH, Stephan Frank Zhang schrieb: I am new to R. How can I get column median? Thanks.Frank [[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] Repeated measures design for GAM? - corrected question...
Dear Simon, Many thanks for pointing me to the GAMM! For clarification, Bird_abundance are breeding densities ( e.g. 1.25 BP/ha, 2.20 BP/ha,...) and count is just the actual survey(e.g. first_survey,...). The dataset looks like Bird_abundance Study_area YEARCOUNT X1 X2 X3 X4 0.15area_1 2004first_survey 1.26area_1 2004second_survey 2.47area_1 2005third_survey 0.00area_1 2005fourth_survey 0.23area_1 2006fifht_survey 2.64area_1 2006sixth_survey 4.14area_2 2004first_survey 5.00area_2 2004second_survey 6.80area_2 2005third_survey 0.15area_2 2005fourth_survey 0.25area_2 2006fifht_survey 2.36area_2 2006sixth_survey 2.59area_3 2004first_survey 6.31area_3 2004second_survey 0.15area_3 2005third_survey 2.85area_3 2005fourth_survey 2.48area_3 2006fifht_survey 1.23area_3 2006sixth_survey Am I correct in assuming the following is a valid syntax for this repeated measures design?: model <-gamm(Bird_abundance ~ YEAR + s(X1)+ s(X2)+ s(X3)+ s(X4),random=list(count=~1,park=~1)) best wishes and thanks again, Diederik Diederik Strubbe Evolutionary Ecology Group Department of Biology, University of Antwerp Universiteitsplein 1 B-2610 Antwerp, Belgium http://webhost.ua.ac.be/deco tel : 32 3 820 23 85 -Original Message- From: Strubbe Diederik Sent: Wed 28-1-2009 18:09 To: r-help@R-project.org Subject: Repeated measures design for GAM? - corrected question... Dear all, I have a question on the use of GAM with repeated measures. My dataset is as follows: - a number of study areas where bird abundance has been determined. Counts have been performed in 3 consecutive years and there were 2 counts per year (i.e. in total 6 counts). - a number of environmental predictors that do not change over year Xi). When using a GLM, a repeated measures design would like: (for example) lme(Bird_abundance = study_area + count +year+ X1 + X2 + X3,random = ~count|study_area). However, I have found no analogue design for a GAM. For now, I have averaged my bird abundances but I wondered whether a more subtle and elegant strategy exists...? Many thanks, Diederik Diederik Strubbe Evolutionary Ecology Group Department of Biology, University of Antwerp Universiteitsplein 1 B-2610 Antwerp, Belgium http://webhost.ua.ac.be/deco tel : 32 3 820 23 85 [[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] Get median of each column
On 29/01/2009, at 8:39 AM, Stephan Kolassa wrote: Assuming your data are in a data.frame called dataset, apply(dataset,2,median) should work. Look at ?apply Note that apply() works with ***matrices***. The foregoing code will work, given that all columns of ``dataset'' are numeric, due to the fact that apply will *coerce* a data frame to a matrix. However it should always be remembered that DATA FRAMES ARE NOT MATRICES!!! cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ 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] Power analysis for MANOVA?
Hi Adam, first: I really don't know much about MANOVA, so I sadly can't help you without learning about it an Pillai's V... which I would be glad to do, but I really don't have the time right now. Sorry! Second: you seem to be doing a kind of "post-hoc power analysis", "my result isn't significant, perhaps that's due to low power? Let's look at the power of my experiment!" My impression is that "post-hoc power analysis" and its interpretation is, shall we say, not entirely accepted within the statistical community, see: Hoenig, J. M., & Heisey, D. M. (2001, February). The abuse of power: The pervasive fallacy of power calculations for data analysis. The American Statistician, 55 (1), 1-6 And this: http://staff.pubhealth.ku.dk/~bxc/SDC-courses/power.pdf However, I am sure that lots of people can discuss this more competently than me... Best wishes Stephan Adam D. I. Kramer schrieb: On Mon, 26 Jan 2009, Stephan Kolassa wrote: My (and, judging from previous traffic on R-help about power analyses, also some other people's) preferred approach is to simply simulate an effect size you would like to detect a couple of thousand times, run your proposed analysis and look how often you get significance. In your simple case, this should be quite easy. I actually don't have much experience running monte-carlo designs like this...so while I'd certainly prefer a bootstrapping method like this one, simulating the effect size given my constraints isn't something I've done before. The MANOVA procedure takes 5 dependent variables, and determines what combination of the variables best discriminates the two levels of my independent variable...then the discrimination rate is represented in the statistic (Pillai's V=.00019), which is then tested (F[5,18653] = 0.71). So coming up with a set of constraints that would produce V=.00019 given my data set doesn't quite sound trivial...so I'll go for the "par" library reference mentioned earlier before I try this. That said, if anyone can refer me to a tool that will help me out (or an instruction manual for RNG), I'd also be much obliged. Many thanks, Adam HTH, Stephan Adam D. I. Kramer schrieb: Hello, I have searched and failed for a program or script or method to conduct a power analysis for a MANOVA. My interest is a fairly simple case of 5 dependent variables and a single two-level categorical predictor (though the categories aren't balanced). If anybody happens to know of a script that will do this in R, I'd love to know of it! Otherwise, I'll see about writing one myself. What I currently see is this, from help.search("power"): stats::power.anova.test Power calculations for balanced one-way analysis of variance tests stats::power.prop.test Power calculations two sample test for proportions stats::power.t.test Power calculations for one and two sample t tests Any references on power in MANOVA would also be helpful, though of course I will do my own lit search for them myself. Cordially, Adam D. I. Kramer __ 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] Get median of each column
Thank you, Rolf, for this well-deserved spanking :-) I promise to amend my ways and think before I send in the future. Best, Stephan Rolf Turner schrieb: On 29/01/2009, at 8:39 AM, Stephan Kolassa wrote: Assuming your data are in a data.frame called dataset, apply(dataset,2,median) should work. Look at ?apply Note that apply() works with ***matrices***. The foregoing code will work, given that all columns of ``dataset'' are numeric, due to the fact that apply will *coerce* a data frame to a matrix. However it should always be remembered that DATA FRAMES ARE NOT MATRICES!!! cheers, Rolf Turner ## Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.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] Cor(df,method = "kendall")
Hi All, Does anyone know of any issues at all with using; Cor(df,method = ³kendall²) On a dataframe (df) 13 columns wide say? Seems to hang my system for a while in calculating the correlation matrix appreciate it is doing some ranking calculations so I am expecting too much that it should return immediately ? In particular trying to use function in Excel (reval) and I am getting OLE error boxes as RGUI hangs. Many Thanks. Glenn [[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] R compilation
yes, first don't crosspost. It all depends on what OS .. blah, blah, blah. You must read the posting guide because it will up your chances of a reply. On Wed, Jan 28, 2009 at 1:37 PM, Attiglah, Mama wrote: > > Hi Mates, > I have a very long R code that needs to go to production but my portfolio > managers do not use R language and the software is not supported by my bank. > Is there any way I can compile the code to an executable file and make it > usable to my portfolio managers who have no knowledge at all of R? > > Thanks > > Mama > - > Mama Attiglah, PhD > Quantitative Strategist > Liability Driven Investment > State Street Global Advisors > 25 Bank Street, London E14 5NU > +44(0)20 7698 6290 (Direct Line) > +44 (0)207 004 2968 (Direct Fax) > Authorised and regulated by the Financial Services Authority. > State Street Global Advisors Limited, a company registered in England with > company number 2509928 > and VAT number 5576591 81 and whose registered office ...{{dropped:21}} __ 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] Newbie Question About Histograms
Hello everyone. Just have a question , cant figure out how to make this histogram. I have this table, that i stored in a variable name new.data2. Table looks like this Year GeoArea SmpNo Month Gear Maturity Length Age YearC 1989 1 36210 221225 1 1988 1991 1 26710 101191 1 1990 1991 1 26710 101202 1 1990 1992 1 3051081162 1 1991 1992 1 3051081165 1 1991 1992 1 3051081166 1 1991 1992 1 3051081167 1 1991 1992 1 3051081167 1 1991 1992 1 3051081169 1 1991 1992 1 3051081170 1 1991 Now I need to make a histogram of Length vs YearC. I would guess that Length would be on the Y-axis and YearC variable would be on X-axis. I have tried many different combinations with command 'hist' but im always getting error " 'x' must be numeric " ... I think im getting that error because of the header which is not numeric. Any help would be appreciated. Thanks guys. Ivan. -- View this message in context: http://www.nabble.com/Newbie-Question-About-Histograms-tp21713626p21713626.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 with normal distribution in random samples...
Hi!!! First time 'R' user looking for a little assistance. Here is what I have so far: practice1 = matrix ((runif(5000, min =0, max = 12)), 100) which is creating 50 samples, for 100 cases, distributed between 0-12. What I would like is to be able to set the mean and SD so that the data is normally distributed around lets say 7. Any help I can get with achieving that goal would be greatly appreciated!!! -Dan -- View this message in context: http://www.nabble.com/Help-with-normal-distribution-in-random-samples...-tp21713636p21713636.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] Newbie Question About Histograms
Kia ora Ivan I think you might want a barplot. ?hist under 'See Also:' states: Typical plots with vertical bars are _not_ histograms. Consider 'barplot' or 'plot(*, type = "h")' for such bar plots. [The online help in R is good.] HTH Peter Alspach > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of pfc_ivan > Sent: Thursday, 29 January 2009 9:04 a.m. > To: r-help@r-project.org > Subject: [R] Newbie Question About Histograms > > > Hello everyone. Just have a question , cant figure out how to > make this histogram. > > I have this table, that i stored in a variable name > new.data2. Table looks like this > > Year GeoArea SmpNo Month Gear Maturity Length Age YearC > 1989 1 36210 221225 1 1988 > 1991 1 26710 101191 1 1990 > 1991 1 26710 101202 1 1990 > 1992 1 3051081162 1 1991 > 1992 1 3051081165 1 1991 > 1992 1 3051081166 1 1991 > 1992 1 3051081167 1 1991 > 1992 1 3051081167 1 1991 > 1992 1 3051081169 1 1991 > 1992 1 3051081170 1 1991 > > Now I need to make a histogram of Length vs YearC. I would > guess that Length would be on the Y-axis and YearC variable > would be on X-axis. I have tried many different combinations > with command 'hist' but im always getting error " 'x' must be > numeric " ... I think im getting that error because of the > header which is not numeric. Any help would be appreciated. > Thanks guys. > > Ivan. > -- > View this message in context: > http://www.nabble.com/Newbie-Question-About-Histograms-tp21713 > 626p21713626.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. > The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited. __ 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] Text data
i have a data column of text entries: 26M_AN_C.bmp 22M_AN_C.bmp 20M_HA_O.bmp 20M_AN_C.bmp 26M_HA_O.bmp 22M_HA_O.bmp 31M_AN_C.bmp 38M_HA_O.bmp . . . . And I would like to sort by the middle tag: AN, HA, etc. Is there a way to parse text data in R? In excel, I would have used the "left" and "right" function to cut out just the middle two letters out and put into another column to sort by. Thanks! -- View this message in context: http://www.nabble.com/Text-data-tp21714334p21714334.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] Changing histogram stack in qplot
I've been using qplot pretty successfully to generate stacked histograms. However, it appears that I need to tweak the colors a little. I've got three temperature variables (characters not numeric) and I need to change from the default qplot colors to the following: Low = Blue Middle = black High = Red Here is pseudo code of what I have currently:qplot(Run, data = TestData, breaks = hist_breaks, , fill = TestData$Temperature, main = short_title) + scale_x_continuous("Run, Radians") + scale_y_continuous("Frequency") + scale_fill_discrete("Temperature") Thanks for any advice and insights. [[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] Text data
This will sort on those characters: > x <- readLines(textConnection("26M_AN_C.bmp + 22M_AN_C.bmp + 20M_HA_O.bmp + 20M_AN_C.bmp + 26M_HA_O.bmp + 22M_HA_O.bmp + 31M_AN_C.bmp + 38M_HA_O.bmp")) > closeAllConnections() > # pick off characters between "_" > sortKey <- sub(".*_(.+)_.*", "\\1", x) > sortKey [1] "AN" "AN" "HA" "AN" "HA" "HA" "AN" "HA" > # output sorted list > x[order(sortKey)] [1] "26M_AN_C.bmp" "22M_AN_C.bmp" "20M_AN_C.bmp" "31M_AN_C.bmp" "20M_HA_O.bmp" "26M_HA_O.bmp" "22M_HA_O.bmp" "38M_HA_O.bmp" > > On Wed, Jan 28, 2009 at 3:37 PM, Alice Lin wrote: > > i have a data column of text entries: > 26M_AN_C.bmp > 22M_AN_C.bmp > 20M_HA_O.bmp > 20M_AN_C.bmp > 26M_HA_O.bmp > 22M_HA_O.bmp > 31M_AN_C.bmp > 38M_HA_O.bmp > . > . > . > . > > > And I would like to sort by the middle tag: AN, HA, etc. > Is there a way to parse text data in R? > > In excel, I would have used the "left" and "right" function to cut out just > the middle two letters out and put into another column to sort by. > > Thanks! > > -- > View this message in context: > http://www.nabble.com/Text-data-tp21714334p21714334.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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Help with normal distribution in random samples...
?rnorm On Wed, Jan 28, 2009 at 4:04 PM, Sea Captain 1779 wrote: > > Hi!!! > > First time 'R' user looking for a little assistance. Here is what I have so > far: > > practice1 = matrix ((runif(5000, min =0, max = 12)), 100) > > which is creating 50 samples, for 100 cases, distributed between 0-12. What > I would like is to be able to set the mean and SD so that the data is > normally distributed around lets say 7. Any help I can get with achieving > that goal would be greatly appreciated!!! > > -Dan > -- > View this message in context: > http://www.nabble.com/Help-with-normal-distribution-in-random-samples...-tp21713636p21713636.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. > -- Mike Lawrence Graduate Student Department of Psychology Dalhousie University www.thatmike.com Looking to arrange a meeting? Check my public calendar: http://www.thatmike.com/mikes-public-calendar ~ Certainty is folly... I think. ~ __ 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] Text data
Jim's solution is more elegant than the following (and probably more efficient) but you could also try the following (This let's you sort by AN/HN, and then by the number at the start of the filename): > text <- c( "26M_AN_C.bmp", "22M_AN_C.bmp", "20M_HA_O.bmp", "20M_AN_C.bmp", "26M_HA_O.bmp", "22M_HA_O.bmp", "31M_AN_C.bmp", "38M_HA_O.bmp") > split <- do.call("rbind",strsplit(text,"_")) > o <- order(split[,2],split[,1],split[,3]) > text[o] [1] 20M_AN_C.bmp" "22M_AN_C.bmp" "26M_AN_C.bmp" "31M_AN_C.bmp" "20M_HA_O.bmp" [6] "22M_HA_O.bmp" "26M_HA_O.bmp" "38M_HA_O.bmp" -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alice Lin Sent: Wednesday, January 28, 2009 3:38 PM To: r-help@r-project.org Subject: [R] Text data i have a data column of text entries: 26M_AN_C.bmp 22M_AN_C.bmp 20M_HA_O.bmp 20M_AN_C.bmp 26M_HA_O.bmp 22M_HA_O.bmp 31M_AN_C.bmp 38M_HA_O.bmp . . . . And I would like to sort by the middle tag: AN, HA, etc. Is there a way to parse text data in R? In excel, I would have used the "left" and "right" function to cut out just the middle two letters out and put into another column to sort by. Thanks! -- View this message in context: http://www.nabble.com/Text-data-tp21714334p21714334.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. === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S. News & World Report (2008). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ 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] Help with normal distribution in random samples...
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Sea Captain 1779 > Sent: Wednesday, January 28, 2009 12:04 PM > To: r-help@r-project.org > Subject: [R] Help with normal distribution in random samples... > > > Hi!!! > > First time 'R' user looking for a little assistance. Here is > what I have so > far: > > practice1 = matrix ((runif(5000, min =0, max = 12)), 100) > > which is creating 50 samples, for 100 cases, distributed > between 0-12. What > I would like is to be able to set the mean and SD so that the data is > normally distributed around lets say 7. Any help I can get > with achieving > that goal would be greatly appreciated!!! > > -Dan Use rnorm() instead of runif(). Hope this is helpful, A different Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Changing histogram stack in qplot
Hi Jason, You'll need scale_fill_manual(values = c(low = "blue", middle = "black", high = "red")) See http://had.co.nz/ggplot2/scale_manual.html for more examples/details. Regards, Hadley On Wed, Jan 28, 2009 at 3:11 PM, Jason Rupert wrote: > I've been using qplot pretty successfully to generate stacked histograms. > However, it appears that I need to tweak the colors a little. > > I've got three temperature variables (characters not numeric) and I need to > change from the default qplot colors to the following: > Low = Blue > Middle = black > High = Red > > Here is pseudo code of what I have currently:qplot(Run, data = TestData, > breaks = hist_breaks, , > fill = TestData$Temperature, > main = short_title) + > scale_x_continuous("Run, Radians") + > scale_y_continuous("Frequency") + > scale_fill_discrete("Temperature") > > Thanks for any advice and insights. > > > > > >[[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. > > -- http://had.co.nz/ __ 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] Memory issue?
I had similar issues with memory occupancy. You should explicitly call gc() to call the garbage collector (free memory routine) after you do rm() of the big objects. D. __ 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] rproxy.dll
Duncan Murdoch-2 wrote: > > On 25/10/2008 1:01 PM, Murray Eisenberg wrote: >> Is rproxy.dll supposed to be installed as part of a Windows binary >> installation of R? And the installer put it in R's bin subdirectory? >> >> If so, it seems to be missing from the R-2.8.0 patched, 2008-10-25 >> (r46779), that I installed. >> > > See the CHANGES file: > > oRproxy.dll is no longer part of the R distribution: it has > been replaced by CRAN package rscproxy. > > 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. > > Hi! Since rproxy.dll has been replaced by rscproxy, how can I use the (R)-D COM dll? Cheers! Clément D -- View this message in context: http://www.nabble.com/rproxy.dll-tp20165941p21715182.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] Newbie Question About Histograms
Also I forgot to say that The Y-axis values for each YearC would be the mean value of all the Lenghts that happen in that YearC. Basically I cant figure out how to put the mean values of Lengths for each YearC on Y axis. Thanks in advance! -- View this message in context: http://www.nabble.com/Newbie-Question-About-Histograms-tp21713626p21714995.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] for/if loop
Hi ya, I've revised the code (and finally know what I m doing.. :-D) The good news is.. I dont get any error message, but the bad news is the following optim generate no results. I still think there is something to do with my loop... can anyone advice? Thanks again!!! pp=1 rr=1 for (ii in 1:n){ if (!(panel[ii] == pp)){ hll[pp,1] == sum(lselb1[rr:ii-1]) hll[pp,2] == sum(lselb2[rr:ii-1]) rr==ii pp==pp+1 } if (ii==n){ hll[pp,1] == sum(lselb1[rr:ii]) hll[pp,2] == sum(lselb2[rr:ii]) rr==ii pp==pp+1 } ii=ii+1 } pp=1 rr=1 for (ii in 1:n){ if (!(panel[ii] == pp)){ hll[pp,1] == sum(lselb1[rr:ii-1]) hll[pp,2] == sum(lselb2[rr:ii-1]) rr==ii pp==pp+1 } if (ii==n){ hll[pp,1] == sum(lselb1[rr:ii]) hll[pp,2] == sum(lselb2[rr:ii]) rr==ii pp==pp+1 } ii=ii+1 } SnowManPaddington wrote: > > Hi, it's my first time to write a loop with R for my homework. This loop > is part of the function. I wanna assign values for hll according to panel > [ii,1]=pp. I didn't get any error message in this part. but then when I > further calculate another stuff with hll, the function can't return. I > think it must be some problem in my loop. Probably something stupid or > easy. But I tried to look for previous posts in forum and read R language > help. But none can help.. Thanks! > > > > for (ii in 1:100){ > for (pp in 1:pp+1){ > for (rr in 1:rr+1){ > if (panel[ii,1]!=pp) > { > hll(pp,1)=ColSums(lselb1(rr:ii-1,1)) > hll(pp,2)=ColSums(lselb2(rr:ii-1,1)) > rr=ii > pp=pp+1 > } > else > { > hll(pp,1)=ColSums(lselb1(rr:ii,1)) > hll(pp,2)=ColSums(lselb2(rr:ii,1)) > rr=ii > pp=pp+1} > } > }}} > > > in fact I have the corresponding Gauss code here. But I really don't know > how to write such loop in R. > > rr=1; > ii=1; > pp=1; > do until ii==n+1; > if pan[ii,1] ne pp; > hll[pp,1]=sumc(lselb1[rr:ii-1,1]); > hll[pp,2]=sumc(lselb2[rr:ii-1,1]); > rr=ii; > pp=pp+1; > endif; > if ii==n; > hll[pp,1]=sumc(lselb1[rr:ii,1]); > hll[pp,2]=sumc(lselb2[rr:ii,1]); > rr=ii; > pp=pp+1; > endif; > ii=ii+1; > endo; > > -- View this message in context: http://www.nabble.com/for-if-loop-tp21701496p21715928.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] Newbie Question About Histograms
How about > dta<-read.table("clipboard",header=T) > means<-aggregate(dta$Length,by=list(YearC=dta$YearC),FUN=mean) > barplot(means[,2],names.arg=means[,1]) you may have a look at ?barplot to see (lots of) options for fine tuning the plot. hth. pfc_ivan schrieb: Also I forgot to say that The Y-axis values for each YearC would be the mean value of all the Lenghts that happen in that YearC. Basically I cant figure out how to put the mean values of Lengths for each YearC on Y axis. 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] Using R in a web application
Will Glass-Husain wrote: Hi, I want to use R to do user-submitted jobs in a (java-based) webapp. Specifically, I want * users to upload R scripts * run the R job on user data * save the results to database I'm concerned about sandbox issues. * Is it possible to disable file read/write capability? * Can I prevent the user from loading packages (e.g. the database package). * Can I have users work on separate data sets while preventing access to other user's data? I'm trying to see if there's a secure way to let users upload their R scripts and run on my server. Have a look at Rserve (http://www.rforge.net/Rserve), I've never used it but it might be useful to you. -- Gad Abraham Dept. CSSE and NICTA The University of Melbourne Parkville 3010, Victoria, Australia email: gabra...@csse.unimelb.edu.au web: http://www.csse.unimelb.edu.au/~gabraham __ 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] Changing histogram stack in qplot
Worked beautifully! Thank you again for providing such a flexible package. --- On Wed, 1/28/09, hadley wickham wrote: From: hadley wickham Subject: Re: [R] Changing histogram stack in qplot To: jasonkrup...@yahoo.com Cc: R-help@r-project.org Date: Wednesday, January 28, 2009, 3:32 PM Hi Jason, You'll need scale_fill_manual(values = c(low = "blue", middle = "black", high = "red")) See http://had.co.nz/ggplot2/scale_manual.html for more examples/details. Regards, Hadley On Wed, Jan 28, 2009 at 3:11 PM, Jason Rupert wrote: > I've been using qplot pretty successfully to generate stacked histograms. However, it appears that I need to tweak the colors a little. > > I've got three temperature variables (characters not numeric) and I need to change from the default qplot colors to the following: > Low = Blue > Middle = black > High = Red > > Here is pseudo code of what I have currently:qplot(Run, data = TestData, breaks = hist_breaks, , > fill = TestData$Temperature, > main = short_title) + > scale_x_continuous("Run, Radians") + scale_y_continuous("Frequency") + > scale_fill_discrete("Temperature") > > Thanks for any advice and insights. > > > > > >[[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. > > -- http://had.co.nz/ [[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] Dynamic random effects model
All R experts, How do I fit a dynamic Random effects model with a binary dependent variable in R Thanks JCM [[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] [SPAM] - Re: for/if loop - Bayesian Filter detected spam
Well, maybe you are just bad at typing then ;-) The lines rr==ii, pp==pp+1, etc. are not setting rr and pp but comparing them. Probably you want rr <- ii and pp <- pp+1, etc. And the last line of your loop 'ii=ii+1' means that, since the for statement is already incrementing ii, you are incrementing it twice and skipping the even indices. Omit this line probably. You are also forgetting(?) the operator precedence in sum(lselb1[rr:ii-1]) and similar lines. Note that this is equivalent to sum(lselb1[(rr-1):(ii-1)]); is that what you meant? Or did you want sum(lselb1[rr:(ii-1)])? You are changing some variables but not asking R to print anything as far as I can see. To see the results, ask R to print hll. HTH, -- David -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of SnowManPaddington Sent: Wednesday, January 28, 2009 3:59 PM To: r-help@r-project.org Subject: [SPAM] - Re: [R] for/if loop - Bayesian Filter detected spam Hi ya, I've revised the code (and finally know what I m doing.. :-D) The good news is.. I dont get any error message, but the bad news is the following optim generate no results. I still think there is something to do with my loop... can anyone advice? Thanks again!!! pp=1 rr=1 for (ii in 1:n){ if (!(panel[ii] == pp)){ hll[pp,1] == sum(lselb1[rr:ii-1]) hll[pp,2] == sum(lselb2[rr:ii-1]) rr==ii pp==pp+1 } if (ii==n){ hll[pp,1] == sum(lselb1[rr:ii]) hll[pp,2] == sum(lselb2[rr:ii]) rr==ii pp==pp+1 } ii=ii+1 } pp=1 rr=1 for (ii in 1:n){ if (!(panel[ii] == pp)){ hll[pp,1] == sum(lselb1[rr:ii-1]) hll[pp,2] == sum(lselb2[rr:ii-1]) rr==ii pp==pp+1 } if (ii==n){ hll[pp,1] == sum(lselb1[rr:ii]) hll[pp,2] == sum(lselb2[rr:ii]) rr==ii pp==pp+1 } ii=ii+1 } SnowManPaddington wrote: > > Hi, it's my first time to write a loop with R for my homework. This loop > is part of the function. I wanna assign values for hll according to panel > [ii,1]=pp. I didn't get any error message in this part. but then when I > further calculate another stuff with hll, the function can't return. I > think it must be some problem in my loop. Probably something stupid or > easy. But I tried to look for previous posts in forum and read R language > help. But none can help.. Thanks! > > > > for (ii in 1:100){ > for (pp in 1:pp+1){ > for (rr in 1:rr+1){ > if (panel[ii,1]!=pp) > { > hll(pp,1)=ColSums(lselb1(rr:ii-1,1)) > hll(pp,2)=ColSums(lselb2(rr:ii-1,1)) > rr=ii > pp=pp+1 > } > else > { > hll(pp,1)=ColSums(lselb1(rr:ii,1)) > hll(pp,2)=ColSums(lselb2(rr:ii,1)) > rr=ii > pp=pp+1} > } > }}} > > > in fact I have the corresponding Gauss code here. But I really don't know > how to write such loop in R. > > rr=1; > ii=1; > pp=1; > do until ii==n+1; > if pan[ii,1] ne pp; > hll[pp,1]=sumc(lselb1[rr:ii-1,1]); > hll[pp,2]=sumc(lselb2[rr:ii-1,1]); > rr=ii; > pp=pp+1; > endif; > if ii==n; > hll[pp,1]=sumc(lselb1[rr:ii,1]); > hll[pp,2]=sumc(lselb2[rr:ii,1]); > rr=ii; > pp=pp+1; > endif; > ii=ii+1; > endo; > > -- View this message in context: http://www.nabble.com/for-if-loop-tp21701496p21715928.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] questions about histogram
Hi all, I'm a new R user. I have the following information about a data set and how to make a histogram? data number of observations 0-2 25 2-10 10 10-100 10 100-1000 5 I tried barplot(height=...,width=...,...), the output looks right but the x-axis is missing. How to fix it? Also can I use to draw it? Thanks! WX __ 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] [SPAM] - Re: for/if loop - Bayesian Filter detected spam
On Wed, Jan 28, 2009 at 2:41 PM, wrote: > Well, maybe you are just bad at typing then ;-) > > The lines rr==ii, pp==pp+1, etc. are not setting rr and pp but comparing > them. > Probably you want rr <- ii and pp <- pp+1, etc. > And the last line of your loop 'ii=ii+1' means that, > since the for statement is already incrementing ii, > you are incrementing it twice and skipping the even indices. Omit this > line probably. That is actually not the case (because of the scoping rules for for(), I think). Example: > for (ii in 1:5) { print(ii); ii <- ii + 1; } [1] 1 [1] 2 [1] 3 [1] 4 [1] 5 Another "counter intuitive" (though it isn't) example: for (ii in 1:3) { cat("Outer ii:",ii,"\n"); for (ii in ii:3) { cat(" Inner ii:",ii,"\n"); } } Outer ii: 1 Inner ii: 1 Inner ii: 2 Inner ii: 3 Outer ii: 2 Inner ii: 2 Inner ii: 3 Outer ii: 3 Inner ii: 3 My $.02 /Henrik > You are also forgetting(?) the operator precedence in > sum(lselb1[rr:ii-1]) and similar lines. > Note that this is equivalent to sum(lselb1[(rr-1):(ii-1)]); is that what > you meant? > Or did you want sum(lselb1[rr:(ii-1)])? > You are changing some variables but not asking R to print anything as > far as I can see. > To see the results, ask R to print hll. > > HTH, > -- David > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of SnowManPaddington > Sent: Wednesday, January 28, 2009 3:59 PM > To: r-help@r-project.org > Subject: [SPAM] - Re: [R] for/if loop - Bayesian Filter detected spam > > > Hi ya, I've revised the code (and finally know what I m doing.. :-D) > > The good news is.. I dont get any error message, but the bad news is the > following optim generate no results. I still think there is something to > do > with my loop... can anyone advice? Thanks again!!! > > > > pp=1 > rr=1 > > for (ii in 1:n){ >if (!(panel[ii] == pp)){ >hll[pp,1] == sum(lselb1[rr:ii-1]) >hll[pp,2] == sum(lselb2[rr:ii-1]) >rr==ii >pp==pp+1 >} > >if (ii==n){ >hll[pp,1] == sum(lselb1[rr:ii]) >hll[pp,2] == sum(lselb2[rr:ii]) >rr==ii >pp==pp+1 >} >ii=ii+1 > } > > > > > > pp=1 > rr=1 > > for (ii in 1:n){ >if (!(panel[ii] == pp)){ >hll[pp,1] == sum(lselb1[rr:ii-1]) >hll[pp,2] == sum(lselb2[rr:ii-1]) >rr==ii >pp==pp+1 >} > >if (ii==n){ >hll[pp,1] == sum(lselb1[rr:ii]) >hll[pp,2] == sum(lselb2[rr:ii]) >rr==ii >pp==pp+1 >} >ii=ii+1 > } > > > > > > SnowManPaddington wrote: >> >> Hi, it's my first time to write a loop with R for my homework. This > loop >> is part of the function. I wanna assign values for hll according to > panel >> [ii,1]=pp. I didn't get any error message in this part. but then when > I >> further calculate another stuff with hll, the function can't return. I >> think it must be some problem in my loop. Probably something stupid or >> easy. But I tried to look for previous posts in forum and read R > language >> help. But none can help.. Thanks! >> >> >> >> for (ii in 1:100){ >> for (pp in 1:pp+1){ >> for (rr in 1:rr+1){ >> if (panel[ii,1]!=pp) >> { >> hll(pp,1)=ColSums(lselb1(rr:ii-1,1)) >> hll(pp,2)=ColSums(lselb2(rr:ii-1,1)) >> rr=ii >> pp=pp+1 >> } >> else >> { >> hll(pp,1)=ColSums(lselb1(rr:ii,1)) >> hll(pp,2)=ColSums(lselb2(rr:ii,1)) >> rr=ii >> pp=pp+1} >> } >> }}} >> >> >> in fact I have the corresponding Gauss code here. But I really don't > know >> how to write such loop in R. >> >> rr=1; >> ii=1; >> pp=1; >> do until ii==n+1; >> if pan[ii,1] ne pp; >> hll[pp,1]=sumc(lselb1[rr:ii-1,1]); >> hll[pp,2]=sumc(lselb2[rr:ii-1,1]); >> rr=ii; >> pp=pp+1; >> endif; >> if ii==n; >> hll[pp,1]=sumc(lselb1[rr:ii,1]); >> hll[pp,2]=sumc(lselb2[rr:ii,1]); >> rr=ii; >> pp=pp+1; >> endif; >> ii=ii+1; >> endo; >> >> > > -- > View this message in context: > http://www.nabble.com/for-if-loop-tp21701496p21715928.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, repr