Re: [R] Why missing values are not allowed in 'poly'?
On Mon, Mar 28, 2016 at 8:32 PM, William Dunlap <wdun...@tibco.com> wrote: > If poly were to be changed to allow NA's, how should it act in the > multivariate case when raw=FALSE? > Thank you Bill for looking into this. I was playing myself with your proposed code to come up with a clean patch, and ran into the same queries as you did, i.e. what to do when the NA structure is different in the multivariate case? In the univariate case or in the multivariate case when the NA structure is identical things are straightforward. But in the multivariate case with differing NA structure I'm not sure what is the expected output. Regards, Liviu > Suppose x1 had an NA in position 1 only and x2 had NA in position 2 only. > Should the output matrix have NAs in all columns of rows 1 and 2 with its > coefs attribute reflectiing only the data in na.omit(cbind(x1,x2))? This > would make the output matrix orthonormal after NA removal. > > Or should it remove NAs from the input vectors independently? This is > analogous to what predict.poly() currently does - different columns of the > output will have different patterns of NAs. > > An example of the first method would be: >> poly(c(NA,2,5,7,8), c(1,NA,3,4,9), degree=2) > 1.02.00.1 1.10.2 > [1,] NA NA NA NA NA > [2,] NA NA NA NA NA > [3,] -0.7715167 0.2672612 -0.5132649 0.39599247 0.6350006 > [4,] 0.1543033 -0.8017837 -0.2932942 -0.04525628 -0.7620008 > [5,] 0.6172134 0.5345225 0.8065591 0.49781910 0.1270001 > attr(,"degree") > [1] 1 2 1 2 2 > attr(,"coefs") > [[1]] > [[1]]$alpha > [1] 6.67 6.190476 > > [[1]]$norm2 > [1] 1.00 3.00 4.67 2.571429 > > [[2]] > [[2]]$alpha > [1] 5.33 6.989247 > > [[2]]$norm2 > [1] 1.0 3.0 20.7 14.51613 > attr(,"class") > [1] "poly" "matrix" > > and the second >> poly(c(NA,2,5,7,8), c(1,NA,3,4,9), degree=2) > 1.02.0 0.1 1.10.2 > [1,] NA NA -0.55132280 NA 0.6398330 > [2,] -0.7637626 0.3988620 NA NA NA > [3,] -0.1091089 -0.7407437 -0.21204723 0.02313625 -0.3442756 > [4,] 0.3273268 -0.1709409 -0.04240945 -0.01388175 -0.6106021 > [5,] 0.5455447 0.5128226 0.80577948 0.43958875 0.3150447 > attr(,"degree") > [1] 1 2 1 2 2 > attr(,"coefs") > [[1]] > [[1]]$alpha > [1] 5.50 4.357143 > > [[1]]$norm2 > [1] 1.0 4.0 21.0 56.57143 > > [[2]] > [[2]]$alpha > [1] 4.25 6.289568 > > [[2]]$norm2 > [1] 1. 4. 34.7500 176.6331 > attr(,"class") > [1] "poly" "matrix" > > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Thu, Mar 24, 2016 at 4:54 AM, Martin Maechler > <maech...@stat.math.ethz.ch> wrote: >> >> >>>>> William Dunlap via R-help <r-help@r-project.org> >> >>>>> on Wed, 23 Mar 2016 13:56:35 -0700 writes: >> >> > I don't know what is in R's poly(), but if it is like S+'s or TERR's >> then >> > one could do >> >> > if (anyNA(x)) { >> > nax <- na.exclude(x) >> > px <- poly(x = nax, degree = degree, coefs = coefs, raw = >> > raw, simple = simple) >> > px <- structure(naresid(attr(nax, "na.action"), px), coefs >> > = attr(px, "coefs"), degree = attr(px, "degree"), class = attr(px, >> "class")) >> > return(px) >> > } >> >> > and get nice results in the usual raw=FALSE case as well. Similar >> stuff >> > could be done in the multivariate cases. >> >> I don't have too much time for that now, >> and I know that Bill Dunlap cannot provide patches for R --- for >> good reasons, though it's a pity for us! --- >> but you can, Liviu! >> So, and as you see at every startup of R : >> >>"R is a collaborative project with many contributors." >> >> I'm willing to try "good-looking" patches. >> (to the *sources*, *NOT* to a printout of the function in your R console!) >> >> Martin Maechler >> ETH Zurich and R Core Team. >> >> > Bill Dunlap >> > TIBCO Software >> > wdunlap tibco.com >> >> > On Wed, Mar 23, 2016 at 1:41 PM, Liviu Andronic >> <landronim...@gmail.com> >> > wrote: >> >> >> On Wed, Mar 23, 2016 at
Re: [R] Why missing values are not allowed in 'poly'?
On Wed, Mar 23, 2016 at 9:29 PM, William Dunlap <wdun...@tibco.com> wrote: > I think the worst aspect of this restriction in poly() is that when > you use poly in the formula of a model-fitting function you cannot > have any missing values in the data, even if you supply > na.action=na.exclude. > > > d <- transform(data.frame(y=c(-1,1:10)), x=log(y)) > Warning message: > In log(y) : NaNs produced > > fit <- lm(y ~ poly(x, 3), data=d, na.action=na.exclude) > Error in poly(x, 3) : missing values are not allowed in 'poly' > > Thus people are pushed to using a less stable formulation like > > fit <- lm(y ~ x + I(x^2) + I(x^3), data=d, na.action=na.exclude) > My difficulty precisely. What's more, I inspected the code for `poly` and at least for the simple case of raw=TRUE it seems trivial to support NAs. It suffices to change line 15 of the function: if (anyNA(x)) stop("missing values are not allowed in 'poly'") to: if (!raw && anyNA(x)) stop("missing values are not allowed in 'poly'") This way for raw polynomials estimation continues unimpeded. With the change above, I get this: > poly(x, degree = 2, raw=TRUE) 1 2 [1,] NA NA [2,] 1 1 [3,] 2 4 [4,] 3 9 [5,] 4 16 [6,] 5 25 [7,] 6 36 [8,] 7 49 [9,] 8 64 [10,] 9 81 [11,] 10 100 attr(,"degree") [1] 1 2 attr(,"class") [1] "poly" "matrix" Regards, Liviu > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Wed, Mar 23, 2016 at 12:59 PM, Liviu Andronic <landronim...@gmail.com> > wrote: >> >> Dear all, >> I'm a bit surprised by this behavior in poly: >> >> x <- c(NA, 1:10) >> poly(x, degree = 2, raw=TRUE) >> ## Error in poly(x, degree = 2, raw = TRUE) : >> ## missing values are not allowed in 'poly' >> x^2 >> ## [1] NA 1 4 9 16 25 36 49 64 81 100 >> >> As you can see, poly() will fail if the vector contains NAs, whereas >> it is perfectly possible to obtain the square of the vector manually. >> >> Is there a reason for this limitation in poly? >> >> Regards, >> Liviu >> >> >> -- >> Do you think you know what math is? >> http://www.ideasroadshow.com/issues/ian-stewart-2013-08-02 >> Or what it means to be intelligent? >> http://www.ideasroadshow.com/issues/john-duncan-2013-08-30 >> Think again: >> http://www.ideasroadshow.com/library >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > -- Do you think you know what math is? http://www.ideasroadshow.com/issues/ian-stewart-2013-08-02 Or what it means to be intelligent? http://www.ideasroadshow.com/issues/john-duncan-2013-08-30 Think again: http://www.ideasroadshow.com/library __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Why missing values are not allowed in 'poly'?
Dear all, I'm a bit surprised by this behavior in poly: x <- c(NA, 1:10) poly(x, degree = 2, raw=TRUE) ## Error in poly(x, degree = 2, raw = TRUE) : ## missing values are not allowed in 'poly' x^2 ## [1] NA 1 4 9 16 25 36 49 64 81 100 As you can see, poly() will fail if the vector contains NAs, whereas it is perfectly possible to obtain the square of the vector manually. Is there a reason for this limitation in poly? Regards, Liviu -- Do you think you know what math is? http://www.ideasroadshow.com/issues/ian-stewart-2013-08-02 Or what it means to be intelligent? http://www.ideasroadshow.com/issues/john-duncan-2013-08-30 Think again: http://www.ideasroadshow.com/library __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] creating an equivalent of r-help on r.stackexchange.com ? (was: Re: Should there be an R-beginners list?)
On Sat, Feb 8, 2014 at 4:41 AM, Patrick Connolly p_conno...@slingshot.co.nz wrote: | Dear Don and Bert, | Allow me to address some of your concerns below. Which you do very clearly by positioning your responses underneath what you're commenting on. That doesn't seem to be possible on SE. In addition to Yihui's remarks (including mailing lists are good for discussions, and SO/SE is good for QA's), I would only add that on SE commenting inline is a non-existent problem. On the QA site all communication is restricted to three types, clearly separate forms of interaction: Question, Answer, or Comment. The user may ask only one clearly defined question, well, per Question. And each proposed Answer is supposed to answer that very specific clearly described question. Everything else, going from rants to requests for clarifications go (mostly) in comments (and are mostly ignored). If the question is vague, the OP doesn't need to sift through ML-like threads and comment inline, but simply edits the original Question and adds the required information to make it clear. Same mechanism works nicely for Answers. This means that when dealing with a complex situation what you do is break down the problem in clearly identifiable parts; then in the Question you explain the background and ask a simple question; then in a 2nd Question you re-explain the background (or link to the 1st Question), and ask a second simple question; and so on. This requires a self-discipline that helps the help-providers in understanding where the issue lies, and how it could be addressed. So while on a ML a discussion can quickly digress from a clearly defined question to something extremely more diffuse, threads or no threads (as Yihui mentioned, What was my original question?; and What are we discussing right now?), on a QA web interface moderators (and the community) systematically force the users to stay on topic. And personally I find that useful: no more I stop monitoring a thread because I can't follow it anymore (anyone?). Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] creating an equivalent of r-help on r.stackexchange.com ? (was: Re: Should there be an R-beginners list?)
Dear all, On Sun, Feb 2, 2014 at 10:49 PM, Liviu Andronic landronim...@gmail.com wrote: It seems that StackOverflow is officially proposing user-generated content for download/mirroring: http://blog.stackoverflow.com/2014/01/stack-exchange-cc-data-now-hosted-by-the-internet-archive/?cb=1 All community-contributed content on Stack Exchange is licensed under the Creative Commons BY-SA 3.0 license. And it is currently being mirrored at least at the Internet Archive: https://archive.org/details/stackexchange So, in principle, it would be possible/desirable to: - spin the 'r' tag from StackOverflow and propose an r.stackexchange.com at http://area51.stackexchange.com/categories/8/technology . Such a SE site would be similar to http://mathematica.stackexchange.com/ As Duncan suggested earlier, tying R Core to StackExchange may or may not be a good idea as it would make it somewhat dependent on external corporate interests. (Personally I see both advantages and disadvantages.) So in the end my proposal is not necessarily for r-help to go to SE, but more for R to have its own QA forum/wiki for helping R users. This could perfectly take the form of setting up its own open-source https://github.com/ialbert/biostar-central QA interface (a SE-like web interface) on R Core's servers. In this case the website would look like the following: http://www.biostars.org/ . Regards, Liviu - involve R Core to give blessing for using the R logo, if necessary. This would be similar to what Ubuntu does with AskUbuntu: http://meta.askubuntu.com/questions/5444/is-ask-ubuntu-official-ubuntu - set a mirror on r-project.org for all the user content that is produced by r.stackexchange.com , and thus allow R Core to keep the info publicly available at all times. The mirroring on Internet Archive would still hold. 2. I think an interface like StackOverflow is better than the mailing list interface, and will eventually win out. R-help needs to do nothing, once someone puts together something like StackOverflow that attracts most of the people who give good answers, R-help will just fade away. The advantages for such a move are countless (especially wrt to efficiently organizing R-related knowledge and directing users to appropriate sources of info), so I won't go into that. I would only note that most 'r-sig-*' MLs would become obsolete in such a setup, and would be replaced by the much more efficient tagging system of the SE QA web interface (for example, all posts appropriate for r-sig-gui would simply be tagged with 'gui'; no need for duplicated efforts of monitoring multiple mailing lists). Opinions? Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] creating an equivalent of r-help on r.stackexchange.com ? (was: Re: Should there be an R-beginners list?)
to search for topics of interest that were already addressed in the past; much easier than scouring the mountains of untriaged r-help content. And do not underestimate the soft incentives induced by the voting system. Users seek upvotes (you can set bounties, get moderator privileges and so on), thus making them interested in giving high-quality answers and asking high-quality questions. Very well thought-out stuff. As it is now, r-help messages come to me. I don't have to start up a browser. So it's much easier to go take a quick look at what's new at any time. Agreed. I understand the frustration from using a different medium. True, I had to subscribe to the mailing list, which involves a username and password. But once it's done, it's done. I don't have to login before posting, which means I don't have to remember yet another username and password. Mostly same happens with SE, the way they set it up. What ...duplicated efforts of monitoring multiple mailing lists)? I have no duplicated effort...in fact, I have almost no effort at all, since the messages come to me. There was some initial setup, i.e., to filter different r-* messages to different mailboxes in my email client, but now that that's done, it's as simple as clicking on the correct mailbox. Do you follow r-sig-gui or r-sig-teaching or r-sig-finance or r-sig-robust? Does Brian follow them all? Probably not. People who are seeking specialized help have a hugely reduced chance of getting useful help. On SE however, the efforts are not fragmented; all questions are asked and answered in the same place. If a question pertains to 'plyr' and 'finance', either a finance type or a plyr enthusiast are as likely to answer. For the r-sig-* MLs, one would need to subscribe to all MLs and monitor them all; few do so. In other words, in every way that's important to me, the mailing list approach is superior. I do not support abandoning the mailing list system for any alternative. I'm not an SE evangelist, and only truly discovered it about a month ago or so (even though it seems that I had registered more than a year ago), and initially I was quite very skeptical of this fancy forum. But when I actually realized how _efficient_ this QA interface is, I quickly decided that r-help and associated r-sig-* were good to go the way of the usenet. Long story short, the QA interface is impressive in terms of economic efficiency, i.e. matching up supply and demand; the ML is quite inefficient in comparison. Kind regards, Liviu -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/2/14 1:49 PM, Liviu Andronic landronim...@gmail.com wrote: Dear Duncan, I discovered something interesting wrt to the licensing and mirroring of user-contributed material on StackExchange. Please read below. On Sun, Nov 24, 2013 at 9:00 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: I'm not aware of a discussion on this, but I would say no. Fragmentation is bad. Further fragmentation is worse. TL;DR = Actually I'd say all mailing lists except r-devel should be moving to StackOverlow in the future (disclaimer: I'm not affiliated with it). I would generally agree with you, except for a few points. 1. I avoid StackOverflow, because they claim copyright on the compilation. As I read their terms of service, it would be illegal for anyone to download and duplicate all postings about R. So a posting there is only available as long as they choose to make it available. Postings to the mailing list are archived in several places. It seems that StackOverflow is officially proposing user-generated content for download/mirroring: http://blog.stackoverflow.com/2014/01/stack-exchange-cc-data-now-hosted-by -the-internet-archive/?cb=1 All community-contributed content on Stack Exchange is licensed under the Creative Commons BY-SA 3.0 license. And it is currently being mirrored at least at the Internet Archive: https://archive.org/details/stackexchange So, in principle, it would be possible/desirable to: - spin the 'r' tag from StackOverflow and propose an r.stackexchange.com at http://area51.stackexchange.com/categories/8/technology . Such a SE site would be similar to http://mathematica.stackexchange.com/ - involve R Core to give blessing for using the R logo, if necessary. This would be similar to what Ubuntu does with AskUbuntu: http://meta.askubuntu.com/questions/5444/is-ask-ubuntu-official-ubuntu - set a mirror on r-project.org for all the user content that is produced by r.stackexchange.com , and thus allow R Core to keep the info publicly available at all times. The mirroring on Internet Archive would still hold. 2. I think an interface like StackOverflow is better than the mailing list interface, and will eventually win out. R-help needs to do nothing, once someone puts together something like StackOverflow that attracts most of the people who give
Re: [R] creating an equivalent of r-help on r.stackexchange.com ? (was: Re: Should there be an R-beginners list?)
Dear Clint, On Tue, Feb 4, 2014 at 1:27 AM, Clint Bowman cl...@ecy.wa.gov wrote: Liviu, Thanks for the excellent description of the advantages of SE. However, there is a significant fraction of the population that prefers that information be pushed out to them rather than having to pull it to them. The best system is one that accommodates both equally well. It's not exactly the same as in a mail client, but you also have a push-like interface on SE, sort of: http://stackoverflow.com/questions/tagged/r - The 'Newest' tab displays all recent questions, sorted in chronological order with latest on top; it gets refreshed automatically, as in a mail client (hence, push-like) - The 'Active' tab displays all questions with recent activity (question asked, answered or commented upon) - You also have the very useful 'Unanswered' tab, which allows to identify questions that haven't yet received useful advice Another push-like element in SE is that once you ask a question or answer, any subsequent comments on your post will be notified to you either in the web interface or by email. This helps keep discussions alive. Regards, Liviu Clint Clint BowmanINTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600FAX:(360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels:300 Desmond Drive, Lacey, WA 98503-1274 On Tue, 4 Feb 2014, Liviu Andronic wrote: Dear Don and Bert, Allow me to address some of your concerns below. On Mon, Feb 3, 2014 at 9:56 PM, Bert Gunter gunter.ber...@gene.com wrote: I find SO's voting for posting business especially irritating. I wish merely to post or to read the posts of others without being subjected to some kind of online pseudo game and ratings competition. That alone keeps me away. But Don said it better. On SO voting is irrelevant for either posting a question or an answer. *Anyone* (with an account) can ask a question, and *anyone* can answer a question. Their system of privileges is explained here: http://askubuntu.com/help/privileges . But to summarize: - if you're interested only in giving help, then the only really relevant threshold is 10 and 50 votes (removing some new user restrictions and allowing you to comment on posts, respectively) - if you're interested only in seeking help, then all thresholds are irrelevant really All other thresholds are relevant only if you're interested in contributing to the organization of information, or in moderating this whole forum-slash-wiki thingy. And as a note, given the quality of your answers on r-help, Bert, I have no doubt that you will clock upwards 50 upvotes in a couple of hours or so. I realize that I may be out of step with the masses here, and the masses should certainly decide. Hopefully I won't be around if/when they decide that R-help should go. The proposal is not necessarily to close down r-help. From the myriad lists it currently has, R Core could keep only r-help and r-devel, and encourage new users to seek help on r.stackexchange.com. The scope of r-help could be redefined. On Mon, Feb 3, 2014 at 12:42 PM, MacQueen, Don macque...@llnl.gov wrote: - They waste copious amounts of screen space on irrelevant things such as votes, the number of views, the elapsed time since something or other happened, fancy web-page headers, and so on. Oh, and advertisements. The Mathematica stackexchange example given in a link in one of the emails below (http://mathematica.stackexchange.com/) illustrates these shortcomings -- and it's not the worst such example. Well, I've seen my fair share of advertisements on Gmail, Yahoo Mail or what have you. I know some use dedicated clients, but not all do. (And sofar I haven't noticed one single intrusive or distracting ad on SE.) As for the number of votes, this is actually the most useful bit of this QA interface: it allows for the best questions (or most often asked) to stand out from all the noise. And it allows for the best answers (or those most authoritative) to stand out, too. Accepted answers immediately indicate to others seeking similar help what has worked for the OP. Very useful stuff. Voting also naturally allows to differentiate between neophytes (100), and professional helpers (1k; think of Brian, David or, as it happens, Bert). If you remember long ago someone proposed on r-help a reputation system for our professional helpers, only to be rebuffed essentially because it is unfeasible in a ML interface. The SE QA web interface---or similar---naturally handles this. - In most if not all cases, one has to login before posting. I have too many usernames and passwords as it is. Fair point. However SE found a neat way around this: it keeps cookies around
[R] creating an equivalent of r-help on r.stackexchange.com ? (was: Re: Should there be an R-beginners list?)
Dear Duncan, I discovered something interesting wrt to the licensing and mirroring of user-contributed material on StackExchange. Please read below. On Sun, Nov 24, 2013 at 9:00 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: I'm not aware of a discussion on this, but I would say no. Fragmentation is bad. Further fragmentation is worse. TL;DR = Actually I'd say all mailing lists except r-devel should be moving to StackOverlow in the future (disclaimer: I'm not affiliated with it). I would generally agree with you, except for a few points. 1. I avoid StackOverflow, because they claim copyright on the compilation. As I read their terms of service, it would be illegal for anyone to download and duplicate all postings about R. So a posting there is only available as long as they choose to make it available. Postings to the mailing list are archived in several places. It seems that StackOverflow is officially proposing user-generated content for download/mirroring: http://blog.stackoverflow.com/2014/01/stack-exchange-cc-data-now-hosted-by-the-internet-archive/?cb=1 All community-contributed content on Stack Exchange is licensed under the Creative Commons BY-SA 3.0 license. And it is currently being mirrored at least at the Internet Archive: https://archive.org/details/stackexchange So, in principle, it would be possible/desirable to: - spin the 'r' tag from StackOverflow and propose an r.stackexchange.com at http://area51.stackexchange.com/categories/8/technology . Such a SE site would be similar to http://mathematica.stackexchange.com/ - involve R Core to give blessing for using the R logo, if necessary. This would be similar to what Ubuntu does with AskUbuntu: http://meta.askubuntu.com/questions/5444/is-ask-ubuntu-official-ubuntu - set a mirror on r-project.org for all the user content that is produced by r.stackexchange.com , and thus allow R Core to keep the info publicly available at all times. The mirroring on Internet Archive would still hold. 2. I think an interface like StackOverflow is better than the mailing list interface, and will eventually win out. R-help needs to do nothing, once someone puts together something like StackOverflow that attracts most of the people who give good answers, R-help will just fade away. The advantages for such a move are countless (especially wrt to efficiently organizing R-related knowledge and directing users to appropriate sources of info), so I won't go into that. I would only note that most 'r-sig-*' MLs would become obsolete in such a setup, and would be replaced by the much more efficient tagging system of the SE QA web interface (for example, all posts appropriate for r-sig-gui would simply be tagged with 'gui'; no need for duplicated efforts of monitoring multiple mailing lists). Opinions? Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] convert data frame: two variables into _one_ binary variable
Dear all, Thank you so much for all the replies. The following worked exactly as needed: library(HSAUR2, lib.loc=/home/liv/R/i686-pc-linux-gnu-library/3.0) library(reshape2, lib.loc=/usr/local/lib/R/site-library) data(womensrole) zzz - melt(womensrole,id.var=c(education,gender)) - zzz[rep(1:nrow(zzz), zzz$value), 1:4 ] $agree - $variable == 'agree' [ $education %in% 0:1, ] education gender variable value agree 1 0 Male agree 4 TRUE 1.1 0 Male agree 4 TRUE 1.2 0 Male agree 4 TRUE 1.3 0 Male agree 4 TRUE 2 1 Male agree 2 TRUE 2.1 1 Male agree 2 TRUE 22 0 Female agree 4 TRUE 22.1 0 Female agree 4 TRUE 22.2 0 Female agree 4 TRUE 22.3 0 Female agree 4 TRUE 23 1 Female agree 1 TRUE 43 0 Male disagree 2 FALSE 43.1 0 Male disagree 2 FALSE 64 0 Female disagree 2 FALSE 64.1 0 Female disagree 2 FALSE Regards, Liviu On Mon, Nov 25, 2013 at 8:26 PM, Thomas Stewart tgs.public.m...@gmail.com wrote: I do not think Carl's solution answers your question. Try this: z - textConnection( education gender agree disagree sexe 1 0 Male 420 2 1 Male 200 3 2 Male 400 4 3 Male 630 5 4 Male 550 6 5 Male1370 ) zz - read.table(z,header=TRUE, stringsAsFactors=FALSE); close(z) zzz - melt(zz,id.var=c(education,gender,sexe)) - zzz[rep(1:nrow(zzz), zzz$value), 1:4 ] $agree - $variable == 'agree' -tgs On Mon, Nov 25, 2013 at 4:24 AM, Liviu Andronic landronim...@gmail.com wrote: Dear all, I am trying to convert the following data frame into a format more useful for me: library(HSAUR2, lib.loc=C:/Program Files/R/R-3.0.2/library) Loading required package: tools Attaching package: ‘HSAUR2’ The following object is masked _by_ ‘.GlobalEnv’: womensrole head(womensrole) education gender agree disagree sexe 1 0 Male 420 2 1 Male 200 3 2 Male 400 4 3 Male 630 5 4 Male 550 6 5 Male1370 In 'womensrole', how do I convert 'agree' and 'disagree' variables into one proper binary variable, say: education gender agree sexe 1 0 Male TRUE 0 2 0 Male TRUE 0 3 0 Male TRUE 0 4 0 Male TRUE 0 5 0 Male FALSE 0 6 0 Male FALSE 0 7 1 Male TRUE 0 8 1 Male TRUE 0 9 2 Male TRUE 0 10 2 Male TRUE 0 11 2 Male TRUE 0 12 2 Male TRUE 0 [..] I'm sure there is an easy way to do this (in the form of 'melt', 'cast', etc.), but I'm not sure how to approach the problem. Regards, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] convert data frame: two variables into _one_ binary variable
Dear all, I am trying to convert the following data frame into a format more useful for me: library(HSAUR2, lib.loc=C:/Program Files/R/R-3.0.2/library) Loading required package: tools Attaching package: ‘HSAUR2’ The following object is masked _by_ ‘.GlobalEnv’: womensrole head(womensrole) education gender agree disagree sexe 1 0 Male 420 2 1 Male 200 3 2 Male 400 4 3 Male 630 5 4 Male 550 6 5 Male1370 In 'womensrole', how do I convert 'agree' and 'disagree' variables into one proper binary variable, say: education gender agree sexe 1 0 Male TRUE 0 2 0 Male TRUE 0 3 0 Male TRUE 0 4 0 Male TRUE 0 5 0 Male FALSE 0 6 0 Male FALSE 0 7 1 Male TRUE 0 8 1 Male TRUE 0 9 2 Male TRUE 0 10 2 Male TRUE 0 11 2 Male TRUE 0 12 2 Male TRUE 0 [..] I'm sure there is an easy way to do this (in the form of 'melt', 'cast', etc.), but I'm not sure how to approach the problem. Regards, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R for a stats intro for undergrads in the US?
Dear Spencer, In case you have similar questions you may want to ask them on r-sig-teaching, which deals specifically with such topics. Regards, Liviu On Sun, Nov 17, 2013 at 3:19 AM, Spencer Graves spencer.gra...@prodsyse.com wrote: Hello, All: Would anyone recommend R for an introductory statistics class for freshman psychology students in the US? If yes, might there be any notes for such available? I just checked r-projects.org and CRAN contributed documentation and found nothing. I have a friend who teaches such a class, and wondered if R might be suitable. The alternative is SPSS at $406 per student. Thanks, Spencer -- Spencer Graves, PE, PhD President and Chief Technology Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 ph: 408-655-4567 web: www.structuremonitoring.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] OT: The topic of reproducibility in the media
Dear all, I know that reproducibility is a big concern for the R community, so it may be interesting to some of the readers on this list that The Economist recently ran a series of articles denouncing the alarming number of shoddy and non-reproducible published papers: http://www.economist.com/news/leaders/21588069-scientific-research-has-changed-world-now-it-needs-change-itself-how-science-goes-wrong http://www.economist.com/news/briefing/21588057-scientists-think-science-self-correcting-alarming-degree-it-not-trouble They even went as far as stating that most published scientific research is probably false: http://www.economist.com/blogs/graphicdetail/2013/10/daily-chart-2 Anyways, food for thought for the weekend. Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] list of valid characters in object names
Dear all, Could someone please point me to the definitive list of valid characters that are allowed in object names in R? I believe that the following list covers them: _.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 but I would like to make sure. Thank you, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] list of valid characters in object names
On Sat, Jul 27, 2013 at 3:08 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: Your question is a little ambiguous. All characters are allowed in object names, but the parser will only recognize some of them if they are quoted in backticks. The ones it recognizes without the backticks are ones that the C isalnum() (or iswalnum()) function declares to be alphanumeric, plus . and _. Your list above are all allowed, but locales are allowed to declare other characters to be alpha. I wouldn't recommend using anything else, because your code won't be recognized in other locales. The definitive reference for this is the source code, specifically src/main/gram.y. There's some discussion in the Intro to R manual, section 1.8. Exactly what I was looking for. Thank you, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] union of a list of logical values
Dear all, How can I obtain the union of a list of logical values? Consider the following: x - head(iris) x[,c(2,4)] - NA x[c(2,4),] - NA # x # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 NA 1.4 NA setosa # 2 NA NA NA NANA # 3 4.7 NA 1.3 NA setosa # 4 NA NA NA NANA # 5 5.0 NA 1.4 NA setosa # 6 5.4 NA 1.7 NA setosa z - data.frame(!is.na(x)) # z # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 TRUE FALSE TRUE FALSETRUE # 2FALSE FALSEFALSE FALSE FALSE # 3 TRUE FALSE TRUE FALSETRUE # 4FALSE FALSEFALSE FALSE FALSE # 5 TRUE FALSE TRUE FALSETRUE # 6 TRUE FALSE TRUE FALSETRUE I did find a solution, but it seems more like a hack: ##union of logical values by rows (union of list of logical values) as.logical(rowSums(z)) [1] TRUE FALSE TRUE FALSE TRUE TRUE ##union of logical values by columns as.logical(colSums(z)) [1] TRUE FALSE TRUE FALSE TRUE Another unusable monstrosity is as follows: ##union of list of logical values z[[1]] | z[[2]] | z[[3]] | z[[4]] | z[[5]] [1] TRUE FALSE TRUE FALSE TRUE TRUE Is there a more elegant way to approach this problem and obtain the above logical vectors? Regards, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] union of a list of logical values
On Mon, Jul 22, 2013 at 11:37 AM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: This really only makes sense for a list of logical vectors of the same length. And by 'union' you seem to mean 'or'. Indeed. Two approaches 1) Make a logical matrix and use apply(m, 1, any) Of course! I tried apply(m, 1, |) without luck, but I should have used apply(m, 1, any) instead. Thank you, Liviu 2) Use Reduce(`|`, z) Consider the following: x - head(iris) x[,c(2,4)] - NA x[c(2,4),] - NA # x # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 NA 1.4 NA setosa # 2 NA NA NA NANA # 3 4.7 NA 1.3 NA setosa # 4 NA NA NA NANA # 5 5.0 NA 1.4 NA setosa # 6 5.4 NA 1.7 NA setosa z - data.frame(!is.na(x)) # z # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 TRUE FALSE TRUE FALSETRUE # 2FALSE FALSEFALSE FALSE FALSE # 3 TRUE FALSE TRUE FALSETRUE # 4FALSE FALSEFALSE FALSE FALSE # 5 TRUE FALSE TRUE FALSETRUE # 6 TRUE FALSE TRUE FALSETRUE I did find a solution, but it seems more like a hack: ##union of logical values by rows (union of list of logical values) as.logical(rowSums(z)) [1] TRUE FALSE TRUE FALSE TRUE TRUE ##union of logical values by columns as.logical(colSums(z)) [1] TRUE FALSE TRUE FALSE TRUE Another unusable monstrosity is as follows: ##union of list of logical values z[[1]] | z[[2]] | z[[3]] | z[[4]] | z[[5]] [1] TRUE FALSE TRUE FALSE TRUE TRUE Is there a more elegant way to approach this problem and obtain the above logical vectors? Regards, Liviu -- 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 -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] generate simple function with pre-defined constants
Dear Bill, On Thu, Jun 6, 2013 at 5:36 PM, William Dunlap wdun...@tibco.com wrote: Try the following: generateABFunction - function(a, b) { force(a) force(b) function(x) a*x + b } f12 - generateABFunction(1, 2) f53 - generateABFunction(5,6) f12(10:12) # get 12, 13, 14 f53(10:12) # get 56, 61, 66 See, e.g., yesterday's discussion under the subject Trying to build up functions with its names by means of lapply on why the force() calls are required. Read up on R's environments to see why f12 and f53 look the same but act differently (hint: look at ls.str(environment(f12))). This is exactly what I was trying to do. Thank you for the explanations, Liviu Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Liviu Andronic Sent: Thursday, June 06, 2013 8:00 AM To: r-help@r-project.org Help Subject: Re: [R] generate simple function with pre-defined constants On Thu, Jun 6, 2013 at 4:48 PM, Liviu Andronic landronim...@gmail.com wrote: Dear all, Given: a - 2 b - 3 I'd like to obtain the following function: f - function(x) 2 + 3*x but when I do this: f - function(x) a + b*x ##f ##function(x) a + b*x the 'a' and 'b' objects do not get evaluated to their constants. How could I do that? I found one solution: a - 2 b - 3 f - eval(parse(text=paste(function(z), a, + z * , b))) f ##function(z) 2 + z * 3 but I still have nightmares from: fortune(parse) If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005) Is there a nicer way to approach this? Thanks, Liviu Thanks, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] generate simple function with pre-defined constants
Dear all, Given: a - 2 b - 3 I'd like to obtain the following function: f - function(x) 2 + 3*x but when I do this: f - function(x) a + b*x ##f ##function(x) a + b*x the 'a' and 'b' objects do not get evaluated to their constants. How could I do that? Thanks, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] generate simple function with pre-defined constants
On Thu, Jun 6, 2013 at 4:48 PM, Liviu Andronic landronim...@gmail.com wrote: Dear all, Given: a - 2 b - 3 I'd like to obtain the following function: f - function(x) 2 + 3*x but when I do this: f - function(x) a + b*x ##f ##function(x) a + b*x the 'a' and 'b' objects do not get evaluated to their constants. How could I do that? I found one solution: a - 2 b - 3 f - eval(parse(text=paste(function(z), a, + z * , b))) f ##function(z) 2 + z * 3 but I still have nightmares from: fortune(parse) If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005) Is there a nicer way to approach this? Thanks, Liviu Thanks, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] generate simple function with pre-defined constants
On Thu, Jun 6, 2013 at 5:03 PM, arun smartpink...@yahoo.com wrote: HI, Not sure I understand your question: a - 2 b - 3 f1- function(x) a+b*x I don't want the function to depend on the objects a and b, but instead use the values of those objects (I do this within a function). Liviu f1(2) #[1] 8 f1(3) #[1] 11 f- function(x) 2+3*x f(2) #[1] 8 f(3) #[1] 11 A.K. sessionInfo() R version 3.0.0 (2013-04-03) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] arrayhelpers_0.76-20120816 abind_1.4-0 [3] plyr_1.8 stringr_0.6.2 [5] reshape2_1.2.2 loaded via a namespace (and not attached): [1] tools_3.0.0 - Original Message - From: Liviu Andronic landronim...@gmail.com To: r-help@r-project.org Help r-help@r-project.org Cc: Sent: Thursday, June 6, 2013 10:48 AM Subject: [R] generate simple function with pre-defined constants Dear all, Given: a - 2 b - 3 I'd like to obtain the following function: f - function(x) 2 + 3*x but when I do this: f - function(x) a + b*x ##f ##function(x) a + b*x the 'a' and 'b' objects do not get evaluated to their constants. How could I do that? Thanks, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] More discussion on R usage statistics
On Thu, May 30, 2013 at 2:40 PM, Johnny Zhang johnny...@yahoo.com wrote: I'd be very happy to change its name and welcome any input on another name. Zhiyong collect_rstats or RCollectStats or a variation thereof would do just fine. My 2 cents, Liviu From: Michael Weylandt michael.weyla...@gmail.com Cc: r-help@r-project.org r-help@r-project.org Sent: Wednesday, May 29, 2013 5:26 PM Subject: Re: [R] More discussion on R usage statistics Interesting idea but would you be willing to change the name. Twitter, Stackoverflow, and the like use rstats to refer to R itself and confusion seems probable. https://mobile.twitter.com/search?q=%23rstats Michael Dear R users, There has been discussion on how to collect R usage statistics before and the discussion has led to some good results such as http://neolab.stat.ucla.edu/cranstats/ and http://crantastic.org/. Recently, I tried to put together a package that allows R users to rate, comment, and ask questions on R packages within R. A working version is now available on both github and r-forge. Note that the email feature may not work out as expected because gmail, used by the package, only allows 500 messages sent per day. To install it from R forge, please use install.packages('rstats', repos=http://r-forge.r-project.org;) Using github (require the package devtools), install_github('rstats','johnnyzhz') A brief manual of it can be seen at: http://rstats.psychstat.org/rstats.pdf I'd appreciate it that if you can test this and provide feedback on how to collect and utilize R usage statistics. Best, Zhiyong Zhang [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] configure ddply() to avoid reordering of '.variables'
Hello, I'm using ddply() in plyr and I notice that it has the habit of re-ordering the levels of the '.variables' by which the splitting is done. I'm concerned about correctly retrieving the original ordering. Consider: require(plyr) x - iris[ order(iris$Species, decreasing=T), ] head(x) #Sepal.Length Sepal.Width Petal.Length Petal.Width Species #101 6.3 3.3 6.0 2.5 virginica #102 5.8 2.7 5.1 1.9 virginica #103 7.1 3.0 5.9 2.1 virginica #104 6.3 2.9 5.6 1.8 virginica #105 6.5 3.0 5.8 2.2 virginica #106 7.6 3.0 6.6 2.1 virginica xa - ddply(x, .(Species), function(x) {data.frame(Sepal.Length=x$Sepal.Length, mean.adj=(x$Sepal.Length - mean(x$Sepal.Length)))}) # |==| 100% ##notice how the ordering of Species is different ##from that in the input data frame head(xa) # Species Sepal.Length mean.adj #1 setosa 5.10.094 #2 setosa 4.9 -0.106 #3 setosa 4.7 -0.306 #4 setosa 4.6 -0.406 #5 setosa 5.0 -0.006 #6 setosa 5.40.394 all.equal(xa$Species, x$Species) #[1] 100 string mismatches all.equal(xa[ order(xa$Species, decreasing=T), ]$Species, x$Species) #[1] TRUE all.equal(xa$Sepal.Length, x$Sepal.Length) #[1] Mean relative difference: 0.2785 all.equal(xa[ order(xa$Species, decreasing=T), ]$Sepal.Length, x$Sepal.Length) #[1] TRUE In my real data, should I be concerned that simply reordering by the '.variables' variable wouldn't necessarily restore the original ordering as in the input data frame? Is it possible to instruct ddply() to avoid re-ordering the supplied '.variables' variable? Regards, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] strange behaviour with loops and lists
Dear all, I encountered this strange behaviour with loops and lists. Consider this: xl - list() for(i in 5:7){##loop over numeric vector xl[[i]] - rnorm(i) } xl [[1]] NULL [[2]] [1] -0.4448192 -1.3395014 [[3]] [1] 1.3214195 -1.2968560 -0.6327795 The above lists contained a NULL element for some reason. While the code below: xl - list() for(i in as.character(2:3)){##loop over character vector xl[[i]] - rnorm(i) } xl $`2` [1] -1.139506 2.894280 $`3` [1] 0.0599175 1.0793515 0.4296049 This resulting list contains no extraneous elements. Is this normal? Why? Thanks, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strange behaviour with loops and lists
On Sun, May 19, 2013 at 7:02 PM, peter dalgaard pda...@gmail.com wrote: (The first example really had 2:3, not 5:7, right?) Indeed. I simplified the example mid-email. The essential bit is that to assign to the 2nd element of a list, it needs to have at least two elements: Thanks for the explanations. Regards, Liviu x - list() x[[2]] - 123 x [[1]] NULL [[2]] [1] 123 assigning to an element with a specific name just requires there is an element of that name: x[[2]] - 321 x [[1]] NULL [[2]] [1] 123 $`2` [1] 321 In both cases, x will be extended if needed, so that the required element exists. Notice that there is no relation between the name and the number of a list element; e.g., x[[2]] is the 3rd element in the above example. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] recommended workflow for creating functions (was: Re: [Rd] Patch proposal for R style consistency (concerning deparse.c))
(moving to r-help) Dear all, I think Paul is raising a useful question here: What is the recommended workflow for creating a new function? R prides itself for letting users to create and use home-brewed functions: it's easy to maintain and re-use, doesn't clutter the global environment with intermediary objects, has clear input and output elements. All fine points, and I genuinely see the advantage in using functions, but after several years of using R I still stumble at step 1: building a function. The thing is that I'm not a whizz programmer, so it takes me a lot of time and mind gymnastics to imagine what the intermediary objects within a function, when executed, would look like. Thus I need to see and examine most intermediary objects while building the function. The alternative is to create the input objects and use only the first element while building the function, but this clutters the global workspace and I need to worry about overwriting existing objects. Another way would be to use browser() within the function, but this seems clunky to me. How do you deal with this? Is there a neat way to build a new function in a sandbox, where I can access all objects in the global workspace but cannot overwrite them? Am I approaching this in the wrong way? Opinions welcome. Regards, Liviu On Sun, May 5, 2013 at 7:37 PM, Paul Johnson pauljoh...@gmail.com wrote: It quite often happens that when I'm developing a function, I have to step through line by line to see what's going on. That' won't work for me if I have else by itself at the beginning of a line. As an Objective-C programmer, I very much think it looks nicer to write if ( ) { blah } else { blah } But in R, I can't step through that, so I don't write it that way. The fact that you don't run into that makes me think that I'm preparing functions incorrectly. If you don't check your code line by line, what is your work flow? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Tables package - remove NAs and NaN
On Wed, Apr 24, 2013 at 9:23 PM, Santosh santosh2...@gmail.com wrote: Dear Rxperts, Sorry if I am posting a really really dumb request.. I am new to subversion and am trying to use subversion to download the tables package as suggested by Duncan. I installed subversion client(from collabnet) and tried to access tables package using the command below. svn checkout svn://scm.r-forge.r-project.org/svnroot/tables/ I don't know what's wrong here, but I would suggest that you use an SVN GUI for Windows (like RapidSVN or TortoiseSVN). This should avoid space related issues. Regards, Liviu I get the following error message: C:\Users\santosh\tempsvn checkout svn:// scm.r-forge.r-project.org/svnroot/tables/ svn: E730060: Unable to connect to a repository at URL 'svn://scm.r-forge.r-proj ect.org/svnroot/tables' svn: E730060: Can't connect to host 'scm.r-forge.r-project.org': A connection at tempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. Is there anything additional I need to do with Subversion or with the commands? Regards, Santosh On Tue, Apr 23, 2013 at 5:13 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 13-04-23 6:31 AM, Duncan Murdoch wrote: On 13-04-22 10:40 PM, David Winsemius wrote: On Apr 22, 2013, at 5:49 PM, Santosh wrote: Dear Rxperts, q - data.frame(p=rep(c(A,B),**each=10,len=30), a=rep(c(1,2,3),each=10),id=**seq(30), b=round(runif(30,10,20)), c=round(runif(30,40,70))) The operation below... tabular(((p=factor(p))*(a=**factor(a))+1) ~ (N = 1) + (b + c)* (mean+sd),data=q) yields some rows of NAs and NaN as shown below b c p a N mean sdmean sd A 1 10 16.30 2.497 52.30 9.358 20 NaNNA NaN NA 3 10 15.60 2.716 60.30 8.001 B 10 NaNNA NaN NA 2 10 15.40 2.366 57.70 10.414 30 NaNNA NaN NA All 30 15.77 2.473 56.77 9.601 How do I remove the rows having N=0 ? I would like the resulting table look like.. b c p a N mean sdmean sd A 1 10 16.30 2.497 52.30 9.358 3 10 15.60 2.716 60.30 8.001 B 2 10 15.40 2.366 57.70 10.414 All 30 15.77 2.473 56.77 9.601 Here's a bit of a hack: tabular( (`p a`=interaction(p,a, drop=TRUE, sep= )) ~ (N = 1) + (b + c)* (mean+sd),data=q) b c p a N mean sd mean sd A 1 10 12.8 0.7888 52.1 8.020 B 2 10 16.3 3.0569 54.9 8.711 A 3 10 14.6 3.7771 56.5 6.980 I have been rather hoping that Duncan Murdoch would have noticed the earlier thread, but maybe he can comment on whether there is a more direct route/ This isn't something that the package is designed to handle: if you say p*a, it wants all combinations of p and a. If I wanted a table like that, I'd use a different hack. One possibility is to create that interaction column, but display it as just the initial letter, labelled p, and then add another column to contain the a values as data. It would be tricky to get the formatting right. Another possibility is to generate the whole table with the N=0 rows, and then post-process it to remove those rows, and adjust the row labels appropriately. This approach probably gives the nicer result, but the post-processing is quite messy: you need to delete some rows from the table, from its rowLabels attribute, and from the justification attributes of both the table and its rowLabels. (I should add a [ method to the package to hide this messiness.) I've done this now, in version 0.7.54 on R-forge. To leave out the rows with N=0, you can select a subset of the table where N (the first column) is non-zero: tab - tabular(((p=factor(p))*(a=**factor(a))+1) ~ (N = 1) + (b + c)*(mean+sd),data=q) tab[ tab[,1] 0, ] and it produces this: b c p a N mean sdmean sd A 1 10 16.20 3.458 56.3 10.155 3 10 13.60 2.119 58.1 8.075 B 2 10 14.40 2.547 51.2 9.438 All 30 14.73 2.888 55.2 9.419 Indexing of tables isn't as general as indexing of matrices, but most of the simple forms should work. I haven't tested yet, but I expect this will be fine in LaTeX or HTML (also new, not on CRAN yet) output as well. Duncan Murdoch [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __
Re: [R] identify object that causes Error in loadNamespace(name) : there is no package called ‘R.utils’
Dear Duncan, On Wed, Apr 24, 2013 at 11:04 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: What I've done sometimes in debugging is to change that error to a warning in the getNamespace() function, and add some tracing code to the serialization code to print the names of objects as they are loaded. (This goes in ReadItem in src/main/serialize.c.) I wouldn't expect Liviu to make those changes, but perhaps a verbose option could be added to load(), so that it could be available to users. I have added this in R-devel. The format of the printed output may well change before this is ever released, but it should be enough to identify the bad item already. You'll need a build of R-devel from r62658 or newer to see this. Then load(/tmp/a.rda, verbose=TRUE) will print the names of objects as they are read (the names are read after the attributes and before the value). If you want to see reams of mostly useless information, you can try verbose=n (for some number n=2 or more); this prints names and component numbers to a greater depth. Thank you for adding this in R. I will likely test this feature when it gets released. Best regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] tables: proper use of Hline() in tabular()
Dear all, I am unable to understand how Hline() works in tabular(). I've read the vignette and the help page, and here this example compiles perfectly fine: latex( tabular( Species + Hline() + 1 ~ Heading()*mean*All(iris), data=iris) ) However, if I try it on my own data it fails. Consider this: set.seed(1) Xa - data.frame(p=rep(c(First group,Second group,Third group),each=10,len=30), a=sample(c(Some long label,Some other long label, Yet another label), 30, replace=TRUE),id=seq(30), b=round(runif(30,10,20)), c=round(runif(30,40,70))) (x - tabular(((p=factor(p))*(a=factor(a))+1) ~ (N = 1) + (b + c)* (mean+sd),data=Xa)) pa N mean sdmean sd First group Some long label3 15.67 2.082 64.33 3.786 Some other long label 4 14.75 2.630 52.25 8.461 Yet another label 3 15.67 3.215 50.67 3.055 Second group Some long label2 17.00 1.414 57.50 10.607 Some other long label 3 17.00 1.000 60.00 8.888 Yet another label 5 15.00 3.082 58.20 8.672 Third group Some long label4 13.75 3.594 58.75 5.909 Some other long label 4 13.50 1.732 46.50 3.786 Yet another label 2 16.00 1.414 50.00 4.243 All 30 15.13 2.501 55.37 8.045 I would like to place an Hline() between rows 3:4, rows 6:7, rows 9:10. But either way I place it I get something that doesn't compile in LaTeX (! Misplaced \noalign. error). For example, x - tabular(((p=factor(p)))*(a=factor(a)) +(Hline() + 1) ~ (N = 1) + (b + c)* (mean+sd),data=Xa) latex(x) \begin{tabular}{llc} \hline \multicolumn{2}{c}{b} \multicolumn{2}{c}{c} \\ p a N mean sd mean \multicolumn{1}{c}{sd} \\ \hline First group Some long label $\phantom{0}3$ $15.67$ $2.082$ $64.33$ $\phantom{0}3.786$ \\ Some other long label $\phantom{0}4$ $14.75$ $2.630$ $52.25$ $\phantom{0}8.461$ \\ Yet another label $\phantom{0}3$ $15.67$ $3.215$ $50.67$ $\phantom{0}3.055$ \\ Second group Some long label $\phantom{0}2$ $17.00$ $1.414$ $57.50$ $10.607$ \\ Some other long label $\phantom{0}3$ $17.00$ $1.000$ $60.00$ $\phantom{0}8.888$ \\ Yet another label $\phantom{0}5$ $15.00$ $3.082$ $58.20$ $\phantom{0}8.672$ \\ Third group Some long label $\phantom{0}4$ $13.75$ $3.594$ $58.75$ $\phantom{0}5.909$ \\ Some other long label $\phantom{0}4$ $13.50$ $1.732$ $46.50$ $\phantom{0}3.786$ \\ Yet another label $\phantom{0}2$ $16.00$ $1.414$ $50.00$ $\phantom{0}4.243$ \\ \hline %\\ All $30$ $15.13$ $2.501$ $55.37$ $\phantom{0}8.045$ \\ \hline \end{tabular} Please advise how to use Hline() in the example above. Regards, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] identify object that causes Error in loadNamespace(name) : there is no package called ‘R.utils’
Dear all, I've bumped into the: Error in loadNamespace(name) : there is no package called ‘R.utils’ error. I've already read a bit on this ( http://www.cybaea.net/Blogs/Data/A-warning-on-the-R-save-format.html ) but I have a follow-up question. Given a workspace that automatically loads a package that I don't really need/want (e.g. ‘R.utils’), how do I identify which object requires this package to load? I would like to avoid loading ‘R.utils’ every time I open an R session. Regards, Liviu sessionInfo() R version 2.15.3 (2013-03-01) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] datasets grDevices splines graphics utils stats methods base other attached packages: [1] R.utils_1.23.2R.oo_1.13.0 R.methodsS3_1.4.2 tables_0.7.57 reshape2_1.2.2 [6] car_2.0-15nnet_7.3-6MASS_7.3-23 Hmisc_3.10-1 survival_2.37-2 [11] foreign_0.8-53 loaded via a namespace (and not attached): [1] cluster_1.14.3 grid_2.15.3 lattice_0.20-13 plyr_1.8 rstudio_0.97.312 [6] stringr_0.6.2tools_2.15.3 -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] identify object that causes Error in loadNamespace(name) : there is no package called ‘R.utils’
Dear Duncan, On Wed, Apr 24, 2013 at 4:57 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: What I've done sometimes in debugging is to change that error to a warning in the getNamespace() function, and add some tracing code to the serialization code to print the names of objects as they are loaded. (This goes in ReadItem in src/main/serialize.c.) I wouldn't expect Liviu to make those changes, but perhaps a verbose option could be added to load(), so that it could be available to users. That would be useful, indeed. As it stands save()/load() workspaces in R seems very fragile and could easily trip users when working on multiple machines or sharing their workspace with a colleague. In such cases it is important to be able to quickly pinpoint the offending object. Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] identify object that causes Error in loadNamespace(name) : there is no package called ‘R.utils’
Dear Duncan, On Wed, Apr 24, 2013 at 3:03 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: A better approach is to *never* save and load workspaces unless you know exactly what is in them. Always reply no to the question about saving your workspace (or set that as the default). If you accidentally end up with a workspace being loaded, delete it. I must admit that I'm a bit surprised by this. I was always under the impression that saving/restoring workspaces was the proper workflow in R. If you use R interactively (e.g., not by running scripts), how else would you store your data, intermediary results, etc., while working on a project? Am I missing something? Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Tables package - remove NAs and NaN
Dear David, I'm having the exact same issue as Santosh, and looking at the fix that you've provided it seems to me that results are slightly different. On Tue, Apr 23, 2013 at 4:40 AM, David Winsemius dwinsem...@comcast.net wrote: b c p a N mean sdmean sd A 1 10 16.30 2.497 52.30 9.358 20 NaNNA NaN NA 3 10 15.60 2.716 60.30 8.001 B 10 NaNNA NaN NA 2 10 15.40 2.366 57.70 10.414 30 NaNNA NaN NA All 30 15.77 2.473 56.77 9.601 How do I remove the rows having N=0 ? I would like the resulting table look like.. b c p a N mean sdmean sd A 1 10 16.30 2.497 52.30 9.358 3 10 15.60 2.716 60.30 8.001 B 2 10 15.40 2.366 57.70 10.414 All 30 15.77 2.473 56.77 9.601 Here's a bit of a hack: tabular( (`p a`=interaction(p,a, drop=TRUE, sep= )) ~ (N = 1) + (b + c)* (mean+sd),data=q) b c p a N mean sd mean sd A 1 10 12.8 0.7888 52.1 8.020 B 2 10 16.3 3.0569 54.9 8.711 A 3 10 14.6 3.7771 56.5 6.980 What Santosh and I would expect to get from the above is: [..] A 1 10 16.30 2.497 52.30 9.358 3 10 15.60 2.716 60.30 8.001 [..] but what we get with your approach is: [..] A 1 10 12.8 0.7888 52.1 8.020 B 2 10 16.3 3.0569 54.9 8.711 [..] Although your approach makes things much better, can the original ordering be retained? I have been rather hoping that Duncan Murdoch would have noticed the earlier thread, but maybe he can comment on whether there is a more direct route/ I hope so, too. Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] tables package - error message of duplicate values
Dear David, I'm once again facing the same issue as Santosh. On Sat, Apr 20, 2013 at 12:15 AM, David Winsemius dwinsem...@comcast.net wrote: On Apr 19, 2013, at 2:03 PM, Santosh wrote: Rounding was done to replicate the problem I faced in the original data set... I got an error every time I tried to use digits=0. My basic rule is that if a parameter choice consistently errors out ... stop using it. I'm fundamentally a pragmatist. I would like to use digits=0, but it always errors out. I have a hunch that this might be linked to the following in ?format: digits how many significant digits are to be used for numeric and complex x. The default, NULL, uses getOption(digits). This is a suggestion: enough decimal places will be used so that the smallest (in magnitude) number has this many significant digits, and also to satisfy nsmall. (For the interpretation for complex numbers see signif.) nsmall the minimum number of digits to the right of the decimal point in formatting real/complex numbers in non-scientific formats. Allowed values are 0 = nsmall = 20. But using Format(digits=0, nsmall=0) doesn't solve the problem. Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Tables package - remove NAs and NaN
On Tue, Apr 23, 2013 at 10:06 AM, David Winsemius dwinsem...@comcast.net wrote: On Apr 23, 2013, at 1:00 AM, David Winsemius wrote: On Apr 23, 2013, at 12:53 AM, Liviu Andronic wrote: Dear David, I'm having the exact same issue as Santosh, and looking at the fix that you've provided it seems to me that results are slightly different. Reverse the order of arguemtns to `interaction`: tabular( (`p a`=interaction(a,p, drop=TRUE, sep= )) ~ (N = 1) + (b + c)* (mean+sd),data=q) I suppose that instead of making transpositions in the word `argument`, I should also have instead transposed the columns labels: tabular( (`a p`=interaction(a,p, drop=TRUE, sep= )) ~ (N = 1) + (b + c)* + (mean+sd),data=q) b c a p N mean sd mean sd 1 A 10 12.8 0.7888 52.1 8.020 3 A 10 14.6 3.7771 56.5 6.980 2 B 10 16.3 3.0569 54.9 8.71 Thanks! The following nicely reproduces the original table: ##notice the +1 tabular( (`a p`=interaction(a,p, drop=TRUE, sep= ) +1) ~ (N = 1) + (b + c)* (mean+sd),data=q) b c a p N mean sdmean sd 1 A 10 14.20 3.490 52.2 6.779 3 A 10 16.10 2.807 59.8 7.115 2 B 10 13.90 2.807 55.1 11.060 All 30 14.73 3.107 55.7 8.836 One last bit of nitpick: Is it possible to avoid duplicate printing of the 'A' label? With a small toy data set that is OK, but if you have ~7 categories then the resulting table can be very crowded. Regards, Liviu b c p a N mean sd mean sd 1 A 10 12.8 0.7888 52.1 8.020 3 A 10 14.6 3.7771 56.5 6.980 2 B 10 16.3 3.0569 54.9 8.711 with(q, levels( interaction(p,a, drop=TRUE, sep= ) ) ) [1] A 1 B 2 A 3 with(q, levels( interaction(a,p, drop=TRUE, sep= ) ) ) [1] 1 A 3 A 2 B -- David. On Tue, Apr 23, 2013 at 4:40 AM, David Winsemius dwinsem...@comcast.net wrote: b c p a N mean sdmean sd A 1 10 16.30 2.497 52.30 9.358 20 NaNNA NaN NA 3 10 15.60 2.716 60.30 8.001 B 10 NaNNA NaN NA 2 10 15.40 2.366 57.70 10.414 30 NaNNA NaN NA All 30 15.77 2.473 56.77 9.601 How do I remove the rows having N=0 ? I would like the resulting table look like.. b c p a N mean sdmean sd A 1 10 16.30 2.497 52.30 9.358 3 10 15.60 2.716 60.30 8.001 B 2 10 15.40 2.366 57.70 10.414 All 30 15.77 2.473 56.77 9.601 Here's a bit of a hack: tabular( (`p a`=interaction(p,a, drop=TRUE, sep= )) ~ (N = 1) + (b + c)* (mean+sd),data=q) b c p a N mean sd mean sd A 1 10 12.8 0.7888 52.1 8.020 B 2 10 16.3 3.0569 54.9 8.711 A 3 10 14.6 3.7771 56.5 6.980 What Santosh and I would expect to get from the above is: [..] A 1 10 16.30 2.497 52.30 9.358 3 10 15.60 2.716 60.30 8.001 [..] but what we get with your approach is: [..] A 1 10 12.8 0.7888 52.1 8.020 B 2 10 16.3 3.0569 54.9 8.711 [..] Although your approach makes things much better, can the original ordering be retained? I have been rather hoping that Duncan Murdoch would have noticed the earlier thread, but maybe he can comment on whether there is a more direct route/ I hope so, too. Regards, Liviu David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius Alameda, CA, USA -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Tables package - remove NAs and NaN
Dear David, On Tue, Apr 23, 2013 at 10:00 AM, David Winsemius dwinsem...@comcast.net wrote: tabular( (`p a`=interaction(a,p, drop=TRUE, sep= )) ~ (N = 1) + (b + c)* (mean+sd),data=q) b c p a N mean sd mean sd 1 A 10 12.8 0.7888 52.1 8.020 3 A 10 14.6 3.7771 56.5 6.980 2 B 10 16.3 3.0569 54.9 8.711 Unfortunately although this works, with this approach the formatting completely breaks down. Consider the following slightly modified example: ##generate longer labels q - data.frame(p=rep(c(First group,Second group),each=10,len=30), a=rep(c(Some long label,Some other long label, Yet another label),each=10),id=seq(30), b=round(runif(30,10,20)), c=round(runif(30,40,70))) ##formatting OK (use monospace font) tabular(((p=factor(p))*(a=factor(a))+1) ~ (N = 1) + (b + c)* (mean+sd),data=q) pa N mean sdmean sd First group Some long label 10 12.6 1.897 58.4 9.204 Some other long label 0 NaNNA NaNNA Yet another label 10 15.6 3.373 55.8 7.671 Second group Some long label0 NaNNA NaNNA Some other long label 10 14.1 2.183 58.3 8.551 Yet another label 0 NaNNA NaNNA All 30 14.1 2.771 57.5 8.291 ##formatting broken (use monospace font) tabular( (`a p`=interaction(a,p, drop=TRUE, sep= ) +1) ~ (N = 1) + (b + c)* (mean+sd),data=q) b c a pN mean sdmean sd Some long label First group10 12.6 1.897 58.4 9.204 Yet another label First group 10 15.6 3.373 55.8 7.671 Some other long label Second group 10 14.1 2.183 58.3 8.551 All30 14.1 2.771 57.5 8.291 Unfortunately this last table is unreadable. Is there a way to work around this issue? Maybe we could use tab as separators, but interaction(a,p, drop=TRUE, sep='\t) didn't do what I had hoped. Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Tables package - remove NAs and NaN
Dear Duncan, Thank you for your explanations. On Tue, Apr 23, 2013 at 12:31 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: This isn't something that the package is designed to handle: if you say p*a, it wants all combinations of p and a. To your knowledge is there another 'complex tables' package that could achieve this? If I wanted a table like that, I'd use a different hack. One possibility is to create that interaction column, but display it as just the initial letter, labelled p, and then add another column to contain the a values as data. It would be tricky to get the formatting right. Another possibility is to generate the whole table with the N=0 rows, and then post-process it to remove those rows, and adjust the row labels appropriately. This approach probably gives the nicer result, but the post-processing is quite messy: you need to delete some rows from the table, from its rowLabels attribute, and from the justification attributes of both the table and its rowLabels. (I should add a [ method to the package to hide this messiness.) I think a subsetting method would be useful, indeed. A third hack is less of a hack: don't do that. Just format the mean and sd in a way that displays the NA and NaN values as blanks. I think this could work, at least for unofficial displays of the summaries, but I'm not sure where to start from. What function/argument should one use? Could you give an example? Thank you, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Tables package - remove NAs and NaN
Dear Duncan, On Tue, Apr 23, 2013 at 2:13 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: I've done this now, in version 0.7.54 on R-forge. To leave out the rows with N=0, you can select a subset of the table where N (the first column) is non-zero: tab - tabular(((p=factor(p))*(a=factor(a))+1) ~ (N = 1) + (b + c)*(mean+sd),data=q) tab[ tab[,1] 0, ] and it produces this: b c p a N mean sdmean sd A 1 10 16.20 3.458 56.3 10.155 3 10 13.60 2.119 58.1 8.075 B 2 10 14.40 2.547 51.2 9.438 All 30 14.73 2.888 55.2 9.419 Indexing of tables isn't as general as indexing of matrices, but most of the simple forms should work. I haven't tested yet, but I expect this will be fine in LaTeX or HTML (also new, not on CRAN yet) output as well. Thank you so much for adding this. I've installed 0.7.54 and it seems to work as advertised. The LaTeX output looks flawless, too. Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] avoid losing data.frame attributes on cbind()
Dear Arun, On Tue, Apr 16, 2013 at 10:45 PM, arun smartpink...@yahoo.com wrote: Another method would be: Xc- Xa Xc$var1-NA; Xc$var2- NA Xc[]- append(as.list(Xa),as.list(Xb)) Unfortunately this is still too convoluted and error prone. And mutate() doesn't work for me, as I generate the new vars elsewhere. So is there no other clean way to append several new variables to a data frame, without losing its attributes? Regards, Liviu str(Xc) #'data.frame':150 obs. of 7 variables: # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... # $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... # $ var1: num 5 5 5 5 5 5 5 5 4 5 ... # $ var2: num 4 3 3 3 4 4 3 3 3 3 ... # - attr(*, label)= chr Some df label A.K. - Original Message - From: arun smartpink...@yahoo.com To: Liviu Andronic landronim...@gmail.com Cc: R help r-help@r-project.org Sent: Tuesday, April 16, 2013 2:40 PM Subject: Re: [R] avoid losing data.frame attributes on cbind() HI, Not sure if this helps: library(plyr) res-mutate(Xa,var1=round(Sepal.Length),var2=round(Sepal.Width)) str(res) #'data.frame':150 obs. of 7 variables: # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... # $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... # $ var1: num 5 5 5 5 5 5 5 5 4 5 ... # $ var2: num 4 3 3 3 4 4 3 3 3 3 ... #- attr(*, label)= chr Some df label A.K. - Original Message - From: Liviu Andronic landronim...@gmail.com To: r-help r-h...@stat.math.ethz.ch Cc: Sent: Tuesday, April 16, 2013 2:24 PM Subject: [R] avoid losing data.frame attributes on cbind() Dear all, How should I add several variables to a data frame without losing the attributes of the df? Consider the following: require(Hmisc) Xa - iris label(Xa, self=T) - Some df label str(Xa) 'data.frame':150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... - attr(*, label)= chr Some df label Xb - round(iris[,1:2]) names(Xb) - c(var1,'var2') Xc - cbind(Xa, Xb) #the attribute is now gone str(Xc) 'data.frame':150 obs. of 7 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... $ var1: num 5 5 5 5 5 5 5 5 4 5 ... $ var2: num 4 3 3 3 4 4 3 3 3 3 ... In such cases, when I want to plug some variables from 2nd df into the 1st df, how should I proceed without losing the attributes of the 1st data frame. And, if possible, I'm looking for something nicer than: for(i in names(Xb)) Xa[ , i] - Xb[ , i] Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] efficiently diff two data frames
Dear Rui, Thanks for the pointer. On Tue, Apr 16, 2013 at 8:12 PM, Rui Barradas ruipbarra...@sapo.pt wrote: setdiffDF2 - function(A, B){ f - function(X, Y) !duplicated(rbind(Y, X))[nrow(Y) + 1:nrow(X)] ix1 - f(A, B) ix2 - f(B, A) ix1 ix2 } ix - setdiffDF2(Xe, Xf) Xe[ix,] Xf[ix,] Note that this gives no information on the columns. This seems to work nicely on the rows. But what about the columns? How would I take the resulting subsets and diff column by column? Thanks, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] avoid losing data.frame attributes on cbind()
Dear Arun, On Fri, Apr 19, 2013 at 6:30 PM, arun smartpink...@yahoo.com wrote: Dear Liviu, May be you can use the method mentioned in the link: http://stackoverflow.com/questions/10404224/how-to-delete-a-row-from-a-data-frame-without-losing-the-attributes This approach is still much too complicated (and as you mentioned off-list, it also removes variable names). For now I've settled with the following function: append.data.frame - function(x, values){ stopifnot(is.data.frame(x)) stopifnot(is.data.frame(values)) for(i in names(values)) x[ , i] - values[ , i] return(x) } Xa - iris label(Xa, self=T) - Some df label attributes(Xa)$label [1] Some df label Xb - round(iris[,1:2]) names(Xb) - c(var1,'var2') Xc - append.data.frame(Xa, Xb) attributes(Xc)$label [1] Some df label This won't work if there is only one variable to be added (i.e. a vector). For now this function works, but I would really rather find a nicer solution to this. Thanks, Liviu str(Xa) #'data.frame':150 obs. of 5 variables: # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... # $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... # - attr(*, label)= chr Some df label Xc- cbind(Xa,Xb) as.data.frame.avector -as.data.frame.vector `[.avector` - function(x,i,...) { r - NextMethod([) mostattributes(r) - attributes(x) r } mostattributes(Xc)- attributes(Xa) str(Xc) #'data.frame':150 obs. of 7 variables: # $ : num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... # $ : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... # $ : num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... # $ : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... # $ : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... # $ : num 5 5 5 5 5 5 5 5 4 5 ... # $ : num 4 3 3 3 4 4 3 3 3 3 ... # - attr(*, label)= chr Some df label A.K. - Original Message - From: Liviu Andronic landronim...@gmail.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org Sent: Friday, April 19, 2013 8:13 AM Subject: Re: [R] avoid losing data.frame attributes on cbind() Dear Arun, On Tue, Apr 16, 2013 at 10:45 PM, arun smartpink...@yahoo.com wrote: Another method would be: Xc- Xa Xc$var1-NA; Xc$var2- NA Xc[]- append(as.list(Xa),as.list(Xb)) Unfortunately this is still too convoluted and error prone. And mutate() doesn't work for me, as I generate the new vars elsewhere. So is there no other clean way to append several new variables to a data frame, without losing its attributes? Regards, Liviu str(Xc) #'data.frame':150 obs. of 7 variables: # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... # $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... # $ var1: num 5 5 5 5 5 5 5 5 4 5 ... # $ var2: num 4 3 3 3 4 4 3 3 3 3 ... # - attr(*, label)= chr Some df label A.K. - Original Message - From: arun smartpink...@yahoo.com To: Liviu Andronic landronim...@gmail.com Cc: R help r-help@r-project.org Sent: Tuesday, April 16, 2013 2:40 PM Subject: Re: [R] avoid losing data.frame attributes on cbind() HI, Not sure if this helps: library(plyr) res-mutate(Xa,var1=round(Sepal.Length),var2=round(Sepal.Width)) str(res) #'data.frame':150 obs. of 7 variables: # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... # $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... # $ var1: num 5 5 5 5 5 5 5 5 4 5 ... # $ var2: num 4 3 3 3 4 4 3 3 3 3 ... #- attr(*, label)= chr Some df label A.K. - Original Message - From: Liviu Andronic landronim...@gmail.com To: r-help r-h...@stat.math.ethz.ch Cc: Sent: Tuesday, April 16, 2013 2:24 PM Subject: [R] avoid losing data.frame attributes on cbind() Dear all, How should I add several variables to a data frame without losing the attributes of the df? Consider the following: require(Hmisc) Xa - iris label(Xa, self=T) - Some df label str(Xa) 'data.frame':150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... $ Species
[R] remove higher order interaction terms
Dear all, Consider the model below: x - lm(mpg ~ cyl * disp * hp * drat, mtcars) summary(x) Call: lm(formula = mpg ~ cyl * disp * hp * drat, data = mtcars) Residuals: Min 1Q Median 3Q Max -3.5725 -0.6603 0.0108 1.1017 2.6956 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 1.070e+03 3.856e+02 2.776 0.01350 * cyl -2.084e+02 7.196e+01 -2.896 0.01052 * disp -6.760e+00 3.700e+00 -1.827 0.08642 . hp -9.302e+00 3.295e+00 -2.823 0.01225 * drat -2.824e+02 1.073e+02 -2.633 0.01809 * cyl:disp 1.065e+00 5.034e-01 2.116 0.05038 . cyl:hp1.587e+00 5.296e-01 2.996 0.00855 ** disp:hp 7.422e-02 3.461e-02 2.145 0.04769 * cyl:drat 5.652e+01 2.036e+01 2.776 0.01350 * disp:drat 1.824e+00 1.011e+00 1.805 0.08990 . hp:drat 2.600e+00 9.226e-01 2.819 0.01236 * cyl:disp:hp -1.050e-02 4.518e-03 -2.323 0.03368 * cyl:disp:drat-2.884e-01 1.392e-01 -2.071 0.05484 . cyl:hp:drat -4.428e-01 1.504e-01 -2.945 0.00950 ** disp:hp:drat -2.070e-02 9.568e-03 -2.163 0.04600 * cyl:disp:hp:drat 2.923e-03 1.254e-03 2.331 0.03317 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.245 on 16 degrees of freedom Multiple R-squared: 0.9284, Adjusted R-squared: 0.8612 F-statistic: 13.83 on 15 and 16 DF, p-value: 2.007e-06 Is there a straightforward way to remove the highest order interaction terms? Say: cyl:disp:hp cyl:disp:drat cyl:hp:drat disp:hp:drat cyl:disp:hp:drat I know I could do this: x - lm(mpg ~ cyl * disp * hp * drat - cyl:disp:hp - cyl:disp:drat - cyl:hp:drat - disp:hp:drat - cyl:disp:hp:drat, mtcars) But I was hoping for a more elegant solution. Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] remove higher order interaction terms
On Wed, Apr 17, 2013 at 2:33 PM, Marc Schwartz marc_schwa...@me.com wrote: If you only want up to say second order interactions: summary(lm(mpg ~ (cyl + disp + hp + drat) ^ 2, data = mtcars)) This is what I was looking for. Thank you so much. This is covered in ?formula Indeed. I tried to parse ?formula at several occasions in the past few years, but never quite grasped it fully. Thanks again, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] efficiently diff two data frames
Dear all, What is the quickest and most efficient way to diff two data frames, so as to obtain a vector of indices (or logical) for rows/columns that differ in the two data frames? For example, Xe - head(mtcars) Xf - head(mtcars) Xf[2:4,3:5] - 55 all.equal(Xe, Xf) [1] Component 3: Mean relative difference: 0.6863118 [2] Component 4: Mean relative difference: 0.4728435 [3] Component 5: Mean relative difference: 14.23546 I could use all.equal(), but it only returns human readable info that cannot be easily used programmatically. It also gives no info on the rows. Another way would be to: require(prob) setdiff(Xe, Xf) mpg cyl disp hp dratwt qsec vs am gear carb Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 144 Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 141 Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 031 But again this doesn't return subsetting indices, nor any info on hte columns. Any suggestions on how to approach this? Regards , Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] avoid losing data.frame attributes on cbind()
Dear all, How should I add several variables to a data frame without losing the attributes of the df? Consider the following: require(Hmisc) Xa - iris label(Xa, self=T) - Some df label str(Xa) 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... - attr(*, label)= chr Some df label Xb - round(iris[,1:2]) names(Xb) - c(var1,'var2') Xc - cbind(Xa, Xb) #the attribute is now gone str(Xc) 'data.frame': 150 obs. of 7 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 1 ... $ var1: num 5 5 5 5 5 5 5 5 4 5 ... $ var2: num 4 3 3 3 4 4 3 3 3 3 ... In such cases, when I want to plug some variables from 2nd df into the 1st df, how should I proceed without losing the attributes of the 1st data frame. And, if possible, I'm looking for something nicer than: for(i in names(Xb)) Xa[ , i] - Xb[ , i] Regards, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to transform string to Camel Case?
Dear all, Given the following vector: (z - c('R project', 'hello world', 'something Else')) [1] R project hello worldsomething Else I know how to obtain all capitals or all lower case letters: tolower(z) [1] r project hello worldsomething else toupper(z) [1] R PROJECT HELLO WORLDSOMETHING ELSE I saw the tocamel() function in 'rapport', but it doesn't do what I want to achieve as it actually proceeds to camelCase/CamelCase the strings: tocamel(z) [1] RProject helloWorldsomethingElse But how should I proceed to obtain Camel Case? Here's what I'd like to get: c('R Project', 'Hello World', 'Something Else') Regards, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to transform string to Camel Case?
On Mon, Apr 15, 2013 at 9:25 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote: See for instance capitalize() in the R.utils package. Unfortunately this also fails when NA values are present: z - c(R project, hello world, something Else, NA) R.utils::capitalize(z) [1] R project Hello worldSomething Else NANA Any pointers how to work around that? Thanks, Liviu Henrik On Apr 14, 2013 11:51 PM, Liviu Andronic landronim...@gmail.com wrote: Dear all, Given the following vector: (z - c('R project', 'hello world', 'something Else')) [1] R project hello worldsomething Else I know how to obtain all capitals or all lower case letters: tolower(z) [1] r project hello worldsomething else toupper(z) [1] R PROJECT HELLO WORLDSOMETHING ELSE I saw the tocamel() function in 'rapport', but it doesn't do what I want to achieve as it actually proceeds to camelCase/CamelCase the strings: tocamel(z) [1] RProject helloWorldsomethingElse But how should I proceed to obtain Camel Case? Here's what I'd like to get: c('R Project', 'Hello World', 'Something Else') Regards, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to transform string to Camel Case?
On Mon, Apr 15, 2013 at 9:20 AM, Pascal Oettli kri...@ymail.com wrote: There is an example of how to do do what you are looking for in ?toupper Unfortunately this fails when NA values are present: z - c(R project, hello world, something Else, NA) tocapwords(z) [1] R Project Hello WorldSomething Else NANA Liviu Regards, Pascal On 04/15/2013 03:50 PM, Liviu Andronic wrote: Dear all, Given the following vector: (z - c('R project', 'hello world', 'something Else')) [1] R project hello worldsomething Else I know how to obtain all capitals or all lower case letters: tolower(z) [1] r project hello worldsomething else toupper(z) [1] R PROJECT HELLO WORLDSOMETHING ELSE I saw the tocamel() function in 'rapport', but it doesn't do what I want to achieve as it actually proceeds to camelCase/CamelCase the strings: tocamel(z) [1] RProject helloWorldsomethingElse But how should I proceed to obtain Camel Case? Here's what I'd like to get: c('R Project', 'Hello World', 'Something Else') Regards, Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to transform string to Camel Case?
On Mon, Apr 15, 2013 at 10:10 AM, Gergely Daróczi gerg...@snowl.net wrote: Dear Liviu, I have just updated tocamel to have a new argument, so the development version of the package would produce: tocamel(z, upper = TRUE, sep = ' ') [1] R Project Hello WorldSomething Else Thanks for putting this in. Unfortunately as with other approaches it fails on NA values: z - c(R project, hello world, something Else, NA) tocamel(z, sep=' ', upper=T) [1] R Project Hello WorldSomething Else NANA Can this be fixed? Thanks, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to transform string to Camel Case?
On Mon, Apr 15, 2013 at 2:22 PM, Gergely Daróczi gerg...@snowl.net wrote: I have added an extra check in the function for NA values before applying `paste` at https://github.com/Rapporter/rapport/compare/34ca6a35fb...a04abc8b21 Alex might not like it :) Example: tocamel(z, upper = TRUE, sep = ' ') [1] R Project Hello WorldSomething Else NA Thanks! Now I'm getting somewhere: z - c(R project, hello world, something Else, something-else, NA) tocamel(z, sep=' ', upper=T, delim= ) [1] R Project Hello WorldSomething Else Something-else [5] NA I hope Alex likes your fixes. Thanks, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] categorized complete list of R commands?
On Thu, Apr 4, 2013 at 7:34 AM, ivo welch ivo.we...@anderson.ucla.edu wrote: I wonder whether there is a complete list of all R commands (incl the standard packages) somewhere, preferably each with its one-liner AND categorization(s). the one-liner can be generated from the documentation. Try the 'sos' package. Not exactly what you ask, but close: once you supply a keyword. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Export R generated tables and figures to MS Word
On Wed, Mar 13, 2013 at 1:02 AM, Santosh santosh2...@gmail.com wrote: Dear Rxperts, I am aware of Sweave that generates reports into a pdf, but do know of any tools to generate to export to a MS Word document... Is there a way to use R to generate and export report/publication quality tables and figures and export them to MS word (for reporting purposes)? Instead of pure LaTeX, you may use LyX to generate Sweave/knitr reports. Liviu Thanks so much, Santosh [[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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RExcel, ROOo and LibreOffice inquiry
Dear all I'd like to give RExcel a decent spin, mainly to take advantage of Excel's data management facilities and automatic recalculations. However I cannot use this Windows-only solution on the platform of my choice, Linux. Alternatively I've been considering the cross-platform ROOo, the OpenOffice equivalent of RExcel, but in this case the problem is that the only release available is a beta version from 2009. I wouldn't want to use that for any serious work, nor I am sure that it works with LibreOffice (as OpenOffice is deprecated). Thus is anyone aware of a cross-platform Gnumeric or LibreOffice solution that emulates what RExcel does for Excel on Windows? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RExcel, ROOo and LibreOffice inquiry
On Sun, Nov 25, 2012 at 2:38 PM, John Kane jrkrid...@inbox.com wrote: Can you supply a link for ROOo ? I don't see it anywhere. Oh, sorry. I thought it was obvious: http://rcom.univie.ac.at/download.html#ROOo Also what do you mean OpenOffice is deprecated? Do you mean in terms of using it with ROOo? Otherwide OOo, now under new management at Apache is under active development under the name Apache Open Office. Sun/Oracle discontinued developing OOo and donated it to Apache, which to my surprise made a recent release. However many Linux distros switched to LibreOffice, originally forked from OOo in 2010. To my understanding LibO is the project that should be followed by end-users. Since ROOo is beta and rather outdated, I was wondering if there were an effort to bring an RExcel-like functionality to recent LibO or Gnumeric releases. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Odp: Object Browser
On Fri, Nov 23, 2012 at 6:44 AM, wampeh wam...@gmail.com wrote: How do I get gvarbrowser to display only data.frame named, say atab1 or atab2 or atab*? Also, how do I turn off the selection pull down box? Two remarks. If you hope to get an answer it would be a good idea to CC John Verzani, maintainer of gWidgets. Give RStudio a try as it comes with a built-in object browser. Liviu #I tried: mydefaultclasses - list(Data sets1=c(data.frame) ) # # Then v - gvarbrowser( container =gwindow(Object broser), gWidgets:gvarbrowser_classes=mydefaultclasses ) #-- # but it does not seem to work #I also tried: options(gWidgets:gvarbrowser_classes=mydefaultclasses) #then v - gvarbrowser( container =gwindow(Object broser)) #this too did not work #I would simply like to display the variable browser window for data.frame atab1 (say). Thank you -- View this message in context: http://r.789695.n4.nabble.com/Object-Browser-tp2594912p4650511.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] latex \subfloat{} incompatible with sweave/knitr code
On Thu, Aug 30, 2012 at 12:50 AM, Yihui Xie x...@yihui.name wrote: Do you know what environments are allowed inside \subfloat{}? The No, not really. From what I can tell, \subfloat{} is provided by the `subfig' package. Here's what their docs have to say about compatibility with verbatim and fancyvrb packages: You cannot place a verbatim environment inside of the \subfloat command because the verbatim environment needs to change the character classes before the text in the environment is read by TEX. Therefore, if you really want to include verbatim text inside a sub-float, you will need to place the verbatim text into a box and then feed the box to the \subfloat command. And this is what CTAN says about the 'subfig' package: The package 'subfigure' is now considered obsolete: it was superseded by 'subfig', but users may find the more recent 'subcaption' package more satisfactory. graphics example works because it is nothing but a simple \includegraphics{} command. The table example you gave is much more complicated than that. I played around with the 'subcaption' package and, although it has some side effects on the figures, it accepts verbatim in its 'subtable' environment. See knitr LyX file and PDF: http://s000.tinyupload.com/index.php?file_id=00455858466446731442 http://s000.tinyupload.com/index.php?file_id=07968719976440864387 Maybe it's high time to ask the LyX devels to implement support for the 'subcaption' package. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] latex \subfloat{} incompatible with sweave/knitr code
On Thu, Aug 30, 2012 at 12:50 AM, Yihui Xie x...@yihui.name wrote: Do you know what environments are allowed inside \subfloat{}? The graphics example works because it is nothing but a simple \includegraphics{} command. The table example you gave is much more complicated than that. Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Wed, Aug 29, 2012 at 3:30 PM, Liviu Andronic landronim...@gmail.com wrote: Hey Yihui On Wed, Aug 29, 2012 at 6:17 PM, Yihui Xie x...@yihui.name wrote: Yes that is one possible solution, but the filename is hard-coded somehow. The key to this problem is a missing new line before =, which was addressed in https://github.com/downloads/yihui/knitr/knitr-subfloats.pdf Thanks a lot for the example. The LyX and Rnw source files can be checked out with GIT under https://github.com/yihui/knitr/tree/master/inst/examples If you open knitr-subfloats.lyx, you will see an intentional new line in the ERT, and that is to break \subfloat[asdfa]{= into \subfloat[asdfa]{ = This trick doesn't seem to work for table subfloats. I added a nearly identical example to your document, this time using table floats (instead of figure floats). [1] The document doesn't compile. Any ideas? Regards Liviu [1] http://s000.tinyupload.com/index.php?file_id=64085332583398153478 -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] don't print object attributes
On Tue, Aug 28, 2012 at 9:05 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 28/08/2012 2:16 PM, Liviu Andronic wrote: I came up with a modified version of the above: print_noattr - function(x, keep.some=T, ...){ if(keep.some) xa - attributes(x)[c('names', 'row.names', 'class')] attributes(x) - NULL if(keep.some) attributes(x) - xa print(x) } [..] However this still feels like a hack, and the function should be modified if the object in question contains some other crucial attributes. I think it's reasonable to say it feels like a hack, because it is. x should have had a class and a print method for that class in the first place, if the attributes are not something that users should see. If they are things you should see, then suppressing them is a bad idea. I think I like most the approach below. print2 - function(x, rm.attr=NULL, ...){ if(!is.null(rm.attr)) attributes(x)[rm.attr] - NULL print(x, ...) } x - dlply(iris, .(Species), function(x) describe(x[, 'Sepal.Length'])) attributes(x) $split_type [1] data.frame $split_labels Species 1 setosa 2 versicolor 3 virginica $names [1] setosa versicolor virginica print2(x, c(split_type, split_labels)) $setosa x[, Sepal.Length] n missing uniqueMean .05 .10 .25 .50 .75 50 0 15 5.0064.404.594.805.005.20 .90 .95 5.415.61 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 5.1 5.2 5.3 5.4 5.5 5.7 5.8 Frequency 1 3 1 4 2 5 4 8 8 3 1 5 2 2 1 % 2 6 2 8 4 10 8 16 16 6 2 10 4 4 2 $versicolor x[, Sepal.Length] n missing uniqueMean .05 .10 .25 .50 .75 50 0 21 5.936 5.045 5.380 5.600 5.900 6.300 .90 .95 6.700 6.755 lowest : 4.9 5.0 5.1 5.2 5.4, highest: 6.6 6.7 6.8 6.9 7.0 $virginica x[, Sepal.Length] n missing uniqueMean .05 .10 .25 .50 .75 50 0 21 6.588 5.745 5.800 6.225 6.500 6.900 .90 .95 7.610 7.700 lowest : 4.9 5.6 5.7 5.8 5.9, highest: 7.3 7.4 7.6 7.7 7.9 This way the user has complete control over what attributes are displayed or not. Wouldn't it be reasonable to have such an argument in print()? Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] latex \subfloat{} incompatible with sweave/knitr code
Dear all Are LaTeX \subfloat{} commands incompatible with Sweave code? I cannot get the following code to compile properly: \begin{table} \subfloat[asdfa]{= 2+2 @ } \caption{asdf} \end{table} If I replace the Sweave chunk with a random string or a table, the compilation works fine. Any ideas what happens? I hit the same trouble when running the code chunks through knitr. Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] latex \subfloat{} incompatible with sweave/knitr code
On Wed, Aug 29, 2012 at 1:34 PM, Steve Lianoglou mailinglist.honey...@gmail.com wrote: This isn't exactly what you want, but I'm using kintr and building and saving my figures in the their own chunks then just inlining the path to the generated figure in the \subloat{..}. Things are working fine, eg. my default settings are to suppress chunk echo/output, generate pdf figures, and fig.path='figs/gen-' so: someFig plot(1:10, 1:10, ...) @ \begin{figure}[...] ... \sublfoat[some][caption]{ \includegraphics[...]{figs/gen-someFig.pdf} } ... \end{figure} does the trick for me. Hmm, but how would I use this for tables? In the subfloats I'm outputting Hmisc::describe() results. Thanks Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] wind maps
Dear all I was wondering what old hacks on this list were thinking about the shiny new wind map, which The Economist describes as breathtaking for its elegance and rich data presentation. [1] What do you think of it? And of authors' other graphs? Can something similar be done in R? Regards Liviu [1] http://www.economist.com/blogs/graphicdetail/2012/08/charting-wind -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] latex \subfloat{} incompatible with sweave/knitr code
Hey Yihui On Wed, Aug 29, 2012 at 6:17 PM, Yihui Xie x...@yihui.name wrote: Yes that is one possible solution, but the filename is hard-coded somehow. The key to this problem is a missing new line before =, which was addressed in https://github.com/downloads/yihui/knitr/knitr-subfloats.pdf Thanks a lot for the example. The LyX and Rnw source files can be checked out with GIT under https://github.com/yihui/knitr/tree/master/inst/examples If you open knitr-subfloats.lyx, you will see an intentional new line in the ERT, and that is to break \subfloat[asdfa]{= into \subfloat[asdfa]{ = This trick doesn't seem to work for table subfloats. I added a nearly identical example to your document, this time using table floats (instead of figure floats). [1] The document doesn't compile. Any ideas? Regards Liviu [1] http://s000.tinyupload.com/index.php?file_id=64085332583398153478 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] don't print object attributes
Dear all Suppose the object below: require(Hmisc) require(plyr) x - dlply(iris, .(Species), describe) How can I print the object without displaying the attributes? I inspected ?print and ?print.default with no luck. x $setosa x[, Sepal.Length] n missing uniqueMean .05 .10 .25 .50 .75 50 0 15 5.0064.404.594.805.005.20 .90 .95 5.415.61 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 5.1 5.2 5.3 5.4 5.5 5.7 5.8 Frequency 1 3 1 4 2 5 4 8 8 3 1 5 2 2 1 % 2 6 2 8 4 10 8 16 16 6 2 10 4 4 2 $versicolor x[, Sepal.Length] n missing uniqueMean .05 .10 .25 .50 .75 50 0 21 5.936 5.045 5.380 5.600 5.900 6.300 .90 .95 6.700 6.755 lowest : 4.9 5.0 5.1 5.2 5.4, highest: 6.6 6.7 6.8 6.9 7.0 $virginica x[, Sepal.Length] n missing uniqueMean .05 .10 .25 .50 .75 50 0 21 6.588 5.745 5.800 6.225 6.500 6.900 .90 .95 7.610 7.700 lowest : 4.9 5.6 5.7 5.8 5.9, highest: 7.3 7.4 7.6 7.7 7.9 attr(,split_type) [1] data.frame attr(,split_labels) Species 1 setosa 2 versicolor 3 virginica Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] don't print object attributes
On Tue, Aug 28, 2012 at 7:34 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: Assign a class to the object, and write a print method for it. For example, this doesn't quite do what you want, but it's a start: print.noattributes - function(x, ...) { attributes(x) - NULL print(x) } class(x) - noattributes x It loses some attributes that you probably want to keep (e.g. the names), but otherwise works on your example. I've already tried this solution but that's exactly the trouble with this approach. Do this on a data.frame and loses important information. I came up with a modified version of the above: print_noattr - function(x, keep.some=T, ...){ if(keep.some) xa - attributes(x)[c('names', 'row.names', 'class')] attributes(x) - NULL if(keep.some) attributes(x) - xa print(x) } x - dlply(iris, .(Species), function(x) describe(x[, 'Sepal.Length'])) print_noattr(x) $setosa x[, Sepal.Length] n missing uniqueMean .05 .10 .25 .50 .75 50 0 15 5.0064.404.594.805.005.20 .90 .95 5.415.61 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 5.1 5.2 5.3 5.4 5.5 5.7 5.8 Frequency 1 3 1 4 2 5 4 8 8 3 1 5 2 2 1 % 2 6 2 8 4 10 8 16 16 6 2 10 4 4 2 $versicolor x[, Sepal.Length] n missing uniqueMean .05 .10 .25 .50 .75 50 0 21 5.936 5.045 5.380 5.600 5.900 6.300 .90 .95 6.700 6.755 lowest : 4.9 5.0 5.1 5.2 5.4, highest: 6.6 6.7 6.8 6.9 7.0 $virginica x[, Sepal.Length] n missing uniqueMean .05 .10 .25 .50 .75 50 0 21 6.588 5.745 5.800 6.225 6.500 6.900 .90 .95 7.610 7.700 lowest : 4.9 5.6 5.7 5.8 5.9, highest: 7.3 7.4 7.6 7.7 7.9 However this still feels like a hack, and the function should be modified if the object in question contains some other crucial attributes. On Tue, Aug 28, 2012 at 7:44 PM, Peter Ehlers ehl...@ucalgary.ca wrote: It seems that class listof also works: class(x) - listof x This works great. Thanks. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] test if elements of a character vector contain letters
On Tue, Aug 7, 2012 at 10:26 PM, Marc Schwartz marc_schwa...@me.com wrote: since there are alpha-numerics present, whereas the first option will: grepl([^[:alnum:]], ab%) [1] TRUE So, use the first option. And I should start reading more carefully. The above works fine for me. I ended up defining the following wrappers: is_alpha - function(x) {grepl([[:alpha:]], x)} ##Alphabetic characters is_digit - function(x) {grepl([[:digit:]], x)} ##Digits is_alnum - function(x) {grepl([[:alnum:]], x)} ##Alphanumeric characters is_punct - function(x) {grepl([[:punct:]], x)} ##Punctuation characters is_notalnum - function(x) {grepl([^[:alnum:]], x)} ##Non-Alphanumeric characters Thanks again Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] test if elements of a character vector contain letters
On Mon, Aug 6, 2012 at 7:35 PM, Marc Schwartz marc_schwa...@me.com wrote: is.letter - function(x) grepl([[:alpha:]], x) is.number - function(x) grepl([[:digit:]], x) Quick follow-up question. I'm always reluctant to create functions that would resemble the method of a function (here, is() ), but would in fact not be a genuine method. So would there be any incompatibility between is() and is.letter(), given that the latter is not a method of the former? Is it good (or acceptable) practice to define is.letter() as above? Would is_letter() be better? Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] add leading zeros
Hello On Fri, Jul 27, 2012 at 6:54 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Much easier than you think: x - c(1L, 9000L) sprintf(%05i,x) For anyone interested, I came up with a small wrapper for the above: add.lead - function(x, width=max(nchar(x))){ sprintf(paste('%0', width, 'i', sep=''), x) } x - c(1L, 15L, 234L, 9000L) (xa - add.lead(x)) [1] 0001 0015 0234 9000 nchar(xa) [1] 4 4 4 4 (xb - add.lead(x, 5)) [1] 1 00015 00234 09000 nchar(xb) [1] 5 5 5 5 (xc - add.lead(x, 15)) [1] 001 015 234 0009000 nchar(xc) [1] 15 15 15 15 Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] issue with nzchar() ?
On Mon, Aug 6, 2012 at 5:27 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: On Mon, Aug 6, 2012 at 9:53 AM, Liviu Andronic landronim...@gmail.com wrote: On Mon, Aug 6, 2012 at 4:48 PM, Liviu Andronic landronim...@gmail.com wrote: string, something that I find strange. At best NA is the equivalent of an empty string. Certainly not to my mind, unless you think that zero and NA should be the same for integers and doubles as well. NA (in whatever form) is, to my mind, _unknown_ which is very different than knowing 0. This is a tricky question and I don't have a strong opinion yet. I'm not sure why that's the case, but it's documented on the help page (under value): For ‘nchar’, an integer vector giving the sizes of each element, currently always ‘2’ for missing values (for ‘NA’). I most certainly missed this bit in the help page. My guess is that it's this way for back-compatability from a time when there probably wasn't a proper NA_character_ (that's the parser literal for a character NA) and they really were just NA (the string) -- perhaps in some far distant R 3.0 we'll see nchar(NA_character_) = NA_integer_ As David has also suggested (and Bert alluded), it may be worth having a nchar(..., returnNA=FALSE) argument, which if TRUE would return NA when it encounters NA values in the original vector. Thank you all for the comments. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] test if elements of a character vector contain letters
On Mon, Aug 6, 2012 at 7:35 PM, Marc Schwartz marc_schwa...@me.com wrote: is.letter - function(x) grepl([[:alpha:]], x) is.number - function(x) grepl([[:digit:]], x) Another follow-up. To test for (non-)alphanumeric one would do the following: x - c(letters, 1:26, '+', '-', '%^') x[1:10] - paste(x[1:10], 1:10, sep='') x [1] a1 b2 c3 d4 e5 f6 g7 h8 i9 j10 k l m n [15] o p q r s t u v w x y z 1 2 [29] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [43] 17 18 19 20 21 22 23 24 25 26 + - %^ xb - grepl([[:alnum:]],x) ##test for alphanumeric chars x[xb] [1] a1 b2 c3 d4 e5 f6 g7 h8 i9 j10 k l m n [15] o p q r s t u v w x y z 1 2 [29] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [43] 17 18 19 20 21 22 23 24 25 26 xb - grepl([[:punct:]],x) ##test for non-alphanumeric chars x[xb] [1] + - %^ More regex rules are available on the Wiki [1]. Regards Liviu [1] http://en.wikipedia.org/wiki/Regular_expression __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] test if elements of a character vector contain letters
On Tue, Aug 7, 2012 at 10:18 PM, Marc Schwartz marc_schwa...@me.com wrote: That will get you values where punctuation characters are used, but there may be other non-alphanumeric characters in the vector. There may be ASCII control codes, tabs, newlines, CR, LF, spaces, etc. which would not be found by using [:punct:]. For example: grepl([[:punct:]], ) [1] FALSE If you want to explicitly look for non-alphanumeric characters, you would be better off using a negation of [:alnum:] such as: [..] !grepl([[:alnum:]], x) Good point! Thanks. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] add leading zeros
On Tue, Aug 7, 2012 at 10:48 PM, David Winsemius dwinsem...@comcast.net wrote: On Aug 7, 2012, at 3:55 AM, Liviu Andronic wrote: For anyone interested, I came up with a small wrapper for the above: add.lead - function(x, width=max(nchar(x))){ sprintf(paste('%0', width, 'i', sep=''), x) } Thanks, Liviu; Glad this helped. Your post prompted me to add a variant in my .Rprofile that adds leading zeros to numeric-date values in ddmm format which lost them because they were imported as integers (because I forgot to use colClasses.) In my case I had Excel mangle up Cusips:Losing leading zeros when there was no letter as part of the Cusip (solved with my function above), and interpreting Cusips containing an E (e.g. 12345E123) as _very_ large numbers. This last part I had to correct manually. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] issue with nzchar() ?
Dear all I'm a bit surprised by the results output from nzchar(). The help page says: nzchar is a fast way to find out if elements of a character vector are *non-empty strings*. (my emphasis. However, if you do x - c(letters, NA, '') nzchar(x) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [25] TRUE TRUE TRUE FALSE any(is.na(x)) [1] TRUE the NA value in the character vector will be considered as a non-empty string, something that I find strange. At best NA is the equivalent of an empty string. In this sense, if you Hmisc::describe() the vector you get, as I would expect, that in the context of character vectors NA and '' values are considered together: require(Hmisc) describe(x) x n missing unique 26 2 26 lowest : a b c d e, highest: v w x y z So is this a bug in the function or in the help page? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] issue with nzchar() ?
On Mon, Aug 6, 2012 at 4:48 PM, Liviu Andronic landronim...@gmail.com wrote: string, something that I find strange. At best NA is the equivalent of an empty string. In this sense, if you Hmisc::describe() the vector you get, as I would expect, that in the context of character vectors NA and '' values are considered together: By the way, same question holds for nchar(): Should NA values be reported as 2-char strings, or as 0-char empty/missing values? x - c(letters, NA, '') nchar(x) [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 0 Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] test if elements of a character vector contain letters
Dear all I'm pretty sure that I'm approaching the problem in a wrong way. Suppose the following character vector: (x[1:10] - paste(x[1:10], sample(1:10, 10), sep='')) [1] a10 b7 c2 d3 e6 f1 g5 h8 i9 j4 x [1] a10 b7 c2 d3 e6 f1 g5 h8 i9 j4 k l m n [15] o p q r s t u v w x y z 1 2 [29] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [43] 17 18 19 20 21 22 23 24 25 26 How do you test whether the elements of the vector contain at least one letter (or at least one digit) and obtain a logical vector of the same dimension? I came up with the following awkward function: is_letter - function(x, pattern=c(letters, LETTERS)){ sapply(x, function(y){ any(sapply(pattern, function(z) grepl(z, y, fixed=T))) }) } is_letter(x) a10b7c2d3e6f1g5h8i9j4 k l m n o TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE p q r s t u v w x y z 1 2 3 4 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE 5 6 7 8 9101112131415 16171819 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE 20212223242526 FALSE FALSE FALSE FALSE FALSE FALSE FALSE is_letter(x, 0:9) ##function slightly misnamed a10b7c2d3e6f1g5h8i9j4 k l m n o TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE p q r s t u v w x y z 1 2 3 4 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE 5 6 7 8 9101112131415 16171819 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 20212223242526 TRUE TRUE TRUE TRUE TRUE TRUE TRUE Is there a nicer way to do this? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] test if elements of a character vector contain letters
On Mon, Aug 6, 2012 at 6:42 PM, Bert Gunter gunter.ber...@gene.com wrote: nzchar(x) !is.na(x) No? It doesn't work for what I need: x [1] a10 b8 c9 d2 e3 f4 g1 h7 i6 j5 k l m n [15] o p q r s t u v w x y z 1 2 [29] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [43] 17 18 19 20 21 22 23 24 25 26 nzchar(x) !is.na(x) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [18] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [35] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [52] TRUE I need to have TRUE when an element contains a letter, and FALSE when an element contains only numbers. The above returns TRUE for the entire vector. Regards Liviu On Mon, Aug 6, 2012 at 9:25 AM, Liviu Andronic landronim...@gmail.com wrote: Dear all I'm pretty sure that I'm approaching the problem in a wrong way. Suppose the following character vector: (x[1:10] - paste(x[1:10], sample(1:10, 10), sep='')) [1] a10 b7 c2 d3 e6 f1 g5 h8 i9 j4 x [1] a10 b7 c2 d3 e6 f1 g5 h8 i9 j4 k l m n [15] o p q r s t u v w x y z 1 2 [29] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [43] 17 18 19 20 21 22 23 24 25 26 How do you test whether the elements of the vector contain at least one letter (or at least one digit) and obtain a logical vector of the same dimension? I came up with the following awkward function: is_letter - function(x, pattern=c(letters, LETTERS)){ sapply(x, function(y){ any(sapply(pattern, function(z) grepl(z, y, fixed=T))) }) } is_letter(x) a10b7c2d3e6f1g5h8i9j4 k l m n o TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE p q r s t u v w x y z 1 2 3 4 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE 5 6 7 8 9101112131415 16171819 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE 20212223242526 FALSE FALSE FALSE FALSE FALSE FALSE FALSE is_letter(x, 0:9) ##function slightly misnamed a10b7c2d3e6f1g5h8i9j4 k l m n o TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE p q r s t u v w x y z 1 2 3 4 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE 5 6 7 8 9101112131415 16171819 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 20212223242526 TRUE TRUE TRUE TRUE TRUE TRUE TRUE Is there a nicer way to do this? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] test if elements of a character vector contain letters
On Mon, Aug 6, 2012 at 7:35 PM, Marc Schwartz marc_schwa...@me.com wrote: is.letter - function(x) grepl([[:alpha:]], x) is.number - function(x) grepl([[:digit:]], x) This does exactly what I wanted: x [1] a10 b8 c9 d2 e3 f4 g1 h7 i6 j5 k l m n [15] o p q r s t u v w x y z 1 2 [29] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [43] 17 18 19 20 21 22 23 24 25 26 xb - grepl([[:alpha:]],x) x[xb] ##extract all vector elements that contain a letter [1] a10 b8 c9 d2 e3 f4 g1 h7 i6 j5 k l m n [15] o p q r s t u v w x y z xb - grepl([[:digit:]],x) x[xb] ##extract all vector elements that contain a digit [1] a10 b8 c9 d2 e3 f4 g1 h7 i6 j5 1 2 3 4 [15] 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [29] 19 20 21 22 23 24 25 26 Thanks all for the suggestions! Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] replace values in vector from a replacement table
On Mon, Jul 30, 2012 at 6:00 PM, jim holtman jholt...@gmail.com wrote: try this: (x - rep(letters,2)) [1] a b c d e f g h i j k l m n o p q r s t u v w [24] x y z a b c d e f g h i j k l m n o p q r s t [47] u v w x y z values - c(aa, a, b, NA, d, zz) repl - c(aa, A, B, NA, D, zz) (repl.tab - cbind(values, repl)) values repl [1,] aa aa [2,] aA [3,] bB [4,] NA NA [5,] dD [6,] zz zz indx - match(x, repl.tab[, 1], nomatch = 0) x[indx != 0] - repl.tab[indx, 2] x [1] A B c D e f g h i j k l m n o p q r s t u v w [24] x y z A B c D e f g h i j k l m n o p q r s t [47] u v w x y z Based on this code I came up with the following function. replace2 - function(x, ind, repl){ if(any(is.na(ind))) ind[is.na(ind)] - 0 if(is.vector(x) is.vector(repl)) { (x[ind != 0] - repl[ind]) return(x) } else if(identical(ncol(x), ncol(repl))){ (x[ind != 0, ] - repl[ind, ]) return(x) } } Whereas replicate() can be used only on vectors of same dimension, replicate2() can be used on vectors and matrices/dataframes, and the replacement data can have different nr of rows. It also works with index vectors containing NAs. ##for vectors (indx - match(x, repl.tab[, 1], nomatch = 0)) [1] 2 3 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [46] 0 0 0 0 0 0 0 head(replace2(x, indx, repl.tab[, 2])) [1] A B c D e f (indx - match(x, repl.tab[, 1])) ##index vector with NAs [1] 2 3 NA 5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 2 3 NA 5 [31] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA head(replace2(x, indx, repl.tab[, 2])) [1] A B c D e f ##for matrices/dataframes head(xx - cbind(x, x)) x x [1,] a a [2,] b b [3,] c c [4,] d d [5,] e e [6,] f f (repl.tab2 - cbind(repl.tab[, 2], repl.tab[, 2])) [,1] [,2] [1,] aa aa [2,] A A [3,] B B [4,] NA NA [5,] D D [6,] zz zz head(replace2(xx, indx, repl.tab2)) x x [1,] A A [2,] B B [3,] c c [4,] D D [5,] e e [6,] f f Does this function have any generic value? Are there obvious implementation mistakes? Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] replace values in vector from a replacement table
Dear all I've got stuck when trying to replace values in a vector by selecting replacements from a replacement table. I'm trying to use only base functions. Here's a dummy example: (x - rep(letters,2)) [1] a b c d e f g h i j k l m n o p q r s t u v [23] w x y z a b c d e f g h i j k l m n o p q r [45] s t u v w x y z values - c(aa, a, b, NA, d, zz) repl - c(aa, A, B, NA, D, zz) (repl.tab - cbind(values, repl)) values repl [1,] aa aa [2,] aA [3,] bB [4,] NA NA [5,] dD [6,] zz zz Now I can easily compute all four combinations of 'match' and '%in%': (ind - match(x, repl.tab[ ,1])) [1] 2 3 NA 5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 2 3 NA [30] 5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA (ind - match(repl.tab[ ,1], x)) [1] NA 1 2 NA 4 NA (ind - x %in% repl.tab[ ,1]) [1] TRUE TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [15] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE [29] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [43] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE (ind - repl.tab[ ,1] %in% x) [1] FALSE TRUE TRUE FALSE TRUE FALSE But how do I actually proceed to obtain the following vector? Can it be done without an explicit apply() or loop? res [1] A B c D e f g h i j k l m n o p q r s t u v [23] w x y z A B c D e f g h i j k l m n o p q r [45] s t u v w x y z Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] replace values in vector from a replacement table
On Mon, Jul 30, 2012 at 6:00 PM, jim holtman jholt...@gmail.com wrote: try this: indx - match(x, repl.tab[, 1], nomatch = 0) x[indx != 0] - repl.tab[indx, 2] x [1] A B c D e f g h i j k l m n o p q r s t u v w [24] x y z A B c D e f g h i j k l m n o p q r s t [47] u v w x y z This is excellent! Thank you Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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: Where's the new Tukey?
On Wed, Jul 18, 2012 at 12:30 AM, Kjetil Halvorsen kjetilbrinchmannhalvor...@gmail.com wrote: Venables Ripley: Modern Applied Statistics with S (fourth Edition) [..] On Sat, Jul 14, 2012 at 4:01 PM, Larry White ljw1...@gmail.com wrote: I'm looking for a single book that provides a deep, yet readable introduction to applied data analysis for general readers. In my experience MASS doesn't apply to general readers. More to experts. I'm looking for coverage on things like understanding randomness, natural experiments, confounding, causality and correlation, data cleaning and transforms, lagging, residuals, exploratory graphics, curve fitting, descriptive stats Preferably with examples/case studies that illustrate the art and craft of data analysis. No proofs or heavy math. I'm no expert, but I'm very happy with what I'm reading in 'Statistics' by Freedman et al. (2007) [1]. This book concerns itself with providing the reader with a clear, intuitive and accessible understanding of the fundamentals of statistics. Its hallmark (for better or worse) is the thorough avoidance of formulas or incomprehensible math jargon. (It still contains a lot of proper jargon, but it doesn't assume, as many books do, that the user perfectly understands all the mathematical and statistical terms.) The book requires, essentially, no prerequisites from the reader. As far as I go, very good. [1] https://en.wikipedia.org/wiki/David_A._Freedman_(statistician) For a more rigorous, mathematic and advanced approach I like Applied Regression Analysis and GLM by Fox (2008). Whereas the first book is concerned with intuition, this book is focused on application (in the context of regression analysis). To freely quote the author, the text is as accessible as possible without the material being watered down unduly. The prerequisites for reading the book are higher. As far as I'm concerned, the material is clearly exposed and the author tackles head-on a lot of thorny issues that other books leave untouched. I guess this qualifies as deep, yet readable introduction. This last book can be perfectly complemented with An R Companion to Applier Regression by Fox and Weisberg (2011). This is to teach people R in the context of regression analysis. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] HLOOKUP in R
On Fri, Jul 13, 2012 at 9:25 PM, Silje Nord silje.nordg...@gmail.com wrote: Is there a function similar to excel's hlookup in R ? Try match(). I think it provides hlookup() functionality. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] fill 0-row data.frame with 1 line of NAs
On Tue, Jul 10, 2012 at 4:53 PM, Peter Ehlers ehl...@ucalgary.ca wrote: Both this and Liviu's original solution destroy the factor nature of 'Species' (which may not matter, of course). How about (.xb - iris[ iris$Species=='zz', ]) .xb - .xb[1, ] # this probably shouldn't work, but it does. This one is an excellent solution, but yet another---what I call---quirky behaviour from R. Thanks all! Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] fill 0-row data.frame with 1 line of NAs
On Wed, Jul 11, 2012 at 9:56 PM, William Dunlap wdun...@tibco.com wrote: Why does one want to replace a zero-row data.frame with a one-row data.frame of NA's? Unless this is for an external program that cannot handle zero-row inputs, this suggests that there is an unnecessary limitation (i.e., a bug) in the R code that uses this data.frame. I'm running an apply(df, 1, f) function, where f() matches a df$string in another matrix and fetches data associated with this string. When no match is made I do not need a zero-row data frame, but to preserve the structure of the original df I need a data frame with 1 row of NAs. There may be a nicer approach, but I'm not aware of any. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] fill 0-row data.frame with 1 line of NAs
Dear all Is there a simpler method to achieve the following: When I obtain an empty data.frame after subsetting, I need for it to contain one line of NAs. Here's a dummy example: (.xb - iris[ iris$Species=='zz', ]) [1] Sepal.Length Sepal.Width Petal.Length Petal.Width Species 0 rows (or 0-length row.names) dim(.xb) [1] 0 5 (.xa - data.frame(matrix(rep(NA, ncol(.xb)), 1))) X1 X2 X3 X4 X5 1 NA NA NA NA NA names(.xa) - names(.xb) (.xb - .xa) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 NA NA NA NA NA The solution I came up with is way too convoluted. Anything simpler? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] convert 'character' vector containing mixed formats to 'Date'
Dear all I have a 'character' vector containing mixed formats (thanks Excel!) and I'd like to translate it into a default %Y-%m-%d Date vector. x - c(1/3/2005, 13/04/2004, 2/5/2005, 2/5/2005, 7/5/2007, 22/04/2004, 21/04/2005, 20080430, 13/05/2003, 20080529, NA, NA, 19/05/1999, 17/05/2000, 17/05/2000) In the above you will see that some dates are of format=%d/%m/%Y, others of format=%Y%m%d and some NA values. Can you suggest a straight-forward way of transforming these to a uniform 'character' or 'Date' vector? I tried to do the following, but it outputs very strange results: x [1] 1/3/2005 13/04/2004 2/5/2005 2/5/2005 7/5/2007 22/04/2004 [7] 21/04/2005 20080430 13/05/2003 20080529 NA NA [13] 19/05/1999 17/05/2000 17/05/2000 sum(xa - grepl('/', x)) [1] 11 sum(xb - grepl('200', substr(x, 1,4))) [1] 2 sum(xc - is.na(x)) [1] 2 x[xa] - as.Date(x[xa], format=%d/%m/%Y) x[xb] - as.Date(x[xb], format=%Y%m%d) x [1] 12843 12521 12905 12905 13640 12530 12894 13999 12185 14028 [11] NA NA 10730 11094 11094 The culprit is likely that the 'x' vector is 'character' throughout, but I'm not sure how to work around. For example, I couldn't figure how to create an empty 'Date' vector. Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] convert 'character' vector containing mixed formats to 'Date'
On Thu, Jun 21, 2012 at 2:48 PM, Liviu Andronic landronim...@gmail.com wrote: The culprit is likely that the 'x' vector is 'character' throughout, but I'm not sure how to work around. For example, I couldn't figure how to create an empty 'Date' vector. Regards I think I managed to crack this by myself. I only needed to add an as.character() call: x[xa] - as.character(as.Date(x[xa], format=%d/%m/%Y)) x[xb] - as.character(as.Date(x[xb], format=%Y%m%d)) x [1] 2005-03-01 2004-04-13 2005-05-02 2005-05-02 2007-05-07 2004-04-22 [7] 2005-04-21 2008-04-30 2003-05-13 2008-05-29 NA NA [13] 1999-05-19 2000-05-17 2000-05-17 Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] QQplot normally distributed
Dear Özgür On Wed, Jun 20, 2012 at 7:37 AM, Özgür Asar oa...@metu.edu.tr wrote: Why do you prefer robust methods in the example of Noor and why you need exact normality here? The idea is that when you do hypothesis testing to check whether a given distribution is normal, the results are rarely informative: - if you do not reject the null: you couldn't find sufficient evidence to reject normality, but you don't know what distribution your data follows. You cannot conclude from this result that your data is normal. - if you reject the null: according to the assumptions of the specific test chosen, you find that your distribution doesn't follow normality. But you still don't know what distribution it follows. And at this point you should decide whether you want to check for exact normality, which no distribution conforms to, or approximate normality. Again, see ?SnowsPenultimateNormalityTest and the numerous comments of Greg Snow on this subject on r-help. For example [1]. I also like Uwe Liggs take here [2] (which largely inspired my comments above). Regards Liviu [1] http://tolstoy.newcastle.edu.au/R/e13/help/11/01/0440.html [2] http://tolstoy.newcastle.edu.au/R/e8/help/09/12/6955.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] QQplot normally distributed
On Tue, Jun 19, 2012 at 12:42 PM, Özgür Asar oa...@metu.edu.tr wrote: Following a straight line indicates less evidence towards non-normality. But QQ-Plot is an exploratory tool. You can confirm your ideas obtained from the QQ-Plot via noramlity tests such as Shapiro-Wilk test. Hmm, some gurus on this list would likely disagree. fortune('normality') Usually (but not always) doing tests of normality reflect a lack of understanding of the power of rank tests, and an assumption of high power for the tests (qq plots don't always help with that because of their subjectivity). When possible it's good to choose a robust method. Also, doing pre-testing for normality can affect the type I error of the overall analysis. -- Frank Harrell R-help (April 2005) fortune('normality') The issue really comes down to the fact that the questions: exactly normal?, and normal enough? are 2 very different questions (with the difference becoming greater with increased sample size) and while the first is the easier to answer, the second is generally the more useful one. -- Greg Snow (answering a question about a normality test suitable for large data) R-help (April 2009) For more on this, see ?SnowsPenultimateNormalityTest in TeachingDemos and the references within. Also search the archives as this topic pops up regularly. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 quantreg - symmetry test - bootstrap SE
On Tue, May 29, 2012 at 8:30 AM, stefan23 stefan.vo...@uni-konstanz.de wrote: He folks, I want to use quantile regression for doing a test of symmetrie of a distribution. Following Buchinsky I want to test, whether the square of \tau = \beta(p)+\beta(1-p)-2*\beta(0.5) (\beta(\tau) is the estimated slope parameter for quantile \tau).Unfortunately I do not know how to implement design bootstrap matrix for calculating the standard error. See: http://www.statmethods.net/advstats/bootstrapping.html http://socserv.mcmaster.ca/jfox/Books/Companion/appendix/Appendix-Bootstrapping.pdf Liviu Do you know if there is an existent package computing the necessesary statistics for me? Or do you have an idea how to calculate the standard error? I know that this question contains several big issues and I am very sorry that it is not possible for me to do it for my self or at least to present some parts of it...thank you very, very much for every comment! Cheers Stefan -- View this message in context: http://r.789695.n4.nabble.com/R-quantreg-symmetry-test-bootstrap-SE-tp4631662.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] “For” calculation is so slow
On Tue, May 22, 2012 at 9:01 AM, jiangxijixzy jiangxiji...@163.com wrote: The function I wrote can run well with the small data, but with the large data, the function runs very very slowly. How can I correct it? Thank you very much. My function as below: I guess this is a classic loops vs vectorization problem. fortune('treat') Contrary to popular belief the speed of R's interpreter is rarely the limiting factor to R's speed. People treating R like C is typically the limiting factor. You have vector operations, USE THEM. -- Byron Ellis R-help (October 2005) I would suggest that you read up on vectorization in R to understand why it is often preferred to loops. Two obvious places are an Rnews article by John Fox (if I remember well) and his Companion to Applied Regression book. Moreover, please sign your messages with your real name. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] What's wrong with MEAN?
On Tue, May 22, 2012 at 11:22 AM, Vincy Pyne vincy_p...@yahoo.ca wrote: Thanks a lot for pointing out such a silly mistake from my side. I was simply wondering how come I am not getting such a simple mean. To avoid such mistakes it would help to first store your data in a vector. x-c(16,18) mean(x) [1] 17 If you did otherwise: x- 16,18 Error: unexpected ',' in x- 16, then R would complain. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sweave tables as images?
On Mon, May 21, 2012 at 10:29 PM, Alexander Shenkin ashen...@ufl.edu wrote: So, I think it will be better if I can somehow generate the tables as images. Is there any way to generate tables as images in separate files in Sweave? Or, is there another tree up which I should be barking? Hmm, there are Sweave equivalents for LibreOffice [1] and MS Word [2]. Have you looked into those? You may find other suggestions in the ReproducibleResearch Task View [3]. Liviu [1] http://crantastic.org/packages/odfWeave [2] http://crantastic.org/packages/SWordInstaller [3] http://crantastic.org/task_views/ReproducibleResearch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sweave tables as images?
On Tue, May 22, 2012 at 3:24 PM, Alexander Shenkin ashen...@ufl.edu wrote: If I understand it correctly, odfWeave doesn't have a path backwards from the odf doc back to the original odfWeave doc (which is the main restriction of all these Sweave/knitr/etc solutions in my use case). Please correct me if I'm wrong about that! Unfortunately I cannot help you with this specific question, not least because I've never used odfWeave. From a quick glance to the docs, it seems that you always have two documents: source odfWeave .odt (equivalent to .Rnw) and output .odt (equivalent to .tex). Then using the .odt (.tex) you can generate a PDF. I would be surprised if it were possible to go back from .odt (.tex) to the source .odt (.Rnw). I would suggest that you contact the authors of the respective packages to make sure that the functionality is (not) available. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getting a Likert plot from a data frame
Dear Richard On Tue, May 22, 2012 at 3:20 PM, Richard M. Heiberger r...@temple.edu wrote: mydata - data.frame( row.names=c(group1, group2, group3, group4, group5), males=c(20,30,45,12,5), females=c(35,23,32,8,5)) ## make a pyramid Likert chart as.pyramidLikert(likert(mydata), panel.width=.46) Loading library(HH) and running the code above fails with this error: as.pyramidLikert(likert(mydata), panel.width=.46) Error in inherits(x, trellis) : could not find function likert Am I doing something wrong? Liviu sessionInfo() R version 2.14.2 (2012-02-29) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] splines grid stats graphics grDevices utils datasets [8] methods base other attached packages: [1] HH_2.2-23 latticeExtra_0.6-19 RColorBrewer_1.0-5 [4] leaps_2.9 multcomp_1.2-12 survival_2.36-12 [7] mvtnorm_0.9-9992lattice_0.20-6 plyr_1.7.1 [10] Defaults_1.1-1 fortunes_1.5-0 sos_1.3-1 [13] brew_1.0-6 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getting a Likert plot from a data frame
On Tue, May 22, 2012 at 4:00 PM, Richard M. Heiberger r...@temple.edu wrote: out-of-phase problem Update to HH_2.3-15 that was published on CRAN yesterday. Thanks! It works nicely now. Liviu In HH_2.2-23 you needed to use a slightly longer name plot.likert() instead of likert() On Tue, May 22, 2012 at 9:44 AM, Liviu Andronic landronim...@gmail.com wrote: Dear Richard On Tue, May 22, 2012 at 3:20 PM, Richard M. Heiberger r...@temple.edu wrote: mydata - data.frame( row.names=c(group1, group2, group3, group4, group5), males=c(20,30,45,12,5), females=c(35,23,32,8,5)) ## make a pyramid Likert chart as.pyramidLikert(likert(mydata), panel.width=.46) Loading library(HH) and running the code above fails with this error: as.pyramidLikert(likert(mydata), panel.width=.46) Error in inherits(x, trellis) : could not find function likert Am I doing something wrong? Liviu sessionInfo() R version 2.14.2 (2012-02-29) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] splines grid stats graphics grDevices utils datasets [8] methods base other attached packages: [1] HH_2.2-23 latticeExtra_0.6-19 RColorBrewer_1.0-5 [4] leaps_2.9 multcomp_1.2-12 survival_2.36-12 [7] mvtnorm_0.9-9992 lattice_0.20-6 plyr_1.7.1 [10] Defaults_1.1-1 fortunes_1.5-0 sos_1.3-1 [13] brew_1.0-6 -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Menus - best practices?
On Sat, May 19, 2012 at 9:31 AM, peter dalgaard pda...@gmail.com wrote: Best practice is a bit contentious, but several people have found that the tcltk package offers a path of low resistance. Additionally check gWidgets. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Taking a lead in panel data
On Tue, May 8, 2012 at 12:14 PM, Apoorva Gupta apoorva.ni...@gmail.com wrote: I have checked that. It allows me to get the t-1, t-2 value but not the t+1 value. Is there any other way of achieving this other than using the plm package? It would be easier to help if you provided a minimal reproducible example, as requested in the posting guide. Have you tried diff(x, lag = -1, ...) or lag(x, k = -1, ...) Perhaps this does what you want. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Taking a lead in panel data
On Mon, May 7, 2012 at 3:21 PM, Apoorva Gupta apoorva.ni...@gmail.com wrote: Dear R users, I am working with panel data and I want the difference of a variable with its t+1 value. Could you tell me if such a function exists in the plm package? Perhaps diff() or lag(). See the plm vignette. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] alarm() doesn't beep
Dear all I'd like to make a beeping sound in R, but alarm() doesn't beep? I checked ?alarm but I couldn't find any pointers to system configuration. Any ideas? Regards Liviu sessionInfo() R version 2.14.2 (2012-02-29) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] plyr_1.7.1 Defaults_1.1-1 fortunes_1.5-0 sos_1.3-1 brew_1.0-6 -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] alarm() doesn't beep
On Sat, May 5, 2012 at 8:34 PM, David Winsemius dwinsem...@comcast.net wrote: Is there a command you could call with system()? Yes. Something like: system(play /tmp/02Canon.mp3) works jsut fine. But I was curious about alarm(). Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] recommended way to group function calls in Sweave
Dear Rainer On Wed, Apr 25, 2012 at 5:34 PM, Rainer Schuermann rainer.schuerm...@gmx.net wrote: chunk_name_1,eval=FALSE,echo=FALSE= I like the 'eval=FALSE' trick. SweaveInput( setup.Rnw ) and from here, I can suse the named chunks almost like function calls, as you you describe below. The advantage (for me) is that I have only one place where I maintain the functions code, and only one line in the real document, rather than a lot of code, possibly distributed over the document.. This makes sense for LaTeX, but I actually use LyX and things are a bit more straightforward there. I can put the initialization chunks within a 'TeX inset' that can be collapsed; this way it contains all the necessary code, but takes up only one line in the editor. I attach an example .lyx file. I renamed it to .lyx.txt and cross finger that r-help will accept the attachment; make sure to rename it back when trying to open with LyX. Regards Liviu #LyX 2.0 created this file. For more info see http://www.lyx.org/ \lyxformat 413 \begin_document \begin_header \textclass article \use_default_options true \begin_modules sweave \end_modules \maintain_unincluded_children false \language english \language_package default \inputencoding auto \fontencoding global \font_roman default \font_sans default \font_typewriter default \font_default_family default \use_non_tex_fonts false \font_sc false \font_osf false \font_sf_scale 100 \font_tt_scale 100 \graphics default \default_output_format default \output_sync 0 \bibtex_command default \index_command default \paperfontsize default \spacing single \use_hyperref false \papersize default \use_geometry false \use_amsmath 1 \use_esint 1 \use_mhchem 1 \use_mathdots 1 \cite_engine basic \use_bibtopic false \use_indices false \paperorientation portrait \suppress_date false \use_refstyle 1 \index Index \shortcut idx \color #008000 \end_index \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \paragraph_indentation default \quotes_language english \papercolumns 1 \papersides 1 \paperpagestyle default \tracking_changes false \output_changes false \html_math_output 0 \html_css_as_file 0 \html_be_strict false \end_header \begin_body \begin_layout Standard \begin_inset ERT status collapsed \begin_layout Plain Layout echo=FALSE, results=hide= \end_layout \begin_layout Plain Layout library(xtable) \end_layout \begin_layout Plain Layout d - iris \end_layout \begin_layout Plain Layout ind - 1 \end_layout \begin_layout Plain Layout @ \end_layout \begin_layout Plain Layout \end_layout \begin_layout Plain Layout chunk_name_1,eval=FALSE,echo=FALSE= \end_layout \begin_layout Plain Layout x - cor(d[ , ind]) \end_layout \begin_layout Plain Layout @ \end_layout \begin_layout Plain Layout \end_layout \begin_layout Plain Layout chunk_name_2,eval=FALSE,echo=FALSE= \end_layout \begin_layout Plain Layout # produce a nice table from some data \end_layout \begin_layout Plain Layout xtable(x) \end_layout \begin_layout Plain Layout @ \end_layout \end_inset \end_layout \begin_layout Standard Here's a sample use of Sweave macros. \end_layout \begin_layout Standard \begin_inset ERT status open \begin_layout Plain Layout echo=F, results=tex= \end_layout \begin_layout Plain Layout d - mtcars \end_layout \begin_layout Plain Layout ind - 1:3 \end_layout \begin_layout Plain Layout chunk_name_1 \end_layout \begin_layout Plain Layout chunk_name_2 \end_layout \begin_layout Plain Layout @ \end_layout \end_inset \end_layout \end_body \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.