Re: [R] strange answer when using 'aggregate()' with a formula
I appreciate your kind guidance! I did not read the manual carefully (it's my fault). Thank you so much, Prof. John Fox! Chel Hee Lee On 01/21/2016 12:52 AM, Fox, John wrote: Dear Chel Hee Lee, With the formula method, the default na.action is na.omit; thus, aggregate(y~grp, data=tmp, function(x) sum(is.na(x)), na.action=na.pass) grp y 1 2 1 2 3 0 I hope this helps, John - John Fox, Professor McMaster University Hamilton, Ontario Canada L8S 4M4 Web: socserv.mcmaster.ca/jfox -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Chel Hee Lee Sent: January 21, 2016 5:08 AM To: R-help@r-project.org Subject: [R] strange answer when using 'aggregate()' with a formula Could you kindly test the following codes? It is because I found strange answer when 'aggregate()' is used with a formula. I am trying to count how many missing data entries are in each group. For this exercise, I created data as below: > tmp <- data.frame(grp=c(2,3,2,3), y=c(NA, 0.5, 3, 0.5)) > tmp grp y 1 2 NA 2 3 0.5 3 2 3.0 4 3 0.5 I see that observations (variable y) can be grouped into two groups (variable grp). For group 2, y has NA and 3.0. For group 3, y has 0.5 and 0.5. Hence, the number of missing values is 1 and 0 for group 2 and 3, respectively. This work can be done using 'aggregate()' in the 'stats' package as below: > aggregate(x=tmp$y, by=list(grp=tmp$grp), function(x) sum(is.na(x))) grp x 1 2 1 2 3 0 A formula can be used as below: > aggregate(y~grp, data=tmp, function(x) sum(is.na(x))) grp y 1 2 0 2 3 0 What a surprise! Is this a bug? I would appreciate if you share the results after testing the codes. Thank you so much for your helps in advance! Chel Hee Lee __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] strange answer when using 'aggregate()' with a formula
Could you kindly test the following codes? It is because I found strange answer when 'aggregate()' is used with a formula. I am trying to count how many missing data entries are in each group. For this exercise, I created data as below: > tmp <- data.frame(grp=c(2,3,2,3), y=c(NA, 0.5, 3, 0.5)) > tmp grp y 1 2 NA 2 3 0.5 3 2 3.0 4 3 0.5 I see that observations (variable y) can be grouped into two groups (variable grp). For group 2, y has NA and 3.0. For group 3, y has 0.5 and 0.5. Hence, the number of missing values is 1 and 0 for group 2 and 3, respectively. This work can be done using 'aggregate()' in the 'stats' package as below: > aggregate(x=tmp$y, by=list(grp=tmp$grp), function(x) sum(is.na(x))) grp x 1 2 1 2 3 0 A formula can be used as below: > aggregate(y~grp, data=tmp, function(x) sum(is.na(x))) grp y 1 2 0 2 3 0 What a surprise! Is this a bug? I would appreciate if you share the results after testing the codes. Thank you so much for your helps in advance! Chel Hee Lee __ 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] Translation of R Manuals
Dear the members in the R-help mailing list, R version 2.1.0 and later support translations of program messages. The continuous efforts have been made by R Translation Teams http://developer.r-project.org/TranslationTeams.html. I appreciate the leadership shown by Prof. Duncan Murdoch in this field. Also, I'd like to express thanks to other R core members regarding the support of R message translation. From this point, I would like to share my experience on the translation of R manuals. The R Documentation files are licensed under the General Public License, version 2 or 3. This means that the pilot project to translate them into other languages has permission to reproduce them and translate them. I have worked to build a framework that allows us to keep translation up-to-dated along with the development of R. You can see the prototype of this work in the section Language Support for R - Translation of Messages and Documentation at http://homepage.usask.ca/~chl948/;. You will see title of manual, English text, Template for other languages, Verbatim process, and translated manual. GNU 'gettext' utilities are employed for this work. The portable object template is updated a weekly basis or whenever changes are necessary. The work process is identical to the process of translating R messages. I would appreciate if you are interested in this project. Please contact me if you voluntarily participate in or offer your help with this project of translating R manuals. Comments and corrections is of course most welcome. Chel Hee Lee __ 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] Broken links (???) in rw-FAQ
Thank you so much, David! I also confirmed that the link moved is not found. Chel Hee Lee On 15-06-24 04:15 PM, David Winsemius wrote: On Jun 24, 2015, at 10:52 AM, Chel Hee Lee wrote: Could you also kindly check the following links in the rw-FAQ manual at http://cran.r-project.org/bin/windows/base/rw-FAQ.html?? The links list in the below seem to be broken. I hope these links are fixed in the very near future. Under the section 2.4 Can I customize the installation? * Setup (http://jrsoftware.org/ishelp.php) for details. Under the section 3.3 I want to run R in Chinese/Japanese/Korean * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_language_and_country_strings.asp Under the section 2.26 There is no tilde on my keyboard! * http://office.microsoft.com/en-us/word/HP052590631033.aspx With regard to this one, there was a discussion of this just yesterday in StackOverflow (relative to Italian keyboards which don't seem to be mentioned in the current version of the rw-FAQ). Admittedly this material is not immediately relevant to a windows setup since the question was coming from a Linux user. http://stackoverflow.com/questions/31015152/how-to-type-tilde-in-r http://superuser.com/questions/667622/italian-keyboard-entering-the-tilde-and-backtick-characters-without-cha Looking at some of the linked material, it appears that Windows and Linux have distinctly different answers to tilde-deficient keyboard concerns, so there might be a reason to move a more general answer to R-FAQ and perhaps include material in the section on Internationalization? I could find no mention of tilde-problems in the R-FAQ or the Admin/Setup document. This link is in fact moved to https://support.office.com/en-us/article/HP052590631?CorrelationId=98eaa529-e95a-4628-90ac-1a1da4526b17 That link was 404-ed when I tried it. Under the section 2.24 Does R run under Windows Vista/7/8/Server 2008? * http://windowsvistablog.com/blogs/windowsvista/archive/2007/01/23/security-features-vs-convenience.aspx I appreciate your help! Chel Hee Lee __ 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] Broken links (???) in R-FAQ
Thank you so much, Jim. Yes, I also see that the wiki (rwiki.sciviews.org) is not found. Chel Hee Lee On 15-06-25 04:54 AM, Jim Lemon wrote: Hi Chel Hee, The last link (for FAQ 7.39) is dead and the domain (rwiki.sciviews.org) is not there either. Jim On Thu, Jun 25, 2015 at 3:45 AM, Chel Hee Lee chl...@mail.usask.ca wrote: Could you kindly check if the following links are working fine in the R-FAQ page at http://cran.r-project.org/doc/FAQ/R-FAQ.html? The links listed in the below seem to be broken. I hope these links are fixed in the very near future. Under the section 2.6 Are there Unix-like binaries for R?, * http://CRAN.R-project.org/bin/linux/debian/README Under the section 2.10 What is CRAN?, * http://cran.au.R-project.org/ * http://cran.pt.R-project.org/ Under the section 2.14 What is R-Forge?, * GForge www.gforge.org Under the section 3.1 What is S?, * http://cm.bell-labs.com/cm/ms/departments/sia/Sbook/ * http://cm.bell-labs.com/cm/ms/departments/sia/S/history.html Under the section 4 R Web Interfaces, * http://rwiki.sciviews.org/doku.php?id=faq-r#web_interfaces * Rserve http://stats.math.uni-augsburg.de/Rserve/ Under the section 5.1.4 Add-on packages from Bioconductor, * Bioconductor software packages http://www.bioconductor.org/packages/bioc/ Under the section 7.39 How do I create a plot with two y-axes?, * http://rwiki.sciviews.org/doku.php?id=tips:graphics-base:2yaxes I appreciate your helps! Chel Hee Lee __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Broken links (???) in rw-FAQ
Could you also kindly check the following links in the rw-FAQ manual at http://cran.r-project.org/bin/windows/base/rw-FAQ.html?? The links list in the below seem to be broken. I hope these links are fixed in the very near future. Under the section 2.4 Can I customize the installation? * Setup (http://jrsoftware.org/ishelp.php) for details. Under the section 3.3 I want to run R in Chinese/Japanese/Korean * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_language_and_country_strings.asp Under the section 2.26 There is no tilde on my keyboard! * http://office.microsoft.com/en-us/word/HP052590631033.aspx This link is in fact moved to https://support.office.com/en-us/article/HP052590631?CorrelationId=98eaa529-e95a-4628-90ac-1a1da4526b17 Under the section 2.24 Does R run under Windows Vista/7/8/Server 2008? * http://windowsvistablog.com/blogs/windowsvista/archive/2007/01/23/security-features-vs-convenience.aspx I appreciate your help! Chel Hee Lee __ 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] Broken links (???) in R-FAQ
Could you kindly check if the following links are working fine in the R-FAQ page at http://cran.r-project.org/doc/FAQ/R-FAQ.html? The links listed in the below seem to be broken. I hope these links are fixed in the very near future. Under the section 2.6 Are there Unix-like binaries for R?, * http://CRAN.R-project.org/bin/linux/debian/README Under the section 2.10 What is CRAN?, * http://cran.au.R-project.org/ * http://cran.pt.R-project.org/ Under the section 2.14 What is R-Forge?, * GForge www.gforge.org Under the section 3.1 What is S?, * http://cm.bell-labs.com/cm/ms/departments/sia/Sbook/ * http://cm.bell-labs.com/cm/ms/departments/sia/S/history.html Under the section 4 R Web Interfaces, * http://rwiki.sciviews.org/doku.php?id=faq-r#web_interfaces * Rserve http://stats.math.uni-augsburg.de/Rserve/ Under the section 5.1.4 Add-on packages from Bioconductor, * Bioconductor software packages http://www.bioconductor.org/packages/bioc/ Under the section 7.39 How do I create a plot with two y-axes?, * http://rwiki.sciviews.org/doku.php?id=tips:graphics-base:2yaxes I appreciate your helps! Chel Hee Lee __ 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] How to solve this complex equation
A~ha~!! Thank you, Prof. Peter Dalgaard, so much for your wonderful lesson!!! Learning new things everyday from this R-help mailing list! Chel Hee Lee On 2/11/2015 10:37 AM, peter dalgaard wrote: On 11 Feb 2015, at 17:11 , Chel Hee Lee chl...@mail.usask.ca wrote: The functional form given in the post written by Ssuhanchen captures my eyes. It is the cumulative distribution function of Poisson when the number of counts is less than or equal to 2 with unknown parameter mu=x/2. Since it is a nonlinear function, there may be multiple solutions but the solution should be greater than 0 (if I am in the right track). I am assuming this functional form is originated from the Poisson. Under this assumption, one solution is found as below: rt - uniroot(function(x) ppois(2, lambda=x)-0.05, interval=c(0.5,1), extendInt=yes) Warning messages: 1: In ppois(2, lambda = x) : NaNs produced 2: In ppois(2, lambda = x) : NaNs produced 3: In ppois(2, lambda = x) : NaNs produced ppois(2, lambda=rt$root) [1] 0.051 rt$root [1] 6.295791 Thus, the solution x would be rt$root*2 (Note that I did not try to find other solutions). I hope this helps. Given the Poisson connection, I would pretty strongly expect the solution to be unique. Notice also that your rt$root comes out as the upper end of the confidence interval in poisson.test(2, alt=l) Exact Poisson test data: 2 time base: 1 number of events = 2, time base = 1, p-value = 0.9197 alternative hypothesis: true event rate is less than 1 95 percent confidence interval: 0.00 6.295794 sample estimates: event rate 2 Chel Hee Lee On 2/10/2015 2:29 AM, Rolf Turner wrote: On 10/02/15 14:04, Ssuhanchen wrote: Hi! I want to use R to calculate the variable x which is in a complex equation in below: 2 Σ[exp(-x/2)*(x^k)/(2^k*k!)]=0.05 k=0 how to solve this equation to get the exact x in R? Is this homework? Sure looks like it. Talk to your prof. Or do a bit of work on learning how to use R --- which is presumably the point of the exercise. cheers, Rolf Turner __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to solve this complex equation
The functional form given in the post written by Ssuhanchen captures my eyes. It is the cumulative distribution function of Poisson when the number of counts is less than or equal to 2 with unknown parameter mu=x/2. Since it is a nonlinear function, there may be multiple solutions but the solution should be greater than 0 (if I am in the right track). I am assuming this functional form is originated from the Poisson. Under this assumption, one solution is found as below: rt - uniroot(function(x) ppois(2, lambda=x)-0.05, interval=c(0.5,1), extendInt=yes) Warning messages: 1: In ppois(2, lambda = x) : NaNs produced 2: In ppois(2, lambda = x) : NaNs produced 3: In ppois(2, lambda = x) : NaNs produced ppois(2, lambda=rt$root) [1] 0.051 rt$root [1] 6.295791 Thus, the solution x would be rt$root*2 (Note that I did not try to find other solutions). I hope this helps. Chel Hee Lee On 2/10/2015 2:29 AM, Rolf Turner wrote: On 10/02/15 14:04, Ssuhanchen wrote: Hi! I want to use R to calculate the variable x which is in a complex equation in below: 2 Σ[exp(-x/2)*(x^k)/(2^k*k!)]=0.05 k=0 how to solve this equation to get the exact x in R? Is this homework? Sure looks like it. Talk to your prof. Or do a bit of work on learning how to use R --- which is presumably the point of the exercise. cheers, Rolf Turner __ 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] Rotate array by 90°
lapply(1:2, function(x) t(A[rev(1:3),,x])) [[1]] [,1] [,2] [,3] [1,] g d a [2,] h e b [3,] i f c [[2]] [,1] [,2] [,3] [1,] p m j [2,] q n k [3,] r o l Is this what you are looking for? I hope this helps. Chel Hee Lee On 02/05/2015 03:17 PM, Karim Mezhoud wrote: Dear aal, Is there a way to rotate array or a cube of matrices by Y axis? MatLab example: A = cat(3,{'a' 'b' 'c';'d' 'e' 'f';'g' 'h' 'i'},{'j' 'k' 'l';'m' 'n' 'o';'p' 'q' 'r'}) A(:,:,1) = 'a''b''c' 'd''e''f' 'g''h''i' A(:,:,2) = 'j''k''l' 'm''n''o' 'p''q''r' Rotate the cell array by 270 degrees. B = rot90(A,3) B(:,:,1) = 'g''d''a' 'h''e''b' 'i''f''c' B(:,:,2) = 'p''m''j' 'q''n''k' 'r''o''l' karim [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R problem
ex - strptime(c(2014-01-30 15:39:46, 2012-04-20 14:49:02), format=%Y-%m-%d %H:%M:%S) ex [1] 2014-01-30 15:39:46 CST 2012-04-20 14:49:02 CST format(ex, format=%a) [1] Thu Fri format(ex, format=%A) [1] Thursday Friday weekdays(ex) [1] Thursday Friday Is this what you are looking for? I hope this helps. Chel Hee Lee On 1/31/2015 3:06 AM, Camilla Timo wrote: Hi there, I have a problem, i have a dataset, in which there are time series from 2010- to 2014, like this: -2014-01-30 15:39:46 -2012-04-20 14:49:02 And so on . I want to have a situation in which there are days of week expressed in word, because I have to calculate days of week and on the other hand week end. For example, i want : -2014- 01 monday 15:39:46 -2012-04 saturday 14:49:02 Thanks guys Inviato da iPhone __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] pch size in a legend
Hi Ahmed, It also works with the following working environment: R.version _ platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 status major 3 minor 1.2 year 2014 month 10 day31 svn rev66913 language R version.string R version 3.1.2 (2014-10-31) nickname Pumpkin Helmet unlist(.Platform) OS.type file.sep dynlib.ext GUI endian pkgType windows / .dll Rgui little win.binary path.sep r_arch ;x64 Chel Hee Lee On 1/30/2015 9:55 PM, Jim Lemon wrote: Hi Ahmed, Hmmm, this seems to work for me (R-3.1.2, Linux) legend(0,2100, legend=c(2009,2010,2012,2013,2014), col = 1,cex=1,lty=NA,pch=c(1,2,6,7,8),lwd=2,bty=n,pt.cex=2) Jim On Sat, Jan 31, 2015 at 8:49 AM, Ahmed Attia ahmedati...@gmail.com wrote: Hi R users, I would like to adjust the pch size in a legend without changing the text size, pt.cex does not do the job. R 2.15.2 32 bit. legend(0,2100, legend=c(2009,2010,2012,2013,2014), col = 1,cex=1,lty=NA,pch=c(1,2,6,7,8),lwd=2,bty=n) Thanks Ahmed Attia, Ph.D. Agronomist Soil Scientist Post-Doc Research Associate Texas AM AgriLife Research-Vernon ahmed.at...@ag.tamu.edu Cell phone: 001-979-248-5215 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] quetion about matrix compute
Here is another implementation: b [1] 1 2 3 4 5 c [1] 1 2 1 3 5 4 outer(c,b, ==)*1 [,1] [,2] [,3] [,4] [,5] [1,]10000 [2,]01000 [3,]10000 [4,]00100 [5,]00001 [6,]00010 I hope this helps. Chel Hee Lee On 1/30/2015 11:52 AM, JS Huang wrote: Hi, Here is my implementation. Hope this helps. b [1] 1 2 3 4 5 c [1] 1 2 1 3 5 4 sapply(b,function(x)ifelse(x==c,1,0)) [,1] [,2] [,3] [,4] [,5] [1,]10000 [2,]01000 [3,]10000 [4,]00100 [5,]00001 [6,]00010 -- View this message in context: http://r.789695.n4.nabble.com/quetion-about-matrix-compute-tp4702505p4702532.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lost in plotmath expressions
Why don't try this? nams-c(P2O5 ['%'], D50 [mu*m]) pdf(test.pdf) for(i in 1:2) + plot(1,1,xlab=parse(text=(bquote(.(nams[i]) dev.off() Is this what you are looking for? I hope this helps. On 1/30/2015 7:54 AM, PIKAL Petr wrote: Thanks So the key is to put expression(s) directly into pool of annotations. I should think about it myself, stupid me. I normally use paste but your constructions are much more readable. thanks again. Petr -Original Message- From: Richard M. Heiberger [mailto:r...@temple.edu] Sent: Friday, January 30, 2015 2:30 PM To: PIKAL Petr Cc: r-help@r-project.org Subject: Re: [R] lost in plotmath expressions I would do this names - c(expression(D[50]~mu*m), expression(P[2]*O[5]*%)) for (i in 1:2) plot(1, 1, xlab=names[i]) On Fri, Jan 30, 2015 at 7:33 AM, PIKAL Petr petr.pi...@precheza.cz wrote: Dear all I usually find out how I can use expressions in picture annotationmyself :-) plot(1,1, xlab=expression(paste(D50 [, mu,m]))) However when I want to use this programmatically I am rather lost. Is there anybody who can shed a light on such annotation? nams-c(P2O5 [%], D50 [mum]) pdf(test.pdf) for (i in 1:2) plot(1, 1, xlab=nams[i]) dev.off() I want to use text with the greek letter. Best regards Petr Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům. Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému. Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat. Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu. V případě, že je tento e-mail součástí obchodního jednání: - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu. - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou. - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech. - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient. __ 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. Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům. Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému. Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat. Odesílatel e-mailu
Re: [R] Repeat elements of character vector
paste(rep(v1, each=3), 1:3, sep=_) [1] a_1 a_2 a_3 b_1 b_2 b_3 c_1 c_2 c_3 Is this what you are looking for? I hope this helps. Chel Hee Lee On 1/30/2015 7:34 AM, Knut Hansen wrote: I have a vector of several character elements: v1 - c(a, b, c) I want each of these elements to be repeated n times and the number of the repetition added as part of the element text, hence rep() will not work. For n=3 the result would be: v2 - c(a_1, a_2, a_3, b_1, b_2, b_3, c_1, c_2, c_3) Knut Hansen knut.han...@uit.no __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Passing a Data Frame Name as a Variable in a Function
I like Jeff's comments on the previous post. Regarding Alan's question, please see the following example. df.1 - data.frame(v1=1:5, v2=letters[1:5]) df.2 - data.frame(v1=LETTERS[1:3], v2=11:13) DFName - ls(pattern = glob2rx(df.*))[1] DFName [1] df.1 length(DFName[,1]) Error in DFName[, 1] : incorrect number of dimensions 'DFName' is a character vector of length 1 (it is neither a matrix nor a data frame). In this case, you may try 'eval()' as below: eval(parse(text=DFName)) v1 v2 1 1 a 2 2 b 3 3 c 4 4 d 5 5 e eval(parse(text=DFName))[,1] [1] 1 2 3 4 5 length(eval(parse(text=DFName))[,1]) [1] 5 Is this what you are looking for? I hope this helps. Chel Hee Lee On 1/29/2015 12:34 AM, Jeff Newmiller wrote: This approach is fraught with dangers. I recommend that you put all of those data frames into a list and have your function accept the list and the name and use the list indexing operator mylist[[DFName]] to refer to it. Having functions that go fishing around in the global environment will be hard to maintain at best, and buggy at worst. That said, I usually work with all of my data frames combined as one and use the plyr, dplyr, or data.table packages to apply my algorithms to each group of rows identified by a character or factor column. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On January 28, 2015 5:37:34 PM PST, Alan Yong alany...@caltech.edu wrote: Dear R-help, I have df.1001 as a data frame with rows columns of values. I also have other data frames named similarly, i.e., df.*. I used DFName from: DFName - ls(pattern = glob2rx(df.*))[1] would like to pass on DFName to another function, like: length(DFName[, 1]) however, when I run: length(DFName[, 1]) Error in DFName[, 1] : incorrect number of dimensions and length(df.1001[, 1]) [1] 104 do not provide the same expected answer. How can I successfully pass the data frame name of df.1001 as a variable named DFName in a function? Thanks, Alan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] problem with conditional column sums
Or, you can also do the same job using 'colSums()' as shown in the below: colSums(status==I) 2010 2011 2012 344 I hope this helps. Chel Hee Lee On 1/28/2015 7:31 PM, JSHuang wrote: Hi, I think you need quotation around I like the following: status 2010 2011 2012 1 AAA 2 AII 3 AAA 4 UUU 5 AAA 6 III 7 UII 8 AUA 9 IAU 10III apply(start,2,function(x) {sum(x==I,na.rm=TRUE)}) X2010 X2011 X2012 3 4 4 -- View this message in context: http://r.789695.n4.nabble.com/problem-with-conditional-column-sums-tp4702426p4702434.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Paste every two columns together
Hi Bert! yes, you are VERY correct!!! Why am I making this simple thing so complicated??? ;) Thank you so much for your nice lesson! Chel Hee Lee On 01/28/2015 09:59 PM, Bert Gunter wrote: eek! Chel Hee,anything that complicated should engender fear and trembling. Much simpler and more efficient (if I understand correctly) i - seq.int(1L,length(ID1),by = 2L) paste0(ID1[i],ID1[i+1]) That gives a vector of paired letters. If you want a single character string, just collapse with a (space): paste0(ID1[i],ID1[i+1],collapse= ) Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. Clifford Stoll On Wed, Jan 28, 2015 at 7:41 PM, Chel Hee Lee chl...@mail.usask.ca wrote: I am using just the first row of your data (i.e. ID1). ID1 - c(A, A, T, G, C, T, G, C, G, T, C, G, T, A) do.call(c,lapply(tapply(ID1, gl(7,2), c), paste, collapse=)) 1234567 AA TG CT GC GT CG TA Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/28/2015 05:55 PM, Kate Ignatius wrote: I have genetic data as follows (simple example, actual data is much larger): comb = ID1 A A T G C T G C G T C G T A ID2 G C T G C C T G C T G T T T And I wish to get an output like this: ID1 AA TG CT GC GT CG TA ID2 GC TG CC TG CT GT TT That is, paste every two columns together. I have this code, but I get the error: Error in seq.default(2, nchar(x), 2) : 'to' must be of length 1 conc - function(x) { s - seq(2, nchar(x), 2) paste0(x[s], x[s+1]) } combn - as.data.frame(lapply(comb, conc), stringsAsFactors=FALSE) Thanks in advance! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] adding an additional column for preserving uniqueness
I like the way presented by William Dunlap in the previous post. You may also try this: dat1$item - Reduce(c,lapply(table(dat1$Date), seq_len)) dat2$item - Reduce(c,lapply(table(dat2$Date), seq_len)) dat1 Date ConcAve item 1 2009-07-08 71 2 2009-08-26 11 3 2009-08-26 22 4 2009-09-15 21 5 2009-10-14 21 6 2009-10-14 22 7 2009-10-16 1011 8 2009-10-16 932 9 2009-11-18 41 10 2009-11-18 32 11 2010-01-04 41 dat2 Date ConcAve item 1 2009-08-26 4.84e-051 2 2009-09-15 4.58e-051 3 2009-10-14 3.86e-051 4 2009-10-14 3.55e-052 5 2009-10-16 3.07e-051 6 2009-10-16 2.35e-052 7 2009-11-18 2.00e-051 8 2009-11-18 1.96e-052 9 2010-01-04 1.52e-051 10 2010-01-04 1.53e-052 11 2010-02-10 2.23e-051 I hope this helps. Chel Hee Lee On 01/28/2015 07:38 PM, William Dunlap wrote: with(dat1, ave(integer(length(Date)), Date, FUN=seq_along)) [1] 1 1 2 1 1 2 1 2 1 2 1 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Jan 28, 2015 at 4:54 PM, Morway, Eric emor...@usgs.gov wrote: The two datasets below are excerpts from much larger datasets. Note that there are duplicate dates in both dat1 and dat2, e.g., 2009-10-14. dat1 - read.table(textConnection(Date ConcAve 2009-07-08 7 2009-08-26 1 2009-08-26 2 2009-09-15 2 2009-10-14 2 2009-10-14 2 2009-10-16 101 2009-10-16 93 2009-11-18 4 2009-11-18 3 2010-01-04 4),header=T) closeAllConnections() dat2 - read.table(textConnection(Date ConcAve 2009-08-26 4.84e-05 2009-09-15 4.58e-05 2009-10-14 3.86e-05 2009-10-14 3.55e-05 2009-10-16 3.07e-05 2009-10-16 2.35e-05 2009-11-18 2.00e-05 2009-11-18 1.96e-05 2010-01-04 1.52e-05 2010-01-04 1.53e-05 2010-02-10 2.23e-05),header=T) closeAllConnections() I'm seeking an R operation that will append a third column to both data.frame's such that it makes these duplicates unique when I run merge(). The desired result for dat1 would be: Date ConcAve item 2009-07-08 7 1 2009-08-26 1 1 2009-08-26 2 2 2009-09-15 2 1 2009-10-14 2 1 2009-10-14 2 2 2009-10-16 101 1 2009-10-16 93 2 2009-11-18 4 1 2009-11-18 3 2 2010-01-04 4 1 this way, I don't get this: merge(dat1, dat2, by=Date) # Date ConcAve.x ConcAve.y #1 2009-08-26 1 4.84e-05 #2 2009-08-26 2 4.84e-05 #3 2009-09-15 2 4.58e-05 #4 2009-10-14 2 3.55e-05 #5 2009-10-14 2 3.86e-05 #6 2009-10-14 2 3.55e-05 #7 2009-10-14 2 3.86e-05 #8 2009-10-16 101 3.07e-05 #9 2009-10-16 101 2.35e-05 #10 2009-10-1693 3.07e-05 #11 2009-10-1693 2.35e-05 #12 2009-11-18 4 1.96e-05 #13 2009-11-18 4 2.00e-05 #14 2009-11-18 3 1.96e-05 #15 2009-11-18 3 2.00e-05 #16 2010-01-04 4 1.52e-05 #17 2010-01-04 4 1.53e-05 With the new column, which I've inserted manually in this small example, I instead get the merge result below, which is what I'm after for the larger problem: dat3 - read.table(textConnection(Date ConcAve item 2009-07-08 7 1 2009-08-26 1 1 2009-08-26 2 2 2009-09-15 2 1 2009-10-14 2 1 2009-10-14 2 2 2009-10-16 101 1 2009-10-16 93 2 2009-11-18 4 1 2009-11-18 3 2 2010-01-04 4 1),header=T) closeAllConnections() dat4 - read.table(textConnection(Date ConcAve item 2009-08-26 4.84e-05 1 2009-09-15 4.58e-05 1 2009-10-14 3.86e-05 1 2009-10-14 3.55e-05 2 2009-10-16 3.07e-05 1 2009-10-16 2.35e-05 2 2009-11-18 2.00e-05 1 2009-11-18 1.96e-05 2 2010-01-04 1.52e-05 1 2010-01-04 1.53e-05 2 2010-02-10 2.23e-05 1),header=T) closeAllConnections() merge(dat3, dat4, by=c(Date,item)) #Date item ConcAve.x ConcAve.y #1 2009-08-261 1 4.84e-05 #2 2009-09-151 2 4.58e-05 #3 2009-10-141 2 3.86e-05 #4 2009-10-142 2 3.55e-05 #5 2009-10-161 101 3.07e-05 #6 2009-10-16293 2.35e-05 #7 2009-11-181 4 2.00e-05 #8 2009-11-182 3 1.96e-05 #9 2010-01-041 4 1.52e-05 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R
Re: [R] Paste every two columns together
I am using just the first row of your data (i.e. ID1). ID1 - c(A, A, T, G, C, T, G, C, G, T, C, G, T, A) do.call(c,lapply(tapply(ID1, gl(7,2), c), paste, collapse=)) 1234567 AA TG CT GC GT CG TA Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/28/2015 05:55 PM, Kate Ignatius wrote: I have genetic data as follows (simple example, actual data is much larger): comb = ID1 A A T G C T G C G T C G T A ID2 G C T G C C T G C T G T T T And I wish to get an output like this: ID1 AA TG CT GC GT CG TA ID2 GC TG CC TG CT GT TT That is, paste every two columns together. I have this code, but I get the error: Error in seq.default(2, nchar(x), 2) : 'to' must be of length 1 conc - function(x) { s - seq(2, nchar(x), 2) paste0(x[s], x[s+1]) } combn - as.data.frame(lapply(comb, conc), stringsAsFactors=FALSE) Thanks in advance! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] get latest dates for different people in a dataset
do.call(rbind, lapply(split(data, data$Name), function(x) x[order(x$CheckInDate),][nrow(x),])) Name CheckInDate Temp John John 2014-04-01 99.0 Mary Mary 2014-03-01 98.1 Sam Sam 2014-04-01 97.5 Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/23/2015 05:43 PM, Tan, Richard wrote: Hi, Can someone help for a R question? I have a data set like: NameCheckInDate Temp John 1/3/2014 97 Mary 1/3/2014 98.1 Sam 1/4/2014 97.5 John 1/4/2014 99 I'd like to return a dataset that for each Name, get the row that is the latest CheckInDate for that person. For the example above it would be NameCheckInDate Temp John 1/4/2014 99 Mary 1/3/2014 98.1 Sam 1/4/2014 97.5 Thank you for your help! Richard [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum of grouped elements of vector
Here is some examples using functions 'tapply()' as suggested by Bert Gunter in the previous post, 'aggregate()', and 'xtabs()'. Note that 'grp.id' means 'group indicator'. a - c(1,2,3,4,5,6,7,8) new1 - c(1+2, 3, 4+5+6, 7+8) new1 [1] 3 3 15 15 grp.id - c(1,1, 2, 3,3,3, 4,4) tapply(X=a, INDEX=grp.id, FUN=sum) 1 2 3 4 3 3 15 15 aggregate(x=a, by=list(grp.id), FUN=sum) Group.1 x 1 1 3 2 2 3 3 3 15 4 4 15 xtabs(formula=a~grp.id) grp.id 1 2 3 4 3 3 15 15 I hope this helps. Chel Hee Lee On 1/23/2015 3:32 AM, Bert Gunter wrote: If Jim's answer is not what you want, then I would say it is because your question is too vague to be answered. In particular, how do you specify the elements of the vector that are to be summed to create the new vectors? ?tapply might then be relevant here, but that's just a guess. -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. Clifford Stoll On Fri, Jan 23, 2015 at 12:45 AM, Kathryn Lord kathryn.lord2...@gmail.com wrote: Dear R users, I have a quick quesiton. Here is a vector a. a- c(1,2,3,4,5,6,7,8). (In fact, I have a huge vector.) With a, I'd like to create new vectors, for example, new1 = (1+2, 3, 4+5+6, 7+8) new2 = (1, 2+3+4+5+6+7, 8) new3 = (1+2+3+4+5+6+7, 8) How could I make the above vectors using R? Any suggestion will be greatly appreciated. Best, Kathryn Lord [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] Counting Words
x - c(hola mundo mundo); table(unlist(strsplit(x, ))) hola mundo 1 2 Is this what you are looking for? I hope this helps. Chel Hee Lee On 1/22/2015 8:25 AM, bgnumis bgnum wrote: Hi all, I want to cout the different words in a text. You see if the text is: hola mundo mundo the program will count: hola 1 mundo 2 Is posible that Cran r have a similar function? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] subscript out of bounds
I hope this toy example gives an idea to understand the problems that you are facing now. Please see the below: # 1. Create an empty list A - list() A list() # 2. Add the first component (vector with two elements). A[[1]] - c(2,6) A [[1]] [1] 2 6 # 3. Now, add the third component (vector with three elements). # I did not add the second component INTENTIONALLY. A[[3]] - c(1,3,2) A [[1]] [1] 2 6 [[2]] NULL [[3]] [1] 1 3 2 # I see the second element has NULL value. # You can apply 'is.null()' to this second component. is.null(A[[2]]) [1] TRUE # However, you will see the error as below if 'is.null()' is used for the fourth component. is.null(A[[4]]) Error in A[[4]] : subscript out of bounds # Why? It is because the list 'A' has only three components. length(A) [1] 3 I hope this helps. I would appreciate if you DO READ the posting guide. Chel Hee Lee On 1/20/2015 9:30 AM, Ragia Ibrahim wrote: Hello, kindly , how to catch this Error Error in A[[i]] : subscript out of bounds and check that the list is empty is.null( A[[i]] ) do no twork thanks in advance R.I [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] add a list name into the list content in a new output
Hi Joshua, You may use 'do.call()'. Please see the output in below: result - lapply(names(op), function(x){ + col1 - x + col2 - row.names(op[[x]]) + mat - op[[x]] + row.names(mat) - NULL + rval - cbind(col1, col2, mat) + names(rval) - c(trait, locus, names(mat)) + rval + }) result [[1]] traitlocus chr pos ci.low ci.high lod 1bp c7.loc45 7 47.7 36.7156.7 6.11 2bp c15.loc8 15 12.0 3.9622.8 5.29 [[2]] trait locus chr pos ci.low ci.high lod 1hr c2.loc54 2 59.8 14.887.8 4.19 2hr D15MIT184 15 22.8 12.036.0 3.15 [[3]] trait locus chr pos ci.low ci.high lod 1bw c15.loc16 15 20 11 30 6.75 [[4]] trait locus chr pos ci.low ci.high lod 1 heart_wt c12.loc49 12 51.2 28.262.2 3.65 do.call(rbind, result) trait locus chr pos ci.low ci.high lod 1 bp c7.loc45 7 47.7 36.7156.7 6.11 2 bp c15.loc8 15 12.0 3.9622.8 5.29 3 hr c2.loc54 2 59.8 14.8087.8 4.19 4 hr D15MIT184 15 22.8 12.0036.0 3.15 5 bw c15.loc16 15 20.0 11.0030.0 6.75 6 heart_wt c12.loc49 12 51.2 28.2062.2 3.65 Is this what you are looking for? I hope this helps. Chel Hee Lee On 1/20/2015 9:23 AM, Shuhua Zhan wrote: Hi Chel, Thank you very much for your help! I'm sorry I did not post my wanted output correctly. I only want the colnames of the data frame occur once as a table: trait locus chr pos ci.low ci.high lod bp c7.loc45 7 47.7 36.7156.7 6.11 bp c15.loc8 15 12.0 3.9622.8 5.29 hr c2.loc542 59.8 14.887.8 4.19 hr D15MIT184 15 22.8 12.036.0 3.15 bw c15.loc16 15 20 11 30 6.75 heart_wt c12.loc49 12 51.2 28.262.2 3.65 How to add command to your script to scape those colnames? Thanks again, Joshua - Original Message - From: Chel Hee Lee chl...@mail.usask.ca To: Shuhua Zhan sz...@uoguelph.ca, r-help r-help@r-project.org Sent: Monday, January 19, 2015 10:44:23 PM Subject: Re: [R] add a list name into the list content in a new output I am just using the first two components of your output. op $bp chr pos ci.low ci.high lod c7.loc45 7 47.7 36.7156.7 6.11 c15.loc8 15 12.0 3.9622.8 5.29 $hr chr pos ci.low ci.high lod c2.loc542 59.8 14.887.8 4.19 D15MIT184 15 22.8 12.036.0 3.15 result - lapply(names(op), function(x){ + col1 - x + col2 - row.names(op[[x]]) + mat - op[[x]] + row.names(mat) - NULL + rval - cbind(col1, col2, mat) + names(rval) - c(trait, locus, names(mat)) + rval + }) result [[1]] traitlocus chr pos ci.low ci.high lod 1bp c7.loc45 7 47.7 36.7156.7 6.11 2bp c15.loc8 15 12.0 3.9622.8 5.29 [[2]] trait locus chr pos ci.low ci.high lod 1hr c2.loc54 2 59.8 14.887.8 4.19 2hr D15MIT184 15 22.8 12.036.0 3.15 Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/19/2015 02:14 PM, Shuhua Zhan wrote: Dear All, I'd like to add a list name into the list contents to make a new output. The list is a list of data.frame derived from summary command in Rqtl. I want to add this list name to the data frame with a given column name such as trait and output this entire list as a table tab delimited as below. Here is the list generated by summary command in Rqtl: summary(out.all, threshold=3, format=tabByCol) bp: chr pos ci.low ci.high lod c7.loc45 7 47.7 36.7156.7 6.11 c15.loc8 15 12.0 3.9622.8 5.29 hr: chr pos ci.low ci.high lod c2.loc542 59.8 14.887.8 4.19 D15MIT184 15 22.8 12.036.0 3.15 bw: chr pos ci.low ci.high lod c15.loc16 15 20 11 30 6.75 heart_wt: chr pos ci.low ci.high lod c12.loc49 12 51.2 28.262.2 3.65 The new output I want: trait locus chr pos ci.low ci.high lod bp c7.loc45 7 47.7 36.7156.7 6.11 bp c15.loc8 15 12.0 3.9622.8 5.29 trait locus chr pos ci.low ci.high lod hr c2.loc542 59.8 14.887.8 4.19 hr D15MIT184 15 22.8 12.036.0 3.15 trait locus chr pos ci.low ci.high lod bw c15.loc16 15 20 11 30 6.75 heart_wt locus chr pos ci.low ci.high lod trait c12.loc49 12 51.2 28.262.2 3.65 I appreciate for your help for any suggestions!! Joshua __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Evaluated expression in lattice key
I guess that you may need 'panel.text()' to customize panel function. Please run the following code and see the output. You will see different value of R-squared in each panel. xyplot( y~x|name, data=df, panel = function(x, y, ...) { panel.xyplot(x, y, ...) panel.abline(lm(y~x), col=red) panel.text(1, -1, bquote(R^2 == .(summary(lm(y~x))$r.squared))) }, grid = TRUE ) Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/17/2015 07:08 AM, Naresh Gurbuxani wrote: In a conditional xyplot, I would like to add some numerical results in every panel. Consider below example. df - data.frame(x = rnorm(100), name = A) df - within(df, {y - x + 0.2 * rnorm(100)}) df2 - data.frame(x = rnorm(100), y = rnorm(100), name = B) df - rbind(df, df2) rm(df2) with(df, xyplot(y ~ x | name, data = df, panel = function(x, y, ...){ panel.xyplot(x, y) panel.lmline(x, y, col = grey) }, auto.key = list(corner = c(1,0), x = 0.9, y = 0.1, text = substitute(expression(R^{2} == myval), list(myval = summary(lm(y ~ x))$r.squared) There are two problems with this plot. First, there is only one key. I want two different keys for the two panels. Second, R^2 is for all data. For each panel, I want R^2 calculated using only the data plotted in that panel. Please help. Thanks,Naresh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] add a list name into the list content in a new output
I am just using the first two components of your output. op $bp chr pos ci.low ci.high lod c7.loc45 7 47.7 36.7156.7 6.11 c15.loc8 15 12.0 3.9622.8 5.29 $hr chr pos ci.low ci.high lod c2.loc542 59.8 14.887.8 4.19 D15MIT184 15 22.8 12.036.0 3.15 result - lapply(names(op), function(x){ + col1 - x + col2 - row.names(op[[x]]) + mat - op[[x]] + row.names(mat) - NULL + rval - cbind(col1, col2, mat) + names(rval) - c(trait, locus, names(mat)) + rval + }) result [[1]] traitlocus chr pos ci.low ci.high lod 1bp c7.loc45 7 47.7 36.7156.7 6.11 2bp c15.loc8 15 12.0 3.9622.8 5.29 [[2]] trait locus chr pos ci.low ci.high lod 1hr c2.loc54 2 59.8 14.887.8 4.19 2hr D15MIT184 15 22.8 12.036.0 3.15 Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/19/2015 02:14 PM, Shuhua Zhan wrote: Dear All, I'd like to add a list name into the list contents to make a new output. The list is a list of data.frame derived from summary command in Rqtl. I want to add this list name to the data frame with a given column name such as trait and output this entire list as a table tab delimited as below. Here is the list generated by summary command in Rqtl: summary(out.all, threshold=3, format=tabByCol) bp: chr pos ci.low ci.high lod c7.loc45 7 47.7 36.7156.7 6.11 c15.loc8 15 12.0 3.9622.8 5.29 hr: chr pos ci.low ci.high lod c2.loc542 59.8 14.887.8 4.19 D15MIT184 15 22.8 12.036.0 3.15 bw: chr pos ci.low ci.high lod c15.loc16 15 20 11 30 6.75 heart_wt: chr pos ci.low ci.high lod c12.loc49 12 51.2 28.262.2 3.65 The new output I want: trait locus chr pos ci.low ci.high lod bp c7.loc45 7 47.7 36.7156.7 6.11 bp c15.loc8 15 12.0 3.9622.8 5.29 trait locus chr pos ci.low ci.high lod hr c2.loc542 59.8 14.887.8 4.19 hr D15MIT184 15 22.8 12.036.0 3.15 trait locus chr pos ci.low ci.high lod bw c15.loc16 15 20 11 30 6.75 heart_wt locus chr pos ci.low ci.high lod trait c12.loc49 12 51.2 28.262.2 3.65 I appreciate for your help for any suggestions!! Joshua __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting elements out of list in list in list
Aha! I haven't thought about it. I really like the approach presented by Bert Gunter in the previous post. It is a good lesson. I made my previous code a little bit better by building a function that pulls out only the desired component. At this time, the names of sublists are changed as below (i.e. the names of 'A', 'B', 'C' in the example given by Rainer M Krug are changed to 'A', 'Aha', 'alpha' here): x1 - list(A = 11, Aha = 21, alpha = 31) x2 - list(A = 12, Aha = 22, alpha = 32) x3 - list(A = 13, Aha = 23, alpha = 33) x4 - list(A = 14, Aha = 24, alpha = 34) y1 - list(x1 = x1, x2 = x2) y2 - list(x3 = x3, x4 = x4) x - list(f1 = y1, f2 = y2) extr.1 - function(x, name){ + xl - unlist(x) + depth - sum(unlist(strsplit(names(xl)[1], split=)) == .) + 1 + xl[grep(paste(^,name,$, sep=), unlist(strsplit(names(xl), ., fixed=TRUE)))/depth] + } extr.1(x=x, name=alpha) f1.x1.alpha f1.x2.alpha f2.x3.alpha f2.x4.alpha 31 32 33 34 extr.1(x=x, name=A) f1.x1.A f1.x2.A f2.x3.A f2.x4.A 11 12 13 14 extr.1(x=x, name=a) named numeric(0) extr.1(x=x, name=Aha) f1.x1.Aha f1.x2.Aha f2.x3.Aha f2.x4.Aha 21222324 Hm this function 'extr.1()' seems to be (much) slower than the function 'extr()'. Chel Hee Lee On 01/16/2015 11:34 AM, Bert Gunter wrote: Chee Hee's approach is both simpler and almost surely more efficient, but I wanted to show another that walks the tree (i.e. the list) directly using recursion at the R level to pull out the desired components. This is in keeping with R's functional programming paradigm and avoids the use of regular expressions to extract the desired components from the unlist() version. extr - function(x,nm){ if(is.recursive(x)){ wh - names(x) %in% nm c(x[wh],lapply(x[!wh],extr,nm=nm) ) } else NULL } ## The return value contains a bunch of NULLs; so use unlist() to remove them unlist(extr(x,A)) f1.x1.A f1.x2.A f2.x3.A f2.x4.A 11 12 13 14 I would welcome any possibly slicker versions of the above. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. Clifford Stoll On Fri, Jan 16, 2015 at 7:23 AM, Chel Hee Lee chl...@mail.usask.ca wrote: This approach may not be fancy as what you are looking for. xl - unlist(x) xl[grep(A, names(xl))] f1.x1.A f1.x2.A f2.x3.A f2.x4.A 11 12 13 14 I hope this helps. Chel Hee Lee On 01/16/2015 04:40 AM, Rainer M Krug wrote: Hi Consider the following variable: --8---cut here---start-8--- x1 - list( A = 11, B = 21, C = 31 ) x2 - list( A = 12, B = 22, C = 32 ) x3 - list( A = 13, B = 23, C = 33 ) x4 - list( A = 14, B = 24, C = 34 ) y1 - list( x1 = x1, x2 = x2 ) y2 - list( x3 = x3, x4 = x4 ) x - list( f1 = y1, f2 = y2 ) --8---cut here---end---8--- To extract all fields named A from y1, I can do , | sapply(y1, [[, A) | x1 x2 | 11 12 ` But how can I do the same for x? I could put an sapply into an sapply, but this would be less then elegant. Is there an easier way of doing this? Thanks, Rainer __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Extracting elements out of list in list in list
This approach may not be fancy as what you are looking for. xl - unlist(x) xl[grep(A, names(xl))] f1.x1.A f1.x2.A f2.x3.A f2.x4.A 11 12 13 14 I hope this helps. Chel Hee Lee On 01/16/2015 04:40 AM, Rainer M Krug wrote: Hi Consider the following variable: --8---cut here---start-8--- x1 - list( A = 11, B = 21, C = 31 ) x2 - list( A = 12, B = 22, C = 32 ) x3 - list( A = 13, B = 23, C = 33 ) x4 - list( A = 14, B = 24, C = 34 ) y1 - list( x1 = x1, x2 = x2 ) y2 - list( x3 = x3, x4 = x4 ) x - list( f1 = y1, f2 = y2 ) --8---cut here---end---8--- To extract all fields named A from y1, I can do , | sapply(y1, [[, A) | x1 x2 | 11 12 ` But how can I do the same for x? I could put an sapply into an sapply, but this would be less then elegant. Is there an easier way of doing this? Thanks, Rainer __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Evaluating a formula
You may use 'eval()' with 'parse()' if you wish to use 'formula()' as below: a - params[[1]] b - params[[2]] eval(parse(text=func1)) [1] 5.00 5.652893 6.338843 7.057851 7.809917 8.595041 [7] 9.413223 10.264463 11.148760 12.066116 13.016529 14.00 [13] 15.016529 16.066116 17.148760 18.264463 19.413223 20.595041 [19] 21.809917 23.057851 24.338843 25.652893 27.00 28.380165 [25] 29.793388 31.239669 32.719008 34.231405 35.776860 37.355372 [31] 38.966942 40.611570 42.289256 44.00 45.743802 47.520661 [37] 49.330579 51.173554 53.049587 54.958678 56.900826 58.876033 [43] 60.884298 62.925620 65.00 67.107438 69.247934 71.421488 [49] 73.628099 75.867769 78.140496 80.446281 82.785124 85.157025 [55] 87.561983 90.00 92.471074 94.975207 97.512397 100.082645 [61] 102.685950 105.322314 107.991736 110.694215 113.429752 116.198347 [67] 119.00 121.834711 124.702479 127.603306 130.537190 133.504132 [73] 136.504132 139.537190 142.603306 145.702479 148.834711 152.00 [79] 155.198347 158.429752 161.694215 164.991736 168.322314 171.685950 [85] 175.082645 178.512397 181.975207 185.471074 189.00 192.561983 [91] 196.157025 199.785124 203.446281 207.140496 210.867769 214.628099 [97] 218.421488 222.247934 226.107438 230.00 Or, you can define your own function as below: fn - function(x, a, b)a*x^2 + b*x fn(x=x, a=params[[1]], b=params[[2]]) [1] 5.00 5.652893 6.338843 7.057851 7.809917 8.595041 [7] 9.413223 10.264463 11.148760 12.066116 13.016529 14.00 [13] 15.016529 16.066116 17.148760 18.264463 19.413223 20.595041 [19] 21.809917 23.057851 24.338843 25.652893 27.00 28.380165 [25] 29.793388 31.239669 32.719008 34.231405 35.776860 37.355372 [31] 38.966942 40.611570 42.289256 44.00 45.743802 47.520661 [37] 49.330579 51.173554 53.049587 54.958678 56.900826 58.876033 [43] 60.884298 62.925620 65.00 67.107438 69.247934 71.421488 [49] 73.628099 75.867769 78.140496 80.446281 82.785124 85.157025 [55] 87.561983 90.00 92.471074 94.975207 97.512397 100.082645 [61] 102.685950 105.322314 107.991736 110.694215 113.429752 116.198347 [67] 119.00 121.834711 124.702479 127.603306 130.537190 133.504132 [73] 136.504132 139.537190 142.603306 145.702479 148.834711 152.00 [79] 155.198347 158.429752 161.694215 164.991736 168.322314 171.685950 [85] 175.082645 178.512397 181.975207 185.471074 189.00 192.561983 [91] 196.157025 199.785124 203.446281 207.140496 210.867769 214.628099 [97] 218.421488 222.247934 226.107438 230.00 Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/16/2015 02:16 AM, philippe massicotte wrote: Hi all. How we evaluate a formula in R? Ex.: params - list(a = 2, b = 3) x - seq(1,10, length.out = 100) func1 - as.formula(y ~ a*x^2 + b*x) ##How to evaluate func1 using x and the params list ??? Thank you in advance, Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Change of locale
Thank you so much. Your explanation is very clear and helpful to understand. Thank you, again. Chel Hee Lee On 1/12/2015 5:56 AM, Prof Brian Ripley wrote: You don't want to change the locale, rather the message language. That is not a locale, and e.g. LANGUAGE=en is the correct form. See http://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Localization-of-messages for what may be possible during a session: nothing is guaranteed. Documented behaviour is never a bug: in this case you are using OS services and it depends on the OS (and as the manual says, on precisely what versions of the support software the OS is using). I see a Error: object 'a' not found Sys.setlocale(LC_MESSAGES, zh_CN.UTF-8) [1] zh_CN.UTF-8 a 错误: 找不到对象'a' Sys.setlocale(LC_MESSAGES, en_GB.UTF-8) [1] en_GB.UTF-8 a Error: object 'a' not found on Fedora 20. On 12/01/2015 06:19, Chel Hee Lee wrote: Could anyone kindly guide me how to change locale? Any advice would be greatly appreciated. What I am trying to do is to see if messages are correctly in a given locale. The environment variables are: sessionInfo() R version 3.1.2 (2014-10-31) Platform: x86_64-pc-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=en_CA.UTF-8 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 * Since I do not create any objects yet, the following message must be shown when typing the alphabet 'a'. a Error: object 'a' not found Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 en_CA:en_US:en Sys.getlocale(LC_MESSAGES) [1] en_CA.UTF-8 I am happy with this result. Now, I'd like to see messages in Chineses. Sys.setlocale(LC_MESSAGES, zh_CN.UTF-8) [1] zh_CN.UTF-8 a Error: object 'a' not found The message is still shown in English; thus, I am changing the value of 'LANGUAGE'. Sys.setenv(LANGUAGE=zh_CN.UTF-8) a 错误: 找不到对象'a' Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 zh_CN.UTF-8 Sys.getlocale(LC_MESSAGES) [1] zh_CN.UTF-8 Now, I'd like to use messages in English again. At this time, I changed the value of LANGUAGE rather than LC_MESSAGES. Sys.setenv(LANGUAGE=en_CA.UTF-8) a 错误: 找不到对象'a' I still see this message in Chinese so that I change 'LC_MESSAGES'. Sys.setlocale(LC_MESSAGES, en_CA.UTF-8) [1] en_CA.UTF-8 a Error: object 'a' not found Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 en_CA.UTF-8 Sys.getlocale(LC_MESSAGES) [1] en_CA.UTF-8 Thus, should I set the same value on both 'LANGUAGE' and 'LC_MESSAGES' in order to change messages in a given locale? However, it is questionable. Please see the following example (messages in Japanese): Sys.setenv(LANGUAGE=ja_JP.UTF-8) a エラー: オブジェクト 'a' がありません Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 ja_JP.UTF-8 Sys.getlocale(LC_MESSAGES) [1] en_CA.UTF-8 Sys.setenv(LANGUAGE=en_CA.UTF-8) a エラー: オブジェクト 'a' がありません Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 en_CA.UTF-8 Sys.getlocale(LC_MESSAGES) [1] en_CA.UTF-8 a エラー: オブジェクト 'a' がありません Is this a bug? Any advice would be greatly appreciated. Chel Hee Lee __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Change of locale
Could anyone kindly guide me how to change locale? Any advice would be greatly appreciated. What I am trying to do is to see if messages are correctly in a given locale. The environment variables are: sessionInfo() R version 3.1.2 (2014-10-31) Platform: x86_64-pc-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=en_CA.UTF-8 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 * Since I do not create any objects yet, the following message must be shown when typing the alphabet 'a'. a Error: object 'a' not found Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 en_CA:en_US:en Sys.getlocale(LC_MESSAGES) [1] en_CA.UTF-8 I am happy with this result. Now, I'd like to see messages in Chineses. Sys.setlocale(LC_MESSAGES, zh_CN.utf8) [1] zh_CN.utf8 a Error: object 'a' not found The message is still shown in English; thus, I am changing the value of 'LANGUAGE'. Sys.setenv(LANGUAGE=zh_CN.utf8) a 错误: 找不到对象'a' Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 zh_CN.utf8 Sys.getlocale(LC_MESSAGES) [1] zh_CN.utf8 Now, I'd like to use messages in English again. At this time, I changed the value of LANGUAGE rather than LC_MESSAGES. Sys.setenv(LANGUAGE=en_CA.utf8) a 错误: 找不到对象'a' I still see this message in Chinese so that I change 'LC_MESSAGES'. Sys.setlocale(LC_MESSAGES, en_CA.utf8) [1] en_CA.utf8 a Error: object 'a' not found Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 en_CA.utf8 Sys.getlocale(LC_MESSAGES) [1] en_CA.utf8 Thus, should I set the same value on both 'LANGUAGE' and 'LC_MESSAGES' in order to change messages in a given locale? However, it is questionable. Please see the following example (messages in Japanese): Sys.setenv(LANGUAGE=ja_JP.utf8) a エラー: オブジェクト 'a' がありません Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 ja_JP.utf8 Sys.getlocale(LC_MESSAGES) [1] en_CA.utf8 Sys.setenv(LANGUAGE=en_CA.utf8) a エラー: オブジェクト 'a' がありません Sys.getenv()[c(LANG, LANGUAGE)] LANG LANGUAGE en_CA.UTF-8 en_CA.utf8 Sys.getlocale(LC_MESSAGES) [1] en_CA.utf8 a エラー: オブジェクト 'a' がありません Is this a bug? Any advice would be greatly appreciated. Chel Hee Lee __ 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] number of individuals where X=0 during all periods (longitudinal data)
tmp - split(Test, Test$ID) # number of subjects with X=0 (all periods) x - lapply(tmp, function(x) all(x$X ==0)) length(x[unlist(x)]) [1] 2 # number of subjects with X=0 (at least three weeks) x - lapply(tmp, function(x) sum(x$X==0)=3) length(x[unlist(x)]) [1] 1 Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/22/2014 7:45 AM, najuzz wrote: #Hi guys, #I would like to count the number of individuals that receive X=0 troughout their observational period. #example dataset: ID-c(1,1,1,1,2,2,3,3,3) X-c(0,1,2,1,0,0,0,0,0) Time-c(1,2,3,4,1,2,1,2,3) Test-data.frame(ID,X,Time) # Individuals 2 and 3 have x=0 during all their periods. The count should hence equal to two. I simply have # no clue how R could solve this for me. As an addon, I would also like to know the number of individuals #that report X=0 during all periods plus have at least 3 weeks of observations. The answer would be one in #this sample datset. #Thank you -- View this message in context: http://r.789695.n4.nabble.com/number-of-individuals-where-X-0-during-all-periods-longitudinal-data-tp4701023.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 6 regions around a point
You may try this: get.coords.circle - function(x0, y0, r, len, rot){ + by - seq(from=-pi, to=pi, length.out=len) + x - r*cos(by+rot) + x0 + y - r*sin(by+rot) + y0 + coords - cbind(x,y) + coords[!duplicated(coords),] + } xtms - get.coords.circle(x0=2, y0=4, r=2, len=7, rot=0) xtms1 - get.coords.circle(x0=2, y0=4, r=1, len=7, rot=10) plot(xtms, type=n) segments(x0=xtms[1:3,1], y0=xtms[1:3,2], + x=xtms[4:6,1], y=xtms[4:6,2]) text(xtms[c(4,5,6),], labels=paste(line1, 1:3, sep=_)) text(xtms1, labels=paste(S, 1:6, sep=_)) points(x=2, y=4, cex=3) Please see the output. Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/21/2014 01:25 PM, eliza botto wrote: Dear UseRs, A point was plotted by the following command plot(2,4,ylim=c(0,10),xlim=c(0,5)) how to divide the space around the plotted point into six regions each of 60 degree as shown in the Figure 2a) in the following link http://infolab.usc.edu/csci599/Fall2007/papers/b-2.pdf. Thankyou very much in advance, Eliza. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to make Pivot table with two variables in R?
You are welcome, I am glad that I was able to help. Chel Hee Lee, PhD Biostatistician and Manager Clinical Research Support Unit College of Medicine University of Saskatchewan On 12/20/2014 03:53 AM, Kristi Glover wrote: Thank you Prof. Lee for your code. I am sorry that I noticed that I sent the email in Httml format and realized that it was almost impossible to read it. However, you gave an effort to help me. Now I changed the format. I really appreciated for your help. It seems the code you wrote works for me. Sincerely, KG Date: Sat, 20 Dec 2014 00:09:21 -0600 From: chl...@mail.usask.ca Subject: Re: [R] How to make Pivot table with two variables in R? To: kristi.glo...@hotmail.com; r-help@r-project.org x - dat x$time - as.factor(as.Date(x$time, format=%Y-%B%d)) tmp - split(x, x$tag) tmp1 - do.call(rbind, lapply(tmp, function(x){ + tb - table(x$time) + idx - which(tb0) + tb1 - replace(tb, idx, as.character(x$states)) + })) print(tmp1, quote=FALSE) 2010-05-27 2011-06-27 2011-06-28 2012-06-25 2013-06-21 2014-01-05 2014-07-27 x1 A B B 0 0 0 0 x2 A 0 0 0 0 0 0 x3 0 0 0 D 0 0 0 x4 0 0 0 0 C 0 0 x5 0 0 0 0 B 0 0 x6 0 0 0 0 Out 0 0 x7 0 0 0 C 0 0 Out x8 0 0 0 0 0 B 0 2015-04-07 x1 0 x2 0 x3 0 x4 0 x5 0 x6 A x7 0 x8 0 Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/19/2014 10:45 PM, Kristi Glover wrote: Hi R User, Would you suggest me on how I can build a pivot table using two variables? I want to put text in the table instead of value. I have attached an example data and the type of table (FinalTable) I was looking for. I am looking for your suggestions. ThanksKG=dat-structure(list(tag = structure(c(1L, 1L, 1L, 2L, 3L, 4L, 5L, 6L, 6L, 7L, 7L, 8L), .Label = c(x1, x2, x3, x4, x5, x6, x7, x8), class = factor), time = structure(c(1L, 2L, 3L, 1L, 4L, 5L, 5L, 5L, 8L, 4L, 7L, 6L), .Label = c(2010-May 27, 2011-June 27, 2011-June 28, 2012-June 25, 2013-June 21, 2014-Jan 05, 2014-July 27, 2015-April 07), class = factor), states = structure(c(1L, 2L, 2L, 1L, 4L, 3L, 2L, 5L, 1L, 3L, 5L, 2L), .Label = c(A, B, C, D, Out), class = factor)), .Names = c(tag, time, states), class = data.frame, row.names = c(NA, -12L)) dat###table(dat$tag,dat$time)# it gives value but I want the name of the states in the table instead of value.#For examplefinalTable-structure(list(tag = structure(1:8, .Label = c(x1, x2, x3, x4, x5, x6, x7, x8), class = factor), X2010.May.27 = structure(c(2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0, A), class = factor), X2011.June.27 = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), .Label = c(0, B), class = factor), X2011.June.28 = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0, B), class = factor), X2012.June.25 = structure(c(1L, 1L, 3L, 1L, 1L, 1L, 2L, 1L ), .Label = c(0, C, D), class = factor), X2013.June.21 = structure(c(1L, 1L, 1L, 3L, 2L, 4L, 1L, 1L), .Label = c(0, B, C, Out ), class = factor), X2014.Jan.05 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c(0, B), class = factor), X2014.July.27 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L ), .Label = c(! 0, Out), class = factor), X2015.April.07 = c(0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L)), .Names = c(tag, X2010.May.27, X2011.June.27, X2011.June.28, X2012.June.25, X2013.June.21, X2014.Jan.05, X2014.July.27, X2015.April.07), class = data.frame, row.names = c(NA,-8L)) finalTable #How is it possible to get the finalTable as shown above?Any suggestions? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to make Pivot table with two variables in R?
x - dat x$time - as.factor(as.Date(x$time, format=%Y-%B%d)) tmp - split(x, x$tag) tmp1 - do.call(rbind, lapply(tmp, function(x){ + tb - table(x$time) + idx - which(tb0) + tb1 - replace(tb, idx, as.character(x$states)) + })) print(tmp1, quote=FALSE) 2010-05-27 2011-06-27 2011-06-28 2012-06-25 2013-06-21 2014-01-05 2014-07-27 x1 A B B 0 0 0 0 x2 A 0 0 0 0 0 0 x3 0 0 0 D 0 0 0 x4 0 0 0 0 C 0 0 x5 0 0 0 0 B 0 0 x6 0 0 0 0 Out0 0 x7 0 0 0 C 0 0 Out x8 0 0 0 0 0 B 0 2015-04-07 x1 0 x2 0 x3 0 x4 0 x5 0 x6 A x7 0 x8 0 Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/19/2014 10:45 PM, Kristi Glover wrote: Hi R User, Would you suggest me on how I can build a pivot table using two variables? I want to put text in the table instead of value. I have attached an example data and the type of table (FinalTable) I was looking for. I am looking for your suggestions. ThanksKG=dat-structure(list(tag = structure(c(1L, 1L, 1L, 2L, 3L, 4L, 5L, 6L, 6L, 7L, 7L, 8L), .Label = c(x1, x2, x3, x4, x5, x6, x7, x8), class = factor), time = structure(c(1L, 2L, 3L, 1L, 4L, 5L, 5L, 5L, 8L, 4L, 7L, 6L), .Label = c(2010-May 27, 2011-June 27, 2011-June 28, 2012-June 25, 2013-June 21, 2014-Jan 05, 2014-July 27, 2015-April 07), class = factor), states = structure(c(1L, 2L, 2L, 1L, 4L, 3L, 2L, 5L, 1L, 3L, 5L, 2L), .Label = c(A, B, C, D, Out), class = factor)), .Names = c(tag, time, states), class = data.frame, row.names = c(NA, -12L)) dat###table(dat$tag,dat$time)# it gives value but I want the name of the states in the table instead of value.#For examplefinalTable-structure(list(tag = structure(1:8, .Label = c(x1, x2, x3, x4, x5, x6, x7, x8), class = factor), X2010.May.27 = structure(c(2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0, A), class = factor), X2011.June.27 = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0, B), class = factor), X2011.June.28 = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0, B), class = factor), X2012.June.25 = structure(c(1L, 1L, 3L, 1L, 1L, 1L, 2L, 1L), .Label = c(0, C, D), class = factor), X2013.June.21 = structure(c(1L, 1L, 1L, 3L, 2L, 4L, 1L, 1L), .Label = c(0, B, C, Out), class = factor), X2014.Jan.05 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c(0, B), class = factor), X2014.July.27 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L), .Label = c! (! 0, Out), class = factor), X2015.April.07 = c(0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L)), .Names = c(tag, X2010.May.27, X2011.June.27, X2011.June.28, X2012.June.25, X2013.June.21, X2014.Jan.05, X2014.July.27, X2015.April.07), class = data.frame, row.names = c(NA,-8L)) finalTable #How is it possible to get the finalTable as shown above?Any suggestions? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] combinations between two vectors
I like the example provided by David L. Carlson using the function 'expand.grid()' as shown in the previous email. You may try 'outer()' and 'upper.tri()' instead 'expand.grid()'. Please see the below: x - outer(test, test, paste, sep=,) x [,1] [,2] [,3] [,4] [,5] [1,] 1,1 1,5001 1,10001 1,15001 1,20001 [2,] 5001,1 5001,5001 5001,10001 5001,15001 5001,20001 [3,] 10001,1 10001,5001 10001,10001 10001,15001 10001,20001 [4,] 15001,1 15001,5001 15001,10001 15001,15001 15001,20001 [5,] 20001,1 20001,5001 20001,10001 20001,15001 20001,20001 [6,] 25001,1 25001,5001 25001,10001 25001,15001 25001,20001 [,6] [1,] 1,25001 [2,] 5001,25001 [3,] 10001,25001 [4,] 15001,25001 [5,] 20001,25001 [6,] 25001,25001 x.idx - upper.tri(x, diag=FALSE) x[x.idx] [1] 1,5001 1,10001 5001,10001 1,15001 5001,15001 [6] 10001,15001 1,20001 5001,20001 10001,20001 15001,20001 [11] 1,25001 5001,25001 10001,25001 15001,25001 20001,25001 x.idx2 - upper.tri(x, diag=TRUE) x[x.idx2] [1] 1,1 1,5001 5001,5001 1,10001 5001,10001 [6] 10001,10001 1,15001 5001,15001 10001,15001 15001,15001 [11] 1,20001 5001,20001 10001,20001 15001,20001 20001,20001 [16] 1,25001 5001,25001 10001,25001 15001,25001 20001,25001 [21] 25001,25001 I hope this helps. Thank you, David, for your good lesson. Chel Hee Lee, PhD. Biostatistian and Manager Clinical Research Support Unit College of Medicine University of Saskatchewan On 12/18/2014 9:16 AM, David L Carlson wrote: Depending on what you want, you probably want to start with expand.grid(): # All combinations of test with test pairs1 - expand.grid(test, test) nrow(pairs1) [1] 36 # Exclude cases that differ only in the order of the values # E.g. (1, 5001), but not (5001, 1), also (1, 1), etc are included pairs2 - pairs1[pairs1[,1] = pairs1[,2],] nrow(pairs2) [1] 21 # Same as pairs2 but (1, 1), etc are not included pairs3 - pairs1[pairs1[,1] pairs1[,2],] nrow(pairs3) [1] 15 - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sarah Goslee Sent: Thursday, December 18, 2014 9:06 AM To: Alaios Cc: R-help@r-project.org Subject: Re: [R] combinations between two vectors I can't quite tell what you want: your example output is either unclear to me or mangled by posting in HTML (please don't). Is expand.grid(test, test) what you want, or partway to what you want? Sarah On Thu, Dec 18, 2014 at 9:56 AM, Alaios via R-help r-help@r-project.org wrote: Hi all,I am looking for a function that would give me all the combinations between two vectors.Lets take as example the test-seq(1,3,by=5000) Browse[2] test [1] 1 5001 10001 15001 20001 25001 I want all the combinations between two times the test... I think this is called permutation so a function that could do permutation(test,test)and produce the following 1,11,50011,100011,15001 3,13,5001...25001,20001,25001,25001 is there such a function ? RegardsAlex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Make 2nd col of 2-col df into header row of same df then adjust col1 data display
I like the approach presented by Jeff Newmiller as shown in the previous post (I really like his way). As he suggested, it would be good to start with 'factor' since you have all values of 'Primary.Viol.Type'. You may try to use 'split()' function for creating table that you wish to build. Please see the below (I hope this helps): PViol.Type.Per.Case.Original$Primary.Viol.Type - factor(Primary.Viol.Type, levels=PViol.Type, labels=PViol.Type) tmp - split(PViol.Type.Per.Case.Original, PViol.Type.Per.Case.Original$CaseID) ans - ifelse(do.call(rbind, lapply(tmp, function(x) table(x$Primary.Viol.Type))), 1, NA) ans CaseID BW.BackWages LD.Liquid_Damages MW.Minimum_Wage OT.Overtime 1005317 NA NANA NA NA 1007183 NA NANA NA 1 1008833 NA NANA NA 1 1012281 NA NANA NA NA 1015285 NA NANA NA NA 1015315 NA NANA NA 1 1015322 NA NANA NA NA RK.Records_FLSA V.Poster_Other AS.Age BW.WHMIS_BackWages HS.Hours 1005317 NA NA NA NA1 1007183 NA NA NA NA NA 1008833 NA NA NA NA NA 1012281 NA NA NA NA1 1015285 NA 1 1 NA1 1015315 NA NA NA NA NA 1015322 NA 1 NA NA NA OA.HazOccupationAg ON.HazOccupationNonAg R3.Reg3AgeOccupation 1005317 NANA NA 1007183 NANA NA 1008833 NANA NA 1012281 NANA NA 1015285 NANA NA 1015315 NANA NA 1015322 NANA NA RK.Records_CL V.Other 1005317NA NA 1007183NA NA 1008833NA NA 1012281NA NA 1015285 1 NA 1015315NA NA 1015322NA NA Chel Hee Lee On 12/18/2014 10:02 AM, Jeff Newmiller wrote: No guarantees on best... but one way using base R could be: # Note that CaseID is actually not a valid PViol.Type as you had it PViol.Type - c( BW.BackWages , LD.Liquid_Damages , MW.Minimum_Wage , OT.Overtime , RK.Records_FLSA , V.Poster_Other , AS.Age , BW.WHMIS_BackWages , HS.Hours , OA.HazOccupationAg , ON.HazOccupationNonAg , R3.Reg3AgeOccupation , RK.Records_CL , V.Other ) # explicitly specifying all levels to the factor insures a complete # set of column outputs regardless of what is in the input PViol.Type.Per.Case.Original - data.frame( CaseID , Primary.Viol.Type=factor( Primary.Viol.Type , levels=PViol.Type ) ) tmp - table( PViol.Type.Per.Case.Original ) ans - data.frame( CaseID=rownames( tmp ) , as.data.frame( ifelse( 0==tmp, NA, 1 ) ) ) On Wed, 17 Dec 2014, bcrombie wrote: # I have a dataframe that contains 2 columns: CaseID - c('1015285', '1005317', '1012281', '1015285', '1015285', '1007183', '1008833', '1015315', '1015322', '1015285') Primary.Viol.Type - c('AS.Age', 'HS.Hours', 'HS.Hours', 'HS.Hours', 'RK.Records_CL', 'OT.Overtime', 'OT.Overtime', 'OT.Overtime', 'V.Poster_Other', 'V.Poster_Other') PViol.Type.Per.Case.Original - data.frame(CaseID,Primary.Viol.Type) # CaseID?s can be repeated because there can be up to 14 Primary.Viol.Type?s per CaseID. # I want to transform this dataframe into one that has 15 columns, where the first column is CaseID, and the rest are the 14 primary viol. types. The CaseID column will contain a list of the unique CaseID?s (no replicates) and for each of their rows, there will be a ?1? under a column corresponding to a primary violation type recorded for that CaseID. So, technically, there could be zero to 14 ?1?s? in a CaseID?s row. # For example, the row for CaseID '1015285' above would have a ?1? under ?AS.Age?, ?HS.Hours?, ?RK.Records_CL?, and ?V.Poster_Other?, but have NA under the rest of the columns. PViol.Type - c(CaseID, BW.BackWages, LD.Liquid_Damages, MW.Minimum_Wage
Re: [R] Add encoded special characters (greek characters) as text to plot
Why don't you try this approach if you cannot use 'expression()'? x - c(alpha, beta, gamma, delta) plot(0, type=n) for(i in 1:length(x)) text(x=1, y=i/10, labels=parse(text=x[i])) Please see the output in R. Is this what you are looking for? I hope this helps. I would also appreciate it if you would provide reproducible examples next time. Chel Hee Lee On 12/18/2014 11:48 AM, Jeff Newmiller wrote: Read the posting guide. The solution is likely to depend on your operating system and graphics devices. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On December 18, 2014 8:59:47 AM PST, heyi xiao via R-help r-help@r-project.org wrote: anybody has any hint on this? Subject: Add encoded special characters (greek characters) as text to plot To: r-help@r-project.org Date: Wednesday, December 17, 2014, 9:25 PM Dear all, I read my a character matrix from a text file. Some of them have greek characters. To reserve the special characters, I used stringsAsFactors=F using read.table. I notice that I can’t print these character string using print(), but I can use cat(): print(LC\246\302) [1] LC\246\302 cat(LC\246\302\n) LCβ The problem is when I add text to my output plot like: text(x,y, labels=LC\246\302) I got LC.. on my plot. Obviously text function doesn’t know what’s \246\302. I google that encoding, and can’t find exact what that is. It doesn’t look like ascii or Unicode. Anybody knows what that is? Note that I can’t use expression() method to pass these special characters because these are read from a text file, I just can’t include greek characters manually that way. Is there a way that I can output these strings with special characters automatically? Thank you! Heyi __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Make 2nd col of 2-col df into header row of same df then adjust col1 data display
Please take a look at my code again. The error message says that object 'Primary.Viol.Type' not found. Have you ever created the object 'Primary.Viol.Type'? It will be working if you replace 'Primary.Viol.Type' by 'PViol.Type.Per.Case.Original$Primary.Viol.Type' where 'factor()' is used. I hope this helps. Chel Hee Lee On 12/18/2014 08:57 PM, Crombie, Burnette N wrote: Chel, your solution is fantastic on the dataset I submitted in my question but it is not working when I import my real dataset into R. Do I need to vectorize the columns in my real dataset after importing? I tried a few things (###) but not making progress: MERGE_PViol.Detail.Per.Case - read.csv(~/FOIA_FLSA/MERGE_PViol.Detail.Per.Case_for_rtf10.csv, stringsAsFactors=TRUE) ### select only certain columns PViol.Type.Per.Case.Original - MERGE_PViol.Detail.Per.Case[,c(CaseID, Primary.Viol.Type)] ### write.csv(PViol.Type.Per.Case,file=PViol.Type.Per.Case.Select.csv) ### PViol.Type.Per.Case.Original - read.csv(~/FOIA_FLSA/PViol.Type.Per.Case.Select.csv) ### PViol.Type.Per.Case.Original$X - NULL ###PViol.Type.Per.Case.Original[] - lapply(PViol.Type.Per.Case.Original, as.character) PViol.Type - c(CaseID, BW.BackWages, LD.Liquid_Damages, MW.Minimum_Wage, OT.Overtime, RK.Records_FLSA, V.Poster_Other, AS.Age, BW.WHMIS_BackWages, HS.Hours, OA.HazOccupationAg, ON.HazOccupationNonAg, R3.Reg3AgeOccupation, RK.Records_CL, V.Other) PViol.Type.Per.Case.Original$Primary.Viol.Type - factor(Primary.Viol.Type, levels=PViol.Type, labels=PViol.Type) ### Error in factor(Primary.Viol.Type, levels = PViol.Type, labels = PViol.Type) : object 'Primary.Viol.Type' not found tmp - split(PViol.Type.Per.Case.Original,PViol.Type.Per.Case.Original$CaseID) ans - ifelse(do.call(rbind, lapply(tmp, function(x)table(x$Primary.Viol.Type))), 1, NA) -Original Message- From: Crombie, Burnette N Sent: Thursday, December 18, 2014 3:01 PM To: 'Chel Hee Lee' Subject: RE: [R] Make 2nd col of 2-col df into header row of same df then adjust col1 data display Thanks for taking the time to review this, Chel. I've got to step away from my desk, but will reply more substantially as soon as possible. -- BNC -Original Message- From: Chel Hee Lee [mailto:chl...@mail.usask.ca] Sent: Thursday, December 18, 2014 2:43 PM To: Jeff Newmiller; Crombie, Burnette N Cc: r-help@r-project.org Subject: Re: [R] Make 2nd col of 2-col df into header row of same df then adjust col1 data display I like the approach presented by Jeff Newmiller as shown in the previous post (I really like his way). As he suggested, it would be good to start with 'factor' since you have all values of 'Primary.Viol.Type'. You may try to use 'split()' function for creating table that you wish to build. Please see the below (I hope this helps): PViol.Type.Per.Case.Original$Primary.Viol.Type - factor(Primary.Viol.Type, levels=PViol.Type, labels=PViol.Type) tmp - split(PViol.Type.Per.Case.Original, PViol.Type.Per.Case.Original$CaseID) ans - ifelse(do.call(rbind, lapply(tmp, function(x) table(x$Primary.Viol.Type))), 1, NA) ans CaseID BW.BackWages LD.Liquid_Damages MW.Minimum_Wage OT.Overtime 1005317 NA NANA NA NA 1007183 NA NANA NA 1 1008833 NA NANA NA 1 1012281 NA NANA NA NA 1015285 NA NANA NA NA 1015315 NA NANA NA 1 1015322 NA NANA NA NA RK.Records_FLSA V.Poster_Other AS.Age BW.WHMIS_BackWages HS.Hours 1005317 NA NA NA NA1 1007183 NA NA NA NA NA 1008833 NA NA NA NA NA 1012281 NA NA NA NA1 1015285 NA 1 1 NA1 1015315 NA NA NA NA NA 1015322 NA 1 NA NA NA OA.HazOccupationAg ON.HazOccupationNonAg R3.Reg3AgeOccupation 1005317 NANA NA 1007183 NANA NA 1008833 NANA NA 1012281 NANA NA 1015285 NANA NA 1015315
Re: [R] pairing columns based on a value
I do not think that you need regular expressions for your problem. Please see the below: d0 - dat_unmatched tmp - apply(d0, 1, function(x){ + first - substr(x,1,1) + idx - which(c(T, Y) == first) + comb - paste(x[idx[1]-1], x[idx], collapse= ) + unlist(strsplit(comb, )) + }) names(tmp) - d0$ID tmp $MCZ4325 [1] C23.2 T43.2 $GDR2343 [1] M20.64 Y32.1 M20.64 T44.2 $BZD2643 [1] B83.2 T43.2 B83.2 Y32.1 B83.2 T44.2 $BCM3455 [1] B83.2 T43.2 Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/18/2014 07:41 AM, Michael Dewey wrote: Not sure how much help it will be but there is a package on CRAN called icd9. Although clearly the codes are different in ICD 10 it may give you some hints. I suppose you could even email the maintainer to see whether there is an icd10 in the pipeline. On 17/12/2014 20:14, Robert Strother wrote: I have a large dataset (~50,000 rows, 96 columns), of hospital administrative data. many of the columns are clinical coding of inpatient event (using ICD-10). A simplified example of the data is below dput(dat_unmatched) structure(list(ID = structure(c(4L, 3L, 2L, 1L), .Label = c(BCM3455, BZD2643, GDR2343, MCZ4325), class = factor), X.1 = structure(c(2L, 3L, 1L, 1L), .Label = c(B83.2, C23.2, F56.23), class = factor), X.2 = structure(c(2L, 1L, 2L, 2L), .Label = c(M20.64, T43.2 ), class = factor), X.3 = structure(c(2L, 3L, 3L, 1L), .Label = c(F56.23, R23.1, Y32.1), class = factor), X.4 = structure(c(1L, 2L, 2L, 3L), .Label = c(M23.5, T44.2, Y32.1), class = factor), X.5 = structure(c(1L, 2L, 1L, 2L), .Label = c(, Q23.6 ), class = factor)), .Names = c(ID, X.1, X.2, X.3, X.4, X.5), class = data.frame, row.names = c(NA, -4L)) I am interested in a set of codes that start with a T or a Y, and link them to the preceding column that does not begin with a T or Y. I suspect I will need to use regular expressions, and likely a loop, but I am really out of my depth at this point. I would like the final dataset to look like: dput(dat_matched) structure(list(ID = structure(c(4L, 3L, 2L, 1L), .Label = c(BCM3455, BZD2643, GDR2343, MCZ4325), class = factor), X.1 = structure(c(2L, 3L, 1L, 1L), .Label = c(B83.2, C23.2, M20.64), class = factor), X.2 = structure(c(1L, 2L, 1L, 1L), .Label = c(T43.2, Y32.1 ), class = factor), X.3 = structure(c(1L, 4L, 2L, 3L), .Label = c(, B83.2, F56.23, M20.64), class = factor), X.4 = structure(c(1L, 2L, 3L, 3L), .Label = c(, T44.2, Y32.1), class = factor), X.5 = structure(c(1L, 1L, 2L, 1L), .Label = c(, B83.2 ), class = factor), X = structure(c(1L, 1L, 2L, 1L), .Label = c(, T44.2), class = factor)), .Names = c(ID, X.1, X.2, X.3, X.4, X.5, X), class = data.frame, row.names = c(NA, -4L)) Any help appreciated. Matthew [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - No virus found in this message. Checked by AVG - www.avg.com Version: 2015.0.5577 / Virus Database: 4253/8759 - Release Date: 12/18/14 __ 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] Condensing data.frame
datBySite - split(dat, dat$site) output - lapply(datBySite, function(x){ + x$idx - seq_len(nrow(x)) + x$grp - ifelse(x$idx 7, x$idx, 7) + rval - tapply(x$countPercentage, x$grp, sum) + x$grp - x$count - x$countTotal - NULL + x - x[seq_len(7), ] + x$tax_name - as.character(x$tax_name) + x$tax_name[7] - Others + x$new - rval + return(x) + }) head(do.call(rbind, output), 14) sitetax_name countPercentage idx new CID_1.1CID_1 Cyanobacteria 37.483098 1 37.483098 CID_1.2CID_1 Proteobacteria 29.244832 2 29.244832 CID_1.3CID_1 Bacteroidetes 15.825567 3 15.825567 CID_1.4CID_1 Verrucomicrobia6.384960 4 6.384960 CID_1.5CID_1 Firmicutes2.301857 5 2.301857 CID_1.6CID_1 Acidobacteria2.075152 6 2.075152 CID_1.7CID_1 Others1.675182 7 6.684533 CID_10.27 CID_10 Proteobacteria 35.366606 1 35.366606 CID_10.28 CID_10 Bacteroidetes 25.188484 2 25.188484 CID_10.29 CID_10 Cyanobacteria 23.294828 3 23.294828 CID_10.30 CID_10 Verrucomicrobia6.970592 4 6.970592 CID_10.31 CID_10 Acidobacteria1.988448 5 1.988448 CID_10.32 CID_10 Actinobacteria1.644548 6 1.644548 CID_10.33 CID_10 Others1.582823 7 5.546493 I hope this helps. Chel Hee Lee On 12/07/2014 08:21 AM, Morway, Eric wrote: Using the dataset dat (found below), I'm seeking a way to condense down the data.frame such that each site (i.e., CID_1...CID_13) has a maximum of 7 rows of post-processed data, where the first 6 have the highest countPercentage and the 7th row is the sum of countPercentage from all other rows within that site, and it is assigned the name Other. So, for the first two sites in the provided data.frame, CID_1 CID_10, they would reduce to: CID_1 Cyanobacteria 37.48 CID_1 Proteobacteria 29.24 CID_1 Bacteroidetes 15.83 CID_1 Verrucomicrobia 6.38 CID_1 Firmicutes 2.30 CID_1 Acidobacteria 2.08 CID_1 Other6.68 CID_10 Proteobacteria 35.37 CID_10 Bacteroidetes 25.19 CID_10 Cyanobacteria 23.29 CID_10 Verrucomicrobia 6.97 CID_10 Acidobacteria 1.99 CID_10 Actinobacteria 1.64 CID_10 Other 5.55 dat - read.table(header=TRUE, sep=,, text=site,tax_name,count,countTotal,countPercentage CID_1,Cyanobacteria,46295,123509,37.483098398 CID_1,Proteobacteria,36120,123509,29.244832360 CID_1,Bacteroidetes,19546,123509,15.825567368 CID_1,Verrucomicrobia,7886,123509,6.384959801 CID_1,Firmicutes,2843,123509,2.301856545 CID_1,Acidobacteria,2563,123509,2.075152418 CID_1,Actinobacteria,2069,123509,1.675181566 CID_1,Planctomycetes,1481,123509,1.199102899 CID_1,Chloroflexi,1181,123509,0.956205621 CID_1,Gemmatimonadetes,956,123509,0.774032662 CID_1,Spirochaetes,688,123509,0.557044426 CID_1,Lentisphaerae,526,123509,0.425879895 CID_1,Ignavibacteriae,324,123509,0.262329061 CID_1,Chlorobi,238,123509,0.192698508 CID_1,Nitrospirae,230,123509,0.186221247 CID_1,Nitrospinae,169,123509,0.136832134 CID_1,Elusimicrobia,131,123509,0.106065145 CID_1,Tenericutes,114,123509,0.092300966 CID_1,Fibrobacteres,72,123509,0.058295347 CID_1,Thermotogae,21,123509,0.017002810 CID_1,Fusobacteria,21,123509,0.017002810 CID_1,Armatimonadetes,15,123509,0.012144864 CID_1,Synergistetes,10,123509,0.008096576 CID_1,Deinococcus-Thermus,6,123509,0.004857946 CID_1,Deferribacteres,2,123509,0.001619315 CID_1,Caldiserica,2,123509,0.001619315 CID_10,Proteobacteria,16043,45362,35.366606411 CID_10,Bacteroidetes,11426,45362,25.188483753 CID_10,Cyanobacteria,10567,45362,23.294828270 CID_10,Verrucomicrobia,3162,45362,6.970592126 CID_10,Acidobacteria,902,45362,1.988448481 CID_10,Actinobacteria,746,45362,1.644548300 CID_10,Firmicutes,718,45362,1.582822627 CID_10,Gemmatimonadetes,358,45362,0.789206825 CID_10,Planctomycetes,357,45362,0.787002337 CID_10,Chloroflexi,265,45362,0.584189410 CID_10,Spirochaetes,235,45362,0.518054759 CID_10,Ignavibacteriae,177,45362,0.390194436 CID_10,Lentisphaerae,108,45362,0.238084741 CID_10,Nitrospinae,75,45362,0.165336625 CID_10,Nitrospirae,58,45362,0.127860324 CID_10,Chlorobi,44,45362,0.096997487 CID_10,Elusimicrobia,28,45362,0.061725673 CID_10,Fibrobacteres,26,45362,0.057316697 CID_10,Armatimonadetes,15,45362,0.033067325 CID_10,Deinococcus-Thermus,13,45362,0.028658348 CID_10,Tenericutes,10,45362,0.022044883 CID_10,Synergistetes,9,45362,0.019840395 CID_10,Fusobacteria,9,45362,0.019840395 CID_10,Deferribacteres,6,45362,0.013226930 CID_10,Thermotogae,3,45362,0.006613465 CID_10,Caldiserica,2,45362,0.004408977 CID_11,Proteobacteria,10019,31387,31.920858954 CID_11,Cyanobacteria,8811,31387,28.072131774 CID_11,Bacteroidetes,7930,31387,25.265237200 CID_11,Verrucomicrobia,1750,31387,5.575556759 CID_11,Firmicutes,806,31387,2.567942142 CID_11,Acidobacteria,548,31387,1.745945774 CID_11,Actinobacteria,434,31387,1.382738076 CID_11,Chloroflexi,203,31387,0.646764584 CID_11,Planctomycetes,197,31387,0.627648389
Re: [R] need help with withRestarts ?
I am very happy to see the message replied by Martin Morgan. He provides an example how to use the function 'withRestarts()'. I personally like his approach; however, the function 'tryCatch()' evaluates the first argument 'expression'. That's, this function can be placed on anywhere. It seems to me that your primary goal is to make the function 'myfunc()' continue to work. I hope that I correctly understand your question. Please see the place where I put the function 'tryCatch()' in your code. myfunc - function(){ + while(1){ + x - runif(1) + tryCatch( { + if ( x 0.3 ) a - x/2 else a - x/b + print(a) + }, + warning=function(w) print(warning), + error=function(e) print(error), + finally=cat(Error is printed if x 0.3. x=, x, \nAnyway, move to next!\n) ) + Sys.sleep(1) + } + } myfunc() [1] 0.2630333 Error is printed if x 0.3. x= 0.5260666 Anyway, move to next! [1] error Error is printed if x 0.3. x= 0.2929098 Anyway, move to next! [1] 0.2123464 Error is printed if x 0.3. x= 0.4246928 Anyway, move to next! [1] 0.2535644 Error is printed if x 0.3. x= 0.5071288 Anyway, move to next! [1] error Error is printed if x 0.3. x= 0.1941202 Anyway, move to next! (continue) I hope this helps, and thank you so much, Martin Morgan, for your good lesson. Chel Hee Lee On 12/06/2014 07:22 PM, Martin Morgan wrote: On 12/06/2014 02:53 PM, ce wrote: Dear all, Let's say I have this script , below. tryCatch indeed catches the error but exists, I want function to continue and stay in the loop. I found very examples of withRestarts on internet to figure it out. Could you help me how to do it ? myfunc - function() { while(1) { x - runif(1) if ( x 0.3 ) a - x/2 else a - x/b print(a) Sys.sleep(1) } } Hi -- Modify your function so that the code that you'd like to restart after is surrounded with withRestarts(), and with a handler that performs the action you'd like, so myfunc - function() { while(TRUE) { x - runif(1) withRestarts({ if ( x 0.3 ) a - x/2 else a - x/b print(a) }, restartLoop = function() { message(restarting) NULL }) Sys.sleep(1) } } Instead of using tryCatch(), which returns to the top level context to evaluate the handlers, use withCallingHandlers(), which retains the calling context. Write a handler that invokes the restart withCallingHandlers({ myfunc() }, error = function(e) { message(error) invokeRestart(restartLoop) }) It's interesting that tryCatch is usually used with errors (because errors are hard to recover from), and withCallingHandlers are usually used with warnings (because warnings can usually be recovered from), but tryCatch() and withCallingHandlers() can be used with any condition. Martin tryCatch({ myfunc() }, warning = function(w) { print(warning) }, error = function(e) { print(error) }, finally = { print(end) } ) __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scatter plot for repeated measures
It seems that you would like to make a spaghetti plot (in a longitudinal data analysis). You can use the function 'interaction.plot()'. with(my.df, interaction.plot(TIME, ID, X)) I hope this helps. Chel Hee Lee On 12/06/2014 02:24 AM, arun wrote: Not sure whether it is a scatterplot or just a plot with 3 lines. If it is the latter, library(reshape2) matplot(acast(my.df, TIME~ID, value.var='X'), type='l', col=1:3, ylab='X', xlab='TIME') legend('bottomright', inset=.05, legend=LETTERS[1:3], pch=1, col=1:3) A.K. On Friday, December 5, 2014 5:45 PM, farnoosh sheikhi farnoosh...@yahoo.com wrote: Hi Arun, I hope you are doing well. I have a data set as follow: my.df - data.frame(ID=rep(c(A,B,C), 5), TIME=rep(1:5, each=3), X=1:5) I would like to get a scatterplot where x axis is Time (1,2,3,4,5) and y axis is X, but I want to have three lines separately for each ID. I basically want to tack each ID over time. Is this possible? Thanks a lot and Happy Holidays to you! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Put 2 ablines in an empty plot
The following example may give you an idea regarding your question. Please see what happens by typing the codes x - seq(from=-5, to=5, by=1) y1 - 0 + 0.5*x y2 - 0 - 0.5*x plot(x,y1, type=n) points(x,y1) points(x,y2) abline(a=0, b=0.5) abline(a=0, b=-0.5) Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/05/2014 02:30 AM, Adrien Bonvin wrote: Bonjour Hi everybody, Firs of all, sorry for my terrible English, I would like to know if it’s possible to create an “empty plot” in which i could add two ablines I created on two different plots earlyer in my script. As a result I would like to have a plot with only the two ablines (in the same plot) but without the graphs I used to create the ablines in the first place. I hope I explained my problem well enough. Thanks for helping me out, i hope someone has the answer. Adrien Bonvin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rename multiple files in a directory and write renamed files back to directory
Your question is not clear to me. Do you wish to start numbers from 200 using 'formatC()'? formatC(seq(from=200, to=1200, by=500), width=5, flag=0) [1] 00200 00700 01200 You can do the same job using function 'sprintf()' as shown in the below: sprintf(%05d, seq(from=200, to=1200, by=500)) [1] 00200 00700 01200 I like to read the documentation by typing help(formatC) help(sprintf) You may find answers what you wish to get. Documentation has been my best friend when using R. I hope this helps. Chel Hee Lee On 12/05/2014 09:35 AM, Zilefac Elvis wrote: Hi Chel, How can I modify the script such that the numbering starts from 200,... instead of 001? flag=0 does not accept anything other than 0. Thanks, Asong. On Thursday, December 4, 2014 11:17 PM, Chel Hee Lee chl...@mail.usask.ca wrote: I see that a function 'format()' is used in your code. format(c(1,5,32,100), width=3, flag=0) [1] 1 5 32 100 formatC(c(1,5,32,100), width=3, flag=0) [1] 001 005 032 100 I hope this helps. Chel Hee Lee On 12/04/2014 10:54 PM, Zilefac Elvis wrote: Hi Chel, Thanks for the timely reply. It works but a minor problem remains. Here is the modified version of your code: file_names- list.files(pattern=Sim1971-2000_Daily_) new_names - paste(rcp45_Daily_Sim,format(seq(length(file_names)), width=3, flag=00), .dat, sep=) #files - paste(paste(getwd(),lfile,sep=/), list.files(lfile),sep=/)# getwd of these files/contents file.rename(from=file_names, to=new_names) list.files(pattern=*.dat) I changed width =3 and flag=00 because my output has to be 001.dat...200.dat. However, this is what i got: list.files(pattern=*.dat) [1] rcp45_Daily_Sim 1.dat rcp45_Daily_Sim 2.dat rcp45_Daily_Sim 3.dat rcp45_Daily_Sim 4.dat [5] rcp45_Daily_Sim 5.dat rcp45_Daily_Sim 6.dat rcp45_Daily_Sim 7.dat rcp45_Daily_Sim 8.dat [9] rcp45_Daily_Sim 9.dat rcp45_Daily_Sim 10.dat The zeros disappear but I need them. Please help. Asong. On Thursday, December 4, 2014 10:16 PM, Chel Hee Lee chl...@mail.usask.ca wrote: I put five data files (example1.dat, example2.dat, example3.dat, example4.dat, example5.dat, example6.dat) in my working directory. file_names - list.files(pattern=*.dat) file_names [1] example1.dat example2.dat example3.dat example4.dat example5.dat [6] example6.dat new_names - paste(new_example_, + formatC(seq(length(file_names)), width=2, flag=0), + .dat, sep=) new_names [1] new_example_01.dat new_example_02.dat new_example_03.dat [4] new_example_04.dat new_example_05.dat new_example_06.dat file.rename(from=file_names, to=new_names) [1] TRUE TRUE TRUE TRUE TRUE TRUE list.files(pattern=*.dat) [1] new_example_01.dat new_example_02.dat new_example_03.dat [4] new_example_04.dat new_example_05.dat new_example_06.dat Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/04/2014 09:44 PM, Zilefac Elvis via R-help wrote: Hello, I would like to rename multiple files in a directory. Filenames are read using: lfile - list.files(pattern=rcp45_Daily_) files - paste(paste(getwd(),lfile,sep=/), list.files(lfile),sep=/)# getwd of these files dput(lfile) c(rcp45_Daily_Sim001.dat, rcp45_Daily_Sim002.dat) - How can I rename these files (200 in number) using something like: file.rename(lfile, paste0(rcp45_Daily_Sim, 1:200))?The new filenames should be rcp45_Daily_Sim001, rcp45_Daily_Sim002, ..., rcp45_Daily_Sim200. - I would like to write the new file names to the directory. The data files contain huge amounts of data and should not be read into R. Only the file names should change. Many thanks for your helpful answers. Asong. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rename multiple files in a directory and write renamed files back to directory
I put five data files (example1.dat, example2.dat, example3.dat, example4.dat, example5.dat, example6.dat) in my working directory. file_names - list.files(pattern=*.dat) file_names [1] example1.dat example2.dat example3.dat example4.dat example5.dat [6] example6.dat new_names - paste(new_example_, + formatC(seq(length(file_names)), width=2, flag=0), + .dat, sep=) new_names [1] new_example_01.dat new_example_02.dat new_example_03.dat [4] new_example_04.dat new_example_05.dat new_example_06.dat file.rename(from=file_names, to=new_names) [1] TRUE TRUE TRUE TRUE TRUE TRUE list.files(pattern=*.dat) [1] new_example_01.dat new_example_02.dat new_example_03.dat [4] new_example_04.dat new_example_05.dat new_example_06.dat Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/04/2014 09:44 PM, Zilefac Elvis via R-help wrote: Hello, I would like to rename multiple files in a directory. Filenames are read using: lfile - list.files(pattern=rcp45_Daily_) files - paste(paste(getwd(),lfile,sep=/), list.files(lfile),sep=/)# getwd of these files dput(lfile) c(rcp45_Daily_Sim001.dat, rcp45_Daily_Sim002.dat) - How can I rename these files (200 in number) using something like: file.rename(lfile, paste0(rcp45_Daily_Sim, 1:200))?The new filenames should be rcp45_Daily_Sim001, rcp45_Daily_Sim002, ..., rcp45_Daily_Sim200. - I would like to write the new file names to the directory. The data files contain huge amounts of data and should not be read into R. Only the file names should change. Many thanks for your helpful answers. Asong. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rename multiple files in a directory and write renamed files back to directory
I see that a function 'format()' is used in your code. format(c(1,5,32,100), width=3, flag=0) [1] 1 5 32 100 formatC(c(1,5,32,100), width=3, flag=0) [1] 001 005 032 100 I hope this helps. Chel Hee Lee On 12/04/2014 10:54 PM, Zilefac Elvis wrote: Hi Chel, Thanks for the timely reply. It works but a minor problem remains. Here is the modified version of your code: file_names- list.files(pattern=Sim1971-2000_Daily_) new_names - paste(rcp45_Daily_Sim,format(seq(length(file_names)), width=3, flag=00), .dat, sep=) #files - paste(paste(getwd(),lfile,sep=/), list.files(lfile),sep=/)# getwd of these files/contents file.rename(from=file_names, to=new_names) list.files(pattern=*.dat) I changed width =3 and flag=00 because my output has to be 001.dat...200.dat. However, this is what i got: list.files(pattern=*.dat) [1] rcp45_Daily_Sim 1.dat rcp45_Daily_Sim 2.dat rcp45_Daily_Sim 3.dat rcp45_Daily_Sim 4.dat [5] rcp45_Daily_Sim 5.dat rcp45_Daily_Sim 6.dat rcp45_Daily_Sim 7.dat rcp45_Daily_Sim 8.dat [9] rcp45_Daily_Sim 9.dat rcp45_Daily_Sim 10.dat The zeros disappear but I need them. Please help. Asong. On Thursday, December 4, 2014 10:16 PM, Chel Hee Lee chl...@mail.usask.ca wrote: I put five data files (example1.dat, example2.dat, example3.dat, example4.dat, example5.dat, example6.dat) in my working directory. file_names - list.files(pattern=*.dat) file_names [1] example1.dat example2.dat example3.dat example4.dat example5.dat [6] example6.dat new_names - paste(new_example_, + formatC(seq(length(file_names)), width=2, flag=0), + .dat, sep=) new_names [1] new_example_01.dat new_example_02.dat new_example_03.dat [4] new_example_04.dat new_example_05.dat new_example_06.dat file.rename(from=file_names, to=new_names) [1] TRUE TRUE TRUE TRUE TRUE TRUE list.files(pattern=*.dat) [1] new_example_01.dat new_example_02.dat new_example_03.dat [4] new_example_04.dat new_example_05.dat new_example_06.dat Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/04/2014 09:44 PM, Zilefac Elvis via R-help wrote: Hello, I would like to rename multiple files in a directory. Filenames are read using: lfile - list.files(pattern=rcp45_Daily_) files - paste(paste(getwd(),lfile,sep=/), list.files(lfile),sep=/)# getwd of these files dput(lfile) c(rcp45_Daily_Sim001.dat, rcp45_Daily_Sim002.dat) - How can I rename these files (200 in number) using something like: file.rename(lfile, paste0(rcp45_Daily_Sim, 1:200))?The new filenames should be rcp45_Daily_Sim001, rcp45_Daily_Sim002, ..., rcp45_Daily_Sim200. - I would like to write the new file names to the directory. The data files contain huge amounts of data and should not be read into R. Only the file names should change. Many thanks for your helpful answers. Asong. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Getting the most recent dates in a new column from dates in four columns using the dplyr package (mutate verb)
The output in the object 'new1' are apparently same the output in the object 'new2'. Are you trying to compare the entries of two outputs 'new1' and 'new2'? If so, the function 'all()' would be useful: all(new1 == new2, na.rm=TRUE) [1] TRUE If you are interested in the comparison of two objects in terms of class, then the function 'identical()' is useful: attributes(new1) $names [1] id mrjdate cocdate inhdate haldate oldflag $class [1] rowwise_df tbl_df tbldata.frame $row.names [1] 1 2 3 4 5 6 7 attributes(new2) $names [1] id mrjdate cocdate inhdate haldate oiddate $row.names [1] 1 2 3 4 5 6 7 $class [1] data.frame I hope this helps. Chel Hee Lee On 12/03/2014 04:10 PM, Muhuri, Pradip (SAMHSA/CBHSQ) wrote: Hello, Two alternative approaches - mutate() vs. sapply() - were used to get the desired results (i.e., creating a new column of the most recent date from 4 dates ) with help from Arun and Mark on this forum. I now find that the two data objects (created using two different approaches) are not identical although results are exactly the same. identical(new1, new2) [1] FALSE Please see the reproducible example below. I don't understand why the code returns FALSE here. Any hints/comments will be appreciated. Thanks, Pradip # reproducible example library(dplyr) # data object - description temp - id mrjdate cocdate inhdate haldate 1 2004-11-04 2008-07-18 2005-07-07 2007-11-07 2 NA NA NA NA 3 2009-10-24 NA 2011-10-13 NA 4 2007-10-10 NA NA NA 5 2006-09-01 2005-08-10 NA NA 6 2007-09-04 2011-10-05 NA NA 7 2005-10-25 NA NA 2011-11-04 # read the data object example.data - read.table(textConnection(temp), colClasses=c(character, Date, Date, Date, Date), header=TRUE, as.is=TRUE ) # create a new column -dplyr solution (Acknowledgement: Arun) new1 - example.data %% rowwise() %% mutate(oldflag=as.Date(max(mrjdate,cocdate, inhdate, haldate, na.rm=TRUE), origin='1970-01-01')) # create a new column - Base R solution (Acknowlegement: Mark Sharp) new2 - example.data new2$oiddate - as.Date(sapply(seq_along(new2$id), function(row) { if (all(is.na(unlist(example.data[row, c('mrjdate','cocdate', 'inhdate', 'haldate')] { max_d - NA } else { max_d - max(unlist(example.data[row, c('mrjdate','cocdate', 'inhdate', 'haldate')]), na.rm = TRUE) } max_d}), origin = 1970-01-01) identical(new1, new2) # print records print (new1); print(new2) Pradip K. Muhuri SAMHSA/CBHSQ 1 Choke Cherry Road, Room 2-1071 Rockville, MD 20857 Tel: 240-276-1070 Fax: 240-276-1260 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Muhuri, Pradip (SAMHSA/CBHSQ) Sent: Sunday, November 09, 2014 6:11 AM To: 'Mark Sharp' Cc: r-help@r-project.org Subject: Re: [R] Getting the most recent dates in a new column from dates in four columns using the dplyr package (mutate verb) Hi Mark, Your code has also given me the results I expected. Thank you so much for your help. Regards, Pradip Pradip K. Muhuri, PhD SAMHSA/CBHSQ 1 Choke Cherry Road, Room 2-1071 Rockville, MD 20857 Tel: 240-276-1070 Fax: 240-276-1260 -Original Message- From: Mark Sharp [mailto:msh...@txbiomed.org] Sent: Sunday, November 09, 2014 3:01 AM To: Muhuri, Pradip (SAMHSA/CBHSQ) Cc: r-help@r-project.org Subject: Re: [R] Getting the most recent dates in a new column from dates in four columns using the dplyr package (mutate verb) Pradip, mutate() works on the entire column as a vector so that you find the maximum of the entire data set. I am almost certain there is some nice way to handle this, but the sapply() function is a standard approach. max() does not want a dataframe thus the use of unlist(). Using your definition of data1: data3 - data1 data3$oidflag - as.Date(sapply(seq_along(data3$id), function(row) { if (all(is.na(unlist(data1[row, -1] { max_d - NA } else { max_d - max(unlist(data1[row, -1]), na.rm = TRUE) } max_d}), origin = 1970-01-01) data3 idmrjdatecocdateinhdatehaldateoidflag 1 1 2004-11-04 2008-07-18 2005-07-07 2007-11-07 2008-07-18 2 2 NA NA NA NA NA 3 3 2009-10-24 NA 2011-10-13 NA 2011-10-13 4 4 2007-10-10 NA NA NA 2007-10-10 5 5 2006-09-01 2005-08-10 NA NA 2006-09-01 6 6 2007-09-04 2011-10-05 NA NA 2011-10-05 7 7 2005-10-25 NA NA 2011-11-04 2011-11-04 R. Mark Sharp, Ph.D. Director of Primate Records Database Southwest National Primate Research Center Texas Biomedical
Re: [R] combining unequal dataframes based on a common grouping factor
frame1 ID GROUP PROP_AREA 1 1 A 0.33 2 2 A 0.33 3 3 A 0.33 4 4 B 0.50 5 5 B 0.50 6 6 C 1.00 7 7 D 1.00 frame2 GROUP VALUE1 VALUE2 1 A 10 5 2 B 20 10 3 C 30 15 4 D 40 20 obj1 - merge(x=frame1, y=frame2, by=GROUP) obj1$rval1 - obj1$PROP_AREA * obj1$VALUE1 obj1$rval2 - obj1$PROP_AREA * obj1$VALUE2 obj1 GROUP ID PROP_AREA VALUE1 VALUE2 rval1 rval2 1 A 1 0.33 10 5 3.3 1.65 2 A 2 0.33 10 5 3.3 1.65 3 A 3 0.33 10 5 3.3 1.65 4 B 4 0.50 20 10 10.0 5.00 5 B 5 0.50 20 10 10.0 5.00 6 C 6 1.00 30 15 30.0 15.00 7 D 7 1.00 40 20 40.0 20.00 idx - match(x=frame1$GROUP, table=frame2$GROUP) rval1 - frame1[PROP_AREA] * frame2[idx, VALUE1] rval2 - frame1[PROP_AREA] * frame2[idx, VALUE2] cbind(ID=frame1[idx, ID], rval1, rval2) ID PROP_AREA PROP_AREA 1 1 3.3 1.65 2 1 3.3 1.65 3 1 3.3 1.65 4 2 10.0 5.00 5 2 10.0 5.00 6 3 30.0 15.00 7 4 40.0 20.00 Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/03/2014 03:14 PM, Brock Huntsman wrote: I apologize if this is a relatively easy problem, but have been stuck on this issue for a few days. I am attempting to combine values from 2 separate dataframes. Each dataframe contains a shared identifier (GROUP). Dataframe 1 (3272 rows x 3 columns) further divides this shared grouping factor into unique identifiers (ID), as well as contains the proportion of the GROUP area of which the unique identifier consists (PROP_AREA). Dataframe 2 (291 x 14976) in addition to consisting of the shared identifier, also has numerous columns consisting of values (VALUE1, VALUE2). I would like to multiply the PROP_AREA in dataframe 1 by each value in dataframe 2 (VALUE1 through VALUE14976) based on the GROUP factor, constructing a final dataframe of size 3272 x 14976. An example of the data frames are as follows: frame1: ID GROUP PROP_AREA 1 A 0.33 2 A 0.33 3 A 0.33 4 B 0.50 5 B 0.50 6 C 1.00 7 D 1.00 frame2: GROUP VALUE1 VALUE2 A 10 5 B 20 10 C 30 15 D 40 20 Desired dataframe frame3: ID VALUE1 VALUE2 1 3.3 1.65 2 3.3 1.65 3 3.3 1.65 4 10 5 5 10 5 6 30 15 7 40 20 I assume I would need to use the %in% function or if statements, but am unsure how to write the code. I have attempted to construct a for loop with an if statement, but have not been successful as of yet. for(i in 1:nrow(frame1)) { for(j in 2:ncol(frame2)) { if (frame1$GROUP[i] == frame2$GROUP[i]) { frame3[i,j+1] - frame1$PROP_AREA[i]*frame2[i,j+1] } } } Any advice on suggested code or packages to read up on would be much appreciated. Brock [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] coerce data to numeric
In your function 'nbars()', I see the line: tX = rbind(tX, as.data.frame(cbind(GId = ,Grp = names(sG[n]), S = fm, T = fm))) It seems that you wish to have a data frame that has numeric variables 'S' and 'T'. The reason why you have character variables of 'S' and 'T' from your code is that you used a character vector when function 'cbind()' is used. Please see the following example: cbind(1:3, 4:6) [,1] [,2] [1,]14 [2,]25 [3,]36 cbind(1:3, LETTERS[1:3]) [,1] [,2] [1,] 1 A [2,] 2 B [3,] 3 C What do you see? I see that numeric values are changed to characters. Hence, I guess that you will have the output that you want if you change your code as below: tX = rbind(tX, as.data.frame(cbind(GId =0,Grp = 0, S = fm, T = fm))) Of course you have to do little more works with this change in order to get final bar plots. I hope this helps. Chel Hee Lee On 12/03/2014 12:29 PM, Charles R Parker wrote: I am trying to create groups of barplots from data that have different number of records in the groups, in such a way that all of the plots will have the same numbers and sizes of bars represented even when some of the groups will have some bars of zero height. The goal then would be to display multiple plots on a single page using split.screen or something similar. lattice does not seem suitable because of the data structure it operates on. A simple data structure that I operate on is given here: dput(stplot) structure(list(GId = structure(1:11, .Label = c(A1, B1, B2, B3, B4, B5, C1, C2, D1, D2, D3), class = factor), Grp = structure(c(1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L), .Label = c(A, B, C, D), class = factor), S = c(12.3, 23.8, 0, 7.6, 14.32, 1.9, 5.1, 0, 14.6, 10.1, 8.7), T = c(5L, 12L, 2L, 1L, 4L, 1L, 1L, 9L, 5L, 6L, 3L)), .Names = c(GId, Grp, S, T), class = data.frame, row.names = c(NA, -11L )) My code, which doesn't quite work is: nbars - function(x){ sG = summary(x$Grp) mG = max(sG) for(n in 1:length(sG)){ tX = subset(x,x$Grp==names(sG[n])) if(nrow(tX) mG){ fm = as.numeric(rep(length = mG - nrow(tX), 0)) tX = rbind(tX, as.data.frame(cbind(GId = ,Grp = names(sG[n]), S = fm, T = fm))) } #print(tX) #dput(t(as.matrix(tX[,3:4]))) barplot(t(as.matrix(tX[,3:4])),beside=TRUE, names.arg=tX$GId, col = c(navy,gray)) } } The function nbars first gets the list of group values with their counts 'summary(x$Grp)'. It then determines the maximum number of bar pairs in the largest of the groups 'max(sG)', and uses this to determine how much each smaller group needs to be padded to fill out the proper number of bars in the ultimate barplots, using the for loop. If you uncomment the #print(tX) you can see that this works...sort of. The problem becomes apparent if you uncomment the #dput. This shows that the tX treats the S and T values as characters rather than as numeric values. This prevents the barplots from working. By changing the for loop to begin 'for(n in 2:length(sG)' the second plot will display correctly, but the third plot will fail. I have tried various options to force the S and T variables to be numeric, but none of those have worked (as.numeric(fm), as.matrix(fm), as.vector(fm)) in the 'if(nrow(tX) mG)' loop, but these have not worked. If there is a sure-fire way to solve the problem I would be grateful. Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R installation
This question seems to be the problem specific to Ubuntu. What if you post the message to r-sig-deb...@r-project.org?? I hope you get answers from that mailing list. Chel Hee Lee On 12/02/2014 11:10 AM, VG wrote: Hi everyone, I was having trouble with R i installed some time ago on my local ubuntu machine. So i removed R completely from my system in order to re install it. I used these commands to install R sudo apt-get install r-base r-base-dev Then on the terminal I typed which R: it returns /usr/bin/R When i launch R on the terminal by typing R it gives me this: */usr/bin/R: line 236: /usr/lib/R/etc/ldpaths: No such file or directory* R version 3.1.2 (2014-10-31) -- Pumpkin Helmet Copyright (C) 2014 The R Foundation for Statistical Computing Platform: i486-pc-linux-gnu (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. *Warning: namespace ‘DESeq’ is not available and has been replacedby .GlobalEnv when processing object ‘data2* To fix */usr/bin/R: line 236: /usr/lib/R/etc/ldpaths: No such file or directory* I went to */usr/lib/R/etc/ and did * *file ldpaths and it gave me* ldpaths: broken symbolic link to `/etc/R/ldpaths' How to fix this?? Also I need to fix warning Regards Varun [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: R Statistics
Or, you may use this approach: attach(achtergrond) spits - ifelse(uurenminuut = 5.30 uurenminuut 9.30, morning, + ifelse(uurenminuut =16.30 uurenminuut 19.0, evening, + between)) table(spits) spits between evening morning 1636 142 579 I personally like the approach presented by Bill Dunlap (in the previous message). I think his approach is smart and nice. You will see the same results as shown in the above: achtergrond$spits=cut(achtergrond$uurenminuut,c(-1.0,5.30,9.30,16.30,19.0,24.0),right=FALSE) levels(achtergrond$spits) - c(between,morning,between,evening,between) table(achtergrond$spits) between morning evening 1636 579 142 You can also use function 'findInterval()' instead of using 'cut()'. I hope this helps. Chel Hee Lee On 12/02/2014 02:04 PM, William Dunlap wrote: You can do this in 2 steps - have cut() make a factor with a different level for each time period then use levels-() to merge some of the levels. z - cut(.5:3.5, breaks=c(0,1,2,3,4), labels=c(0-1, 1-2, 2-3, 3-4)) levels(z) [1] 0-1 1-2 2-3 3-4 levels(z) - c(between, 1-2, between, 3-4) # or levels(z)[c(1,3)] - between str(z) Factor w/ 3 levels between,1-2,..: 1 2 1 3 Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Dec 2, 2014 at 11:32 AM, Dries David dries-da...@hotmail.com wrote: Hey I have a question about making a new variable in R. I have put my dataset in attachment. I have to make a new variable spits where spits=morning when uurenminuut (also a variabel) is between 5.30 and 9.30, when uurenminuut is between 16.30 and 19.0 spits has to be equal to evening. But here is my problem: for all the values not between 5.30- 9.30 and 16.30-19.0 spits must be equal to between achtergrond$minuutdec=achtergrond$minuut/100 achtergrond$uurenminuut=achtergrond$uur+achtergrond$minuutdec achtergrond$spits=cut(uurenminuut,c(-1.0,5.30,9.30,16.30,19.0,24.0),labels=c(between,morning,between,evening,between),right=FALSE) When I do this i get a warning message, because I use between more than once as label. Between has to be one label that covers all values that are not in morning and evening. Could you help me with this? Kind regards Dries David __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I extract single entries from a factor?
xx - as.factor(c(AL, AK, CA, FL)) xx [1] AL AK CA FL Levels: AK AL CA FL as.character(xx) [1] AL AK CA FL I hope this helps. Chel Hee Lee On 14-11-22 01:12 AM, Aditya Singh wrote: Dear Boris and R-Experts, I have a variable my_state which is a 2-letter character string telling which American state the user inputs. This I am do a if(identical(database entry,my_state)) to check for occurrences in the database. The problem is that the database entry[i,j] shows as a factor with various levels, e.g. the output when I do class(database[i,j])is: [1] TX AL.. levels through WY How do I convert a factor into a character? Aditya On Saturday, November 22, 2014 12:40 AM, Boris Steipe boris.ste...@utoronto.ca wrote: Seems to me you probably wanted a while in line 4. N.b. There's also a missing } and totally messed up formatting :-( B. On Nov 21, 2014, at 1:19 PM, Aditya Singh aps...@yahoo.com wrote: 1 my_min= min(outcome_data[which(outcome_data$State==my_state),11],na.rm=TRUE) 2 print(my_min) 3 jkr=0 4 if (jkr= 4706) {jkr=jkr+1 5 if (identical(outcome_data[jkr,11],my_min) identical(outcome_data[jkr,7],my_state)) { 6 print((outcome_data[jkr,2])) 7 break 8 } Dear Experts, My computer is never 'inside' of the if condition at line 5, as jkr=0 always. my_min is a numeric. my_state is a 2 letter American State (character). This code gives NULL as output. Wondering! Its either very obvious or I am very dumb. Please do do reply! Aditya __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Equivalent to matlab .* operator in R
Another (simpler) way that I can think is that y * matrix(rep(z,3), ncol=ncol(y), byrow=TRUE) [,1] [,2] [1,]00 [2,]6 -3 [3,] 12 -6 I hope this helps. Chel Hee Lee On 14-11-19 08:43 AM, Ruima E. wrote: Thank you Chel Hee. Isn't there a simpler way to do so? On Wed, Nov 19, 2014 at 3:35 PM, Chel Hee Lee chl...@mail.usask.ca wrote: y = matrix(cbind(c(0, 0.5, 1),c(0, 0.5, 1)),ncol=2) z = matrix(c(12, -6),ncol=2) t(apply(y, 1, function(x) x*z)) [,1] [,2] [1,]00 [2,]6 -3 [3,] 12 -6 I hope this helps. Chel Hee Lee On 14-11-19 08:22 AM, Ruima E. wrote: Hi, I have this: y = matrix(cbind(c(0, 0.5, 1),c(0, 0.5, 1)),ncol=2) z = matrix(c(12, -6),ncol=2) In matlab I would do this y .* x I would get this in matlab ans 0-0 6-3 12 -6 What is the equivalent in R? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Equivalent to matlab .* operator in R
y = matrix(cbind(c(0, 0.5, 1),c(0, 0.5, 1)),ncol=2) z = matrix(c(12, -6),ncol=2) t(apply(y, 1, function(x) x*z)) [,1] [,2] [1,]00 [2,]6 -3 [3,] 12 -6 I hope this helps. Chel Hee Lee On 14-11-19 08:22 AM, Ruima E. wrote: Hi, I have this: y = matrix(cbind(c(0, 0.5, 1),c(0, 0.5, 1)),ncol=2) z = matrix(c(12, -6),ncol=2) In matlab I would do this y .* x I would get this in matlab ans 0-0 6-3 12 -6 What is the equivalent in R? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Computing 'exp(1e3)*0' correctly....
I very appreciate for good comments and tip regarding my question. All postings are excellent to know when I am writing such expression in R. Thank you so much, and my question is completely resolved from all your postings. On Sun, 2012-09-02 at 00:50 +0100, Rui Barradas wrote: Em 02-09-2012 00:10, Jeff Newmiller escreveu: I disagree that this answer is wrong. If you want a mathematically correct answer you are going to have to obtain it by applying intelligence to the algorithm in which this calculation occurred. Logarithms are the product of intelligence. And the standard trick to make this sort of computation. x - 1e3 exp(x + log(0)) # zero x - 1e300 exp(x + log(0)) # zero Rui Barradas This is not a mailing list about numerical methods in general, so it probably isn't appropriate to pursue that conversation here. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. CHEL HEE LEE gnust...@gmail.com wrote: I have some trouble to deal the value of 'NaN'. For example, exp(1e3) [1] Inf exp(1e3)*0 [1] NaN The correct answer should be 0 rather than NaN. I will very appreciate if anyone can share some technique to get a correct answer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Computing 'exp(1e3)*0' correctly....
I have some trouble to deal the value of 'NaN'. For example, exp(1e3) [1] Inf exp(1e3)*0 [1] NaN The correct answer should be 0 rather than NaN. I will very appreciate if anyone can share some technique to get a correct answer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Drawing a simplex
Thank you, David. I found some good stuffs for which I have been looking. On Sun, 2012-08-26 at 09:01 -0700, David Winsemius wrote: On Aug 25, 2012, at 9:00 PM, Chel Hee Lee wrote: I will very appreciate if anyone can provide some materials to draw a simplex plot of a Dirichlet distribution in R as shown in the page at http://en.wikipedia.org/wiki/File:Dirichlet_distributions.png . Go to: http://www.rseek.org search on: dirichlet surface Choose the Support lists panel. There are worked examples there. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Drawing a simplex
I will very appreciate if anyone can provide some materials to draw a simplex plot of a Dirichlet distribution in R as shown in the page at http://en.wikipedia.org/wiki/File:Dirichlet_distributions.png . __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] General question on the message with non zero exit status
Oh... I see!!! I very appreciate for your clear explanation! Thank you, Uwe Ligges. -- View this message in context: http://r.789695.n4.nabble.com/General-question-on-the-message-with-non-zero-exit-status-tp4551438p4568839.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] General question on the message with non zero exit status
I have a general question how to understand the message with non-zero exit status when new package is installed. Based on my experience, this message implies a package dependence. Am I correct to understand this message? Are there anyone who can provide some reference or explain details about the message with non zero exit status? I very appreciate for your kindness in advance. -- View this message in context: http://r.789695.n4.nabble.com/General-question-on-the-message-with-non-zero-exit-status-tp4551438p4551438.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.