Re: [R] ANOVA repeated mesures
Hi You have only single value for each participant in each gruppo and AFAIK you can not do statistic on single value. You can check differences among participants fit-lm(valor~participantes, data=df2) fit-lm(valor~participantes, data=df2) anova(fit) Analysis of Variance Table Response: valor Df Sum Sq Mean Sq F value Pr(F) participantes 7 5.167 0.7381 0.3163 0.9358 Residuals 16 37.333 2. and in groups fit-lm(valor~grupo, data=df2) anova(fit) Analysis of Variance Table Response: valor Df Sum Sq Mean Sq F valuePr(F) grupo 2 22.75 11.3750 12.095 0.0003202 *** Residuals 21 19.75 0.9405 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ma Teresa Martinez Soriano Sent: Wednesday, December 18, 2013 4:17 PM To: r-help@r-project.org Subject: [R] ANOVA repeated mesures Hi to everyone, I am tring to make a Anova with repeated measures,my data set looks like: participantes - c(1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8) grupo - factor(c(rep(A, 8), rep(B, 8), rep(C, 8)))valor - c(1, 2, 4, 1, 1, 2, 2, 3, 3, 4, 4, 2, 3, 4, 4, 3, 4, 5, 3, 5, 5, 3, 4, 6)df2 - data.frame(participantes, grupo, valor) I want to find if there is differences in the grupo in each participant. I don't know how to find this p-value for each participant, could you help me, please??Thanks a lot [[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] Significance of spectral peaks
Dear useRs, I have a time series of length approcimately 55. Is it possible to find the significance of fft spectral peaks with R? thank you -- Nuncio.M Scientist National Center for Antarctic and Ocean research Head land Sada Vasco da Gamma Goa-403804 ph off 91 832 2525636 ph: cell 91 9890357423 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Knitr, ggplot and consistent fonts
I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE, fig.height=2.5, fig.cap=Density plot with no fig.width argument, results='hide', fig.pos='ht'= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figWidth, echo=FALSE, fig.height=2.5, fig.width = 3, fig.cap=Density plot with fig.width=3, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthBig, echo=FALSE, fig.height=2.5, out.width = 12cm, fig.cap=Density plot with out.width=12cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthSmall, echo=FALSE, fig.height=2.5, out.width = 8cm, fig.cap=Density plot with out.width=8cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ \end{document} On Sun, Dec 22, 2013 at 11:59 PM, Duncan Mackay dulca...@bigpond.comwrote: Hi Daniel I tried it in Sweave after modifying it for Sweave and a similar thing for Latex but R crashed. I think there is an embedded character/s before the first chunk and in the first chunk. Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Kane Sent: Monday, 23 December 2013 04:19 To: Daniel Haugstvedt; r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Daniel, For some reason I cannot get your example to work. The problem is in the code chunk but I have no idea what is happening. The code is running perfectly in R, itself but LaTeX seems to be choking when it hits the first ggplot statement, that is the one in plot-figHeight= The message I am getting is: Missing $ inserted inserted text $ ggplot(df, aes(x=x)) = geom_ and my knowledge of LateX is not enough to figure out the problem. I tried stripping out most of the LaTeX specific verbiage in the code chunk and running the code in LyX which I use rather than plain vanilla LaTeX and I still cannot get it to work. It is almost as if there is some hidden character in the in that piece of code since I can duplicate the code myself and I even pasted in most of the geom_histogram code into my code chunk and it runs. John Kane Kingston ON Canada -Original Message- From: daniel.haugstv...@gmail.com Sent: Sun, 22 Dec 2013 12:42:50 +0100 To: r-help@r-project.org Subject: [R] Knitr, ggplot and consistent fonts Dear R-help I am using Knitr and ggplot to draft an article and have now started to improve on the layout and graphics. So far I have not been able to maintain the same font size for labels in all my figures. My goal is to be able to change the width of the figures while maintaining the same font. This works for the height parameter (example not included). In the true document I also use tikz, but the problem can be reproduced without it. I know the question is very specific, but my understanding is that this combination of packages is common. (They are really great. Keep up the good work.) There has to be others facing the same problem and someone must have found a nice solution.
Re: [R] Knitr, ggplot and consistent fonts
Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE, fig.height=2.5, fig.cap=Density plot with no fig.width argument, results='hide', fig.pos='ht'= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figWidth, echo=FALSE, fig.height=2.5, fig.width = 3, fig.cap=Density plot with fig.width=3, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthBig, echo=FALSE, fig.height=2.5, out.width = 12cm, fig.cap=Density plot with out.width=12cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthSmall, echo=FALSE, fig.height=2.5, out.width = 8cm, fig.cap=Density plot with out.width=8cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ \end{document} On Sun, Dec 22, 2013 at 11:59 PM, Duncan Mackay dulca...@bigpond.com wrote: Hi Daniel I tried it in Sweave after modifying it for Sweave and a similar thing for Latex but R crashed. I think there is an embedded character/s before the first chunk and in the first chunk. Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Kane Sent: Monday, 23 December 2013 04:19 To: Daniel Haugstvedt; r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Daniel, For some reason I cannot get your example to work. The problem is in the code chunk but I have no idea what is happening. The code is running perfectly in R, itself but LaTeX seems to be choking when it hits the first ggplot statement, that is the one in plot-figHeight= The message I am getting is: Missing $ inserted inserted text $ ggplot(df, aes(x=x)) = geom_ and my knowledge of LateX is not enough to figure out the problem. I tried stripping out most of the LaTeX specific verbiage in the code chunk and running the code in LyX which I use rather than plain vanilla LaTeX and I still cannot get it to work. It is almost as if there is some hidden character in the in that piece of code since I can duplicate the code myself and I even pasted in most of the geom_histogram code into my code chunk and it runs. John Kane Kingston ON Canada -Original Message- From: daniel.haugstv...@gmail.com Sent: Sun, 22 Dec 2013 12:42:50
Re: [R] Significance of spectral peaks
Hello, See ?redfit from dplR, for example. HTH, Pascal On 23 December 2013 18:46, nuncio m nunci...@gmail.com wrote: Dear useRs, I have a time series of length approcimately 55. Is it possible to find the significance of fft spectral peaks with R? thank you -- Nuncio.M Scientist National Center for Antarctic and Ocean research Head land Sada Vasco da Gamma Goa-403804 ph off 91 832 2525636 ph: cell 91 9890357423 [[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. -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] New book release: Data Mining Applications with R
Book title: Data Mining Applications with R Editors: Yanchang Zhao, Yonghua Cen Publisher: Elsevier Publish date: December 2013 ISBN: 978-0-12-411511-8 Length: 514 pages URL: http://www.rdatamining.com/books/dmar An edited book titled Data Mining Applications with R was released in December 2013, which features 15 real-word applications on data mining with R. A preview of the book is available on Google Books at http://books.google.com.au/books?id=nYpqQBAJprintsec=frontcoversource=gbs_ge_summary_rcad=0. R code, data and color figures for the book can be downloaded at http://www.rdatamining.com/books/dmar/code. Buy the book on - Amazon: http://www.amazon.com/Data-Mining-Applications-Yanchang-Zhao/dp/012411511X - Elsevier: http://store.elsevier.com/Data-Mining-Applications-with-R/Yanchang-Zhao/isbn-9780124115118/ - Google Books: http://books.google.com.au/books/about/Data_Mining_Applications_with_R.html?id=nYpqQBAJ Below is its table of contents. Foreword Graham Williams Chapter 1 Power Grid Data Analysis with R and Hadoop Terence Critchlow, Ryan Hafen, Tara Gibson and Kerstin Kleese van Dam Chapter 2 Picturing Bayesian Classifiers: A Visual Data Mining Approach to Parameters Optimization Giorgio Maria Di Nunzio and Alessandro Sordoni Chapter 3 Discovery of emergent issues and controversies in Anthropology using text mining, topic modeling and social network analysis of microblog content Ben Marwick Chapter 4 Text Mining and Network Analysis of Digital Libraries in R Eric Nguyen Chapter 5 Recommendation systems in R Saurabh Bhatnagar Chapter 6 Response Modeling in Direct Marketing: A Data Mining Based Approach for Target Selection Sadaf Hossein Javaheri, Mohammad Mehdi Sepehri and Babak Teimourpour Chapter 7 Caravan Insurance Policy Customer Profile Modeling with R Mining Mukesh Patel and Mudit Gupta Chapter 8 Selecting Best Features for Predicting Bank Loan Default Zahra Yazdani, Mohammad Mehdi Sepehri and Babak Teimourpour Chapter 9 A Choquet Ingtegral Toolbox and its Application in Customer's Preference Analysis Huy Quan Vu, Gleb Beliakov and Gang Li Chapter 10 A Real-Time Property Value Index based on Web Data Fernando Tusell, Maria Blanca Palacios, María Jesús Bárcena and Patricia Menéndez Chapter 11 Predicting Seabed Hardness Using Random Forest in R Jin Li, Justy Siwabessy, Zhi Huang, Maggie Tran and Andrew Heap Chapter 12 Supervised classification of images, applied to plankton samples using R and zooimage Kevin Denis and Philippe Grosjean Chapter 13 Crime analyses using R Madhav Kumar, Anindya Sengupta and Shreyes Upadhyay Chapter 14 Football Mining with R Maurizio Carpita, Marco Sandri, Anna Simonetto and Paola Zuccolotto Chapter 15 Analyzing Internet DNS(SEC) Traffic with R for Resolving Platform Optimization Emmanuel Herbert, Daniel Migault, Stephane Senecal, Stanislas Francfort and Maryline Laurent Regards Yanchang Zhao PhD, Data Miner RDataMining.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 2 factor split and lapply
Sure, here is a reproducible example: testframe-data.frame(factor1=c(a,b,a),factor2=c(1,2,2),data=c(3.34,4.2,2.1)) splitframe-split(testframe,list(factor1=testframe$factor1,factor2=testframe$factor2)) lapply(splitframe,function(x)mean(x[,data])) The above lapply returns $a.1 [1] 3.34 $b.1 [1] NaN $a.2 [1] 2.1 $b.2 [1] 4.2 The results are correct but not presented in a format I prefer... Factor1 and factor2 are combined into a single factor, which is not desired. I want to keep them seperate. Ideally, a table output as below. a b 1 3.34 NaN 2 2.1 4.2 How can I achieve this please? On 23 Dec 2013, at 00:44, Bert Gunter gunter.ber...@gene.com wrote: I believe you missed ?tapply which does what you want I think (in the absence of a reproducible example one cannot be sure). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Sun, Dec 22, 2013 at 3:54 PM, Onur Uncu onuru...@gmail.com wrote: R Users, I have a data frame which I split using 2 factors using the split function: split(datframe, list(f=factor1, f2=factor2)); I then used lapply to get some summary statistics grouped by factor1 and factor2. I now want to change the appearance of this output. I want to get a 2 dimensional table where columns represent values of factor1, rows represent values of factor2 and the entries on the table represent the summary results that were calculated by lapply. I tried as.table() function but did not help. It seems the problem is that R combined factor1 and factor 2 into one factor when I used list(f=factor1, f2=factor2) in the split function. So R is now unable to treat them as 2 different factors in order to put them on row and columns of a table... Any ideas how I can achieve the desired table? Thanks for your help. [[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] 2 factor split and lapply
Hi, You could try: library(reshape2) dcast(as.data.frame(as.table(by(testframe[,3],testframe[,-3],mean))),factor2~factor1,value.var=Freq) # factor2 a b #1 1 3.34 NA #2 2 2.10 4.2 A.K. On Monday, December 23, 2013 9:24 AM, Onur Uncu onuru...@gmail.com wrote: Sure, here is a reproducible example: testframe-data.frame(factor1=c(a,b,a),factor2=c(1,2,2),data=c(3.34,4.2,2.1)) splitframe-split(testframe,list(factor1=testframe$factor1,factor2=testframe$factor2)) lapply(splitframe,function(x)mean(x[,data])) The above lapply returns $a.1 [1] 3.34 $b.1 [1] NaN $a.2 [1] 2.1 $b.2 [1] 4.2 The results are correct but not presented in a format I prefer... Factor1 and factor2 are combined into a single factor, which is not desired. I want to keep them seperate. Ideally, a table output as below. a b 1 3.34 NaN 2 2.1 4.2 How can I achieve this please? On 23 Dec 2013, at 00:44, Bert Gunter gunter.ber...@gene.com wrote: I believe you missed ?tapply which does what you want I think (in the absence of a reproducible example one cannot be sure). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Sun, Dec 22, 2013 at 3:54 PM, Onur Uncu onuru...@gmail.com wrote: R Users, I have a data frame which I split using 2 factors using the split function: split(datframe, list(f=factor1, f2=factor2)); I then used lapply to get some summary statistics grouped by factor1 and factor2. I now want to change the appearance of this output. I want to get a 2 dimensional table where columns represent values of factor1, rows represent values of factor2 and the entries on the table represent the summary results that were calculated by lapply. I tried as.table() function but did not help. It seems the problem is that R combined factor1 and factor 2 into one factor when I used list(f=factor1, f2=factor2) in the split function. So R is now unable to treat them as 2 different factors in order to put them on row and columns of a table... Any ideas how I can achieve the desired table? Thanks for your help. [[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] 2 factor split and lapply
HI, I think this will be more appropriate. dcast(testframe,factor2~factor1,value.var=data,mean) factor2 a b 1 1 3.34 NaN 2 2 2.10 4.2 A.K. On Monday, December 23, 2013 9:37 AM, arun smartpink...@yahoo.com wrote: Hi, You could try: library(reshape2) dcast(as.data.frame(as.table(by(testframe[,3],testframe[,-3],mean))),factor2~factor1,value.var=Freq) # factor2 a b #1 1 3.34 NA #2 2 2.10 4.2 A.K. On Monday, December 23, 2013 9:24 AM, Onur Uncu onuru...@gmail.com wrote: Sure, here is a reproducible example: testframe-data.frame(factor1=c(a,b,a),factor2=c(1,2,2),data=c(3.34,4.2,2.1)) splitframe-split(testframe,list(factor1=testframe$factor1,factor2=testframe$factor2)) lapply(splitframe,function(x)mean(x[,data])) The above lapply returns $a.1 [1] 3.34 $b.1 [1] NaN $a.2 [1] 2.1 $b.2 [1] 4.2 The results are correct but not presented in a format I prefer... Factor1 and factor2 are combined into a single factor, which is not desired. I want to keep them seperate. Ideally, a table output as below. a b 1 3.34 NaN 2 2.1 4.2 How can I achieve this please? On 23 Dec 2013, at 00:44, Bert Gunter gunter.ber...@gene.com wrote: I believe you missed ?tapply which does what you want I think (in the absence of a reproducible example one cannot be sure). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Sun, Dec 22, 2013 at 3:54 PM, Onur Uncu onuru...@gmail.com wrote: R Users, I have a data frame which I split using 2 factors using the split function: split(datframe, list(f=factor1, f2=factor2)); I then used lapply to get some summary statistics grouped by factor1 and factor2. I now want to change the appearance of this output. I want to get a 2 dimensional table where columns represent values of factor1, rows represent values of factor2 and the entries on the table represent the summary results that were calculated by lapply. I tried as.table() function but did not help. It seems the problem is that R combined factor1 and factor 2 into one factor when I used list(f=factor1, f2=factor2) in the split function. So R is now unable to treat them as 2 different factors in order to put them on row and columns of a table... Any ideas how I can achieve the desired table? Thanks for your help. [[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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 2 factor split and lapply
As I said, ?tapply gives you an answer (without using other packages) . Read it. -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Mon, Dec 23, 2013 at 6:22 AM, Onur Uncu onuru...@gmail.com wrote: Sure, here is a reproducible example: testframe-data.frame(factor1=c(a,b,a),factor2=c(1,2,2),data=c(3.34,4.2,2.1)) splitframe-split(testframe,list(factor1=testframe$factor1,factor2=testframe$factor2)) lapply(splitframe,function(x)mean(x[,data])) The above lapply returns $a.1 [1] 3.34 $b.1 [1] NaN $a.2 [1] 2.1 $b.2 [1] 4.2 The results are correct but not presented in a format I prefer... Factor1 and factor2 are combined into a single factor, which is not desired. I want to keep them seperate. Ideally, a table output as below. a b 1 3.34 NaN 2 2.1 4.2 How can I achieve this please? On 23 Dec 2013, at 00:44, Bert Gunter gunter.ber...@gene.com wrote: I believe you missed ?tapply which does what you want I think (in the absence of a reproducible example one cannot be sure). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Sun, Dec 22, 2013 at 3:54 PM, Onur Uncu onuru...@gmail.com wrote: R Users, I have a data frame which I split using 2 factors using the split function: split(datframe, list(f=factor1, f2=factor2)); I then used lapply to get some summary statistics grouped by factor1 and factor2. I now want to change the appearance of this output. I want to get a 2 dimensional table where columns represent values of factor1, rows represent values of factor2 and the entries on the table represent the summary results that were calculated by lapply. I tried as.table() function but did not help. It seems the problem is that R combined factor1 and factor 2 into one factor when I used list(f=factor1, f2=factor2) in the split function. So R is now unable to treat them as 2 different factors in order to put them on row and columns of a table... Any ideas how I can achieve the desired table? Thanks for your help. [[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] R command execution at specific time from within R
Hello, I am trying to write a code that executes an R command at specific time intervals. É want R to do that instead of the operating system. Any help/pointer extremely welcome. Thanks in advance, Costas [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unable to install RcppEigen package due to Rcpp dependency issues
Rewarp rewarp at gmail.com writes: I am trying to install RcppEigen, which depends on Rcpp. Here's what the terminal says: install.packages(RcppEigen) [...] g++ -shared -o RcppEigen.so RcppEigen.o fastLm.o -L/home/rewarp/R/x86_64-pc-linux-gnu-library/3.0/Rcpp/lib -lRcpp -Wl,-rpath,/home/rewarp/R/x86_64-pc-linux-gnu-library/3.0/Rcpp/lib -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR /usr/bin/ld: cannot find -llapack /usr/bin/ld: cannot find -lblas collect2: ld returned 1 exit status You need to install the required libraries. It looks like you may be on Debian or Ubuntu so try $ sudo apt-get install r-base-dev which should pull these in. Support for Rcpp and friends is provided on the rcpp-devel list. Dirk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Knitr, ggplot and consistent fonts
Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE, fig.height=2.5, fig.cap=Density plot with no fig.width argument, results='hide', fig.pos='ht'= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figWidth, echo=FALSE, fig.height=2.5, fig.width = 3, fig.cap=Density plot with fig.width=3, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthBig, echo=FALSE, fig.height=2.5, out.width = 12cm, fig.cap=Density plot with out.width=12cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthSmall, echo=FALSE, fig.height=2.5, out.width = 8cm, fig.cap=Density plot with out.width=8cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ \end{document} On Sun, Dec 22, 2013 at 11:59 PM, Duncan Mackay dulca...@bigpond.com wrote: Hi Daniel I tried it in Sweave after modifying it for Sweave and a similar thing for Latex but R crashed. I think there is an embedded character/s before the first chunk and in the first chunk. Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Kane Sent: Monday, 23 December 2013 04:19 To: Daniel Haugstvedt; r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Daniel, For some reason I cannot get your example
Re: [R] Knitr, ggplot and consistent fonts
If the problem seems to be non-ASCII characters, then the first investigation step is to use the R functions ?tools::showNonASCII ?tools::showNonASCIIfile On Mon, Dec 23, 2013 at 11:37 AM, John Kane jrkrid...@inbox.com wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE, fig.height=2.5, fig.cap=Density plot with no fig.width argument, results='hide', fig.pos='ht'= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figWidth, echo=FALSE, fig.height=2.5, fig.width = 3, fig.cap=Density plot with fig.width=3, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthBig, echo=FALSE, fig.height=2.5, out.width = 12cm, fig.cap=Density plot with out.width=12cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthSmall, echo=FALSE, fig.height=2.5, out.width = 8cm, fig.cap=Density plot with out.width=8cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ \end{document} On Sun, Dec 22, 2013 at 11:59 PM, Duncan Mackay dulca...@bigpond.com wrote: Hi Daniel I tried it in Sweave after modifying it for Sweave and a similar thing for Latex but R crashed. I think there is an embedded character/s before the first chunk and in the first chunk. Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Kane Sent: Monday, 23 December 2013 04:19 To: Daniel Haugstvedt;
[R] error in ca.jo
Dear all, I fit co-integration function between two integrated variables(y1 and y2) over different grid points: for(i in 1:N1){ for(j in 1:N2){ co-ca.jo(data.frame(cbind(y2[i,j,],y1[i,j,])),type=trace, K=2, spec=transitory,ecdet=const,season=NULL,dumvar=NULL) }} I have already extracted grid points with integrated time series. However, when I run the above function, there happens an error Error in solve.default(t(V) %*% SKK %*% V) : system is computationally singular: reciprocal condition number = 1.10221e-35 May you suggest me how to fix this problem please? Thanks in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Knitr, ggplot and consistent fonts
Does not seem to be. I 'think' I removed all the line breaks and it still is not compiling. Thanks for the suggestion. I had not bothered to paste the = text into RStudio and since TexMaker has an automatic wrap, I would never have noticed it. John Kane Kingston ON Canada -Original Message- From: fel...@gmail.com Sent: Mon, 23 Dec 2013 10:53:59 -0600 To: jrkrid...@inbox.com Subject: Re: [R] Knitr, ggplot and consistent fonts Hi, chiming in. Pasted the code in R studio and the format parser wouldn't mark the R code chunks. It was because there were line breaks in the middle of chunk options tags. Couldn't test if removing line breaks works, but maybe that's the source of the problem? On Mon, Dec 23, 2013 at 10:37 AM, John Kane jrkrid...@inbox.com wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE, fig.height=2.5, fig.cap=Density plot with no fig.width argument, results='hide', fig.pos='ht'= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figWidth, echo=FALSE, fig.height=2.5, fig.width = 3, fig.cap=Density plot with fig.width=3, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthBig, echo=FALSE, fig.height=2.5, out.width = 12cm, fig.cap=Density plot with out.width=12cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthSmall, echo=FALSE, fig.height=2.5, out.width = 8cm, fig.cap=Density plot with out.width=8cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill =
Re: [R] Knitr, ggplot and consistent fonts
Thanks Richard. I did not realise such a function existed. Assuming I am using it correctly I do get an error though not where I was expecting it. Anyway the code below returns an error library(tools) showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)) Results Error: unexpected symbol in: showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black John Kane Kingston ON Canada -Original Message- From: r...@temple.edu Sent: Mon, 23 Dec 2013 11:44:42 -0500 To: jrkrid...@inbox.com Subject: Re: [R] Knitr, ggplot and consistent fonts If the problem seems to be non-ASCII characters, then the first investigation step is to use the R functions ?tools::showNonASCII ?tools::showNonASCIIfile On Mon, Dec 23, 2013 at 11:37 AM, John Kane jrkrid...@inbox.com wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE, fig.height=2.5, fig.cap=Density plot with no fig.width argument, results='hide', fig.pos='ht'= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figWidth, echo=FALSE, fig.height=2.5, fig.width = 3, fig.cap=Density plot with fig.width=3, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthBig, echo=FALSE, fig.height=2.5, out.width = 12cm, fig.cap=Density plot with out.width=12cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthSmall, echo=FALSE, fig.height=2.5, out.width = 8cm, fig.cap=Density plot with out.width=8cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..),
Re: [R] Knitr, ggplot and consistent fonts
On 13-12-23 12:40 PM, John Kane wrote: Thanks Richard. I did not realise such a function existed. Assuming I am using it correctly I do get an error though not where I was expecting it. Anyway the code below returns an error library(tools) showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)) Results Error: unexpected symbol in: showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black You get that error because you're using double quotes around a string containing double quotes, and not escaping them. With that string, using single quotes on the outside should be fine: showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)') Duncan Murdoch John Kane Kingston ON Canada -Original Message- From: r...@temple.edu Sent: Mon, 23 Dec 2013 11:44:42 -0500 To: jrkrid...@inbox.com Subject: Re: [R] Knitr, ggplot and consistent fonts If the problem seems to be non-ASCII characters, then the first investigation step is to use the R functions ?tools::showNonASCII ?tools::showNonASCIIfile On Mon, Dec 23, 2013 at 11:37 AM, John Kane jrkrid...@inbox.com wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE, fig.height=2.5, fig.cap=Density plot with no fig.width argument, results='hide', fig.pos='ht'= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figWidth, echo=FALSE, fig.height=2.5, fig.width = 3, fig.cap=Density plot with fig.width=3, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthBig, echo=FALSE, fig.height=2.5, out.width = 12cm, fig.cap=Density plot with out.width=12cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthSmall,
Re: [R] Knitr, ggplot and consistent fonts
Thanks Duncan. I had the feeling I was doing something wrong but did not realise it was that stupid. showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)') now runs and does what the help page seems to imply: Nothing. From the showNonASCII help page: The elements of x containing non-ASCII characters will be returned invisibly. One gets a result one does not see? Does one have to explicitly capture the result somehow? I really have not the faintest idea of what the example from the help page is doing. John Kane Kingston ON Canada -Original Message- From: murdoch.dun...@gmail.com Sent: Mon, 23 Dec 2013 12:51:43 -0500 To: jrkrid...@inbox.com, r...@temple.edu Subject: Re: [R] Knitr, ggplot and consistent fonts On 13-12-23 12:40 PM, John Kane wrote: Thanks Richard. I did not realise such a function existed. Assuming I am using it correctly I do get an error though not where I was expecting it. Anyway the code below returns an error library(tools) showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)) Results Error: unexpected symbol in: showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black You get that error because you're using double quotes around a string containing double quotes, and not escaping them. With that string, using single quotes on the outside should be fine: showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)') Duncan Murdoch John Kane Kingston ON Canada -Original Message- From: r...@temple.edu Sent: Mon, 23 Dec 2013 11:44:42 -0500 To: jrkrid...@inbox.com Subject: Re: [R] Knitr, ggplot and consistent fonts If the problem seems to be non-ASCII characters, then the first investigation step is to use the R functions ?tools::showNonASCII ?tools::showNonASCIIfile On Mon, Dec 23, 2013 at 11:37 AM, John Kane jrkrid...@inbox.com wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE,
[R] Inserting color into an irregular grid comprised of polygons
useRs, The example code below is an attempt to plot some spatial data that is associated with an irregularly spaced grid. The last thing I hope to do with this example is assign the color of each polygon generated in the nested for loop based on the value contained in vals. The R code I'm seeking help with appears at the end of the example code below. How would one assign a color to the polygon at position [j,k] that is appropriately scaled to the total range of vals? The comment appearing before the last line of commented-out code in the example below provides a little more information. Thanks, Eric ## Example R Code library(gsubfn) #uses paste0 func x.space - c(0.1384,0.2767,0.2767,0.2767,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.1384,0.2767,0.2767,0.2767,0.2767,0.2767,0.2767,0.2767,0.415,0.415,0.415,0.415,0.415,0.415,0.415, 0.2767, 0.2767) z.space - c(0.23503518,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.050285053,0.04901495,0.0993,0.042104937,0.057195064,0.059790898,0.0395091,0.03392482,0.022215653,0.043159526,0.048876755,0.050423246,0.049547195,0.049752805,0.050217632,0.049082365,0.0993,0.046798017,0.052501984,0.052228954,0.047071047,0.052899394,0.046400607,0.06309083,0.036209174,0.0993,0.050150216,0.04914978,0.055581152,0.043718845,0.0993,0.0993,0.0993,0.0993,0.0993,0.1986,0.1986,0.1986,0.1986,0.1986,0.3972,0.3972,0.3972,0.4965,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.4965,0.4333665,0.44272622,0.5141073,0.5958,0.4965,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.1986,0.1986) x.range - c(0,sum(x.space)) z.range - c(0,sum(z.space)) z.sum - sum(z.space) vals - matrix(c(0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.684E+01, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.660E+01,0.679E+01,0.683E+01,0.684E+01, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.656E+01,0.679E+01,0.683E+01,0.684E+01, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.603E+01,0.655E+01,0.679E+01,0.683E+01,0.684E+01, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.632E+01,0.656E+01,0.680E+01,0.684E+01,0.684E+01,
Re: [R] 2 factor split and lapply
Hi, No problem. If you have two columns and need the ratio, you could use ?transform testframe$data1 - c(2.24,6.5,4.34) dcast(transform(testframe,ratio=data/data1),factor2~factor1,value.var=ratio,mean) # factor2 a b #1 1 1.491071 NaN #2 2 0.483871 0.6461538 A.K. On Monday, December 23, 2013 10:49 AM, Onur Uncu onuru...@gmail.com wrote: Thank you Arun. May I ask a follow up question? What if the function needed to take multiple arguments? So, instead of mean, suppose the function was function(x,y){x/y} and suppose x and y inputs were 2 columns of a data frame. In other words, is there an mapply type function under reshape package? thnks On Mon, Dec 23, 2013 at 2:45 PM, arun smartpink...@yahoo.com wrote: HI, I think this will be more appropriate. dcast(testframe,factor2~factor1,value.var=data,mean) factor2 a b 1 1 3.34 NaN 2 2 2.10 4.2 A.K. On Monday, December 23, 2013 9:37 AM, arun smartpink...@yahoo.com wrote: Hi, You could try: library(reshape2) dcast(as.data.frame(as.table(by(testframe[,3],testframe[,-3],mean))),factor2~factor1,value.var=Freq) # factor2 a b #1 1 3.34 NA #2 2 2.10 4.2 A.K. On Monday, December 23, 2013 9:24 AM, Onur Uncu onuru...@gmail.com wrote: Sure, here is a reproducible example: testframe-data.frame(factor1=c(a,b,a),factor2=c(1,2,2),data=c(3.34,4.2,2.1)) splitframe-split(testframe,list(factor1=testframe$factor1,factor2=testframe$factor2)) lapply(splitframe,function(x)mean(x[,data])) The above lapply returns $a.1 [1] 3.34 $b.1 [1] NaN $a.2 [1] 2.1 $b.2 [1] 4.2 The results are correct but not presented in a format I prefer... Factor1 and factor2 are combined into a single factor, which is not desired. I want to keep them seperate. Ideally, a table output as below. a b 1 3.34 NaN 2 2.1 4.2 How can I achieve this please? On 23 Dec 2013, at 00:44, Bert Gunter gunter.ber...@gene.com wrote: I believe you missed ?tapply which does what you want I think (in the absence of a reproducible example one cannot be sure). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Sun, Dec 22, 2013 at 3:54 PM, Onur Uncu onuru...@gmail.com wrote: R Users, I have a data frame which I split using 2 factors using the split function: split(datframe, list(f=factor1, f2=factor2)); I then used lapply to get some summary statistics grouped by factor1 and factor2. I now want to change the appearance of this output. I want to get a 2 dimensional table where columns represent values of factor1, rows represent values of factor2 and the entries on the table represent the summary results that were calculated by lapply. I tried as.table() function but did not help. It seems the problem is that R combined factor1 and factor 2 into one factor when I used list(f=factor1, f2=factor2) in the split function. So R is now unable to treat them as 2 different factors in order to put them on row and columns of a table... Any ideas how I can achieve the desired table? Thanks for your help. [[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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Inserting color into an irregular grid comprised of polygons
Recode val into a set of integers equal to the number of color levels you want and then use heat.colors(), terrain.colors(), or a similar function to define a vector of continuous colors. # cut makes it easy to split up the data but it creates a factor # and loses the matrix dimensions so we have to convert back. cv - matrix(as.integer(cut(vals, breaks=10)), dim(vals)) pal - heat.colors(10) Then use polygon(x=x, y=y, border=NA, col=pal[cv[k, j]]) Note: border=NA, not NULL David Carlson -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Morway, Eric Sent: Monday, December 23, 2013 12:11 PM To: R mailing list Subject: [R] Inserting color into an irregular grid comprised of polygons useRs, The example code below is an attempt to plot some spatial data that is associated with an irregularly spaced grid. The last thing I hope to do with this example is assign the color of each polygon generated in the nested for loop based on the value contained in vals. The R code I'm seeking help with appears at the end of the example code below. How would one assign a color to the polygon at position [j,k] that is appropriately scaled to the total range of vals? The comment appearing before the last line of commented-out code in the example below provides a little more information. Thanks, Eric ## Example R Code library(gsubfn) #uses paste0 func x.space - c(0.1384,0.2767,0.2767,0.2767,0.1384,0.13833 334,0.1384,0.1384,0.1384,0.1384,0.1384,0.138 4,0.1384,0.1384,0.1384,0.1384,0.1384,0.1 384,0.1384,0.1384,0.1384,0.1384,0.1384,0 .1384,0.1384,0.1384,0.1384,0.1384,0.1384 ,0.1384,0.1384,0.1384,0.1384,0.1384,0.138333 34,0.1384,0.2767,0.2767,0.2767,0.2767,0.2766 6667,0.2767,0.2767,0.415,0.415,0.415,0.415,0.415,0.415,0 .415, 0.2767, 0.2767) z.space - c(0.23503518,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.0993,0. 0993,0.0993,0.0993,0.0993,0.0993,0.0993,0.050285053,0.04901495,0 .0993,0.042104937,0.057195064,0.059790898,0.0395091,0.03392482,0 .022215653,0.043159526,0.048876755,0.050423246,0.049547195,0.049 752805,0.050217632,0.049082365,0.0993,0.046798017,0.052501984,0. 052228954,0.047071047,0.052899394,0.046400607,0.06309083,0.03620 9174,0.0993,0.050150216,0.04914978,0.055581152,0.043718845,0.099 3,0.0993,0.0993,0.0993,0.0993,0.1986,0.1986,0.1986,0.1986,0.1986 ,0.3972,0.3972,0.3972,0.4965,0.3972,0.3972,0.3972,0.3972,0.3972, 0.3972,0.3972,0.3972,0.4965,0.4333665,0.44272622,0.5141073,0.595 8,0.4965,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972 ,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972,0.3972, 0.3972,0.1986,0.1986) x.range - c(0,sum(x.space)) z.range - c(0,sum(z.space)) z.sum - sum(z.space) vals - matrix(c(0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000 E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00 ,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.0 00E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+ 00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0 .000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000 E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00 ,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.0 00E+00,0.684E+01, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.00 0E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+0 0,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0. 000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E +00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.00 0E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+0 0,0.000E+00,0.000E+00,0.000E+00,0.660E+01,0.679E+01,0.683E+01,0. 684E+01, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.00 0E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+0 0,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0. 000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E +00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.00 0E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+0 0,0.000E+00,0.000E+00,0.000E+00,0.656E+01,0.679E+01,0.683E+01,0. 684E+01, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.00 0E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+0 0,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0. 000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E +00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00, 0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.00 0E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+00,0.000E+0
Re: [R] error in ca.jo
There is a fundamental problem with your code, and there is the problem that you have (sort of) identified. The fundamental problem is that you are only going to get the results of the last call to 'ca.jo' that is done -- assuming it were to run. You presumably want to save some information from each of the computations. You can get the loops to run even when you run into an error with some combinations by using 'try' or 'tryCatch'. There is an example in Circle 8.3.13 of 'The R Inferno'. http://www.burns-stat.com/documents/books/the-r-inferno/ If you have a question related to the actual function as opposed to general problems with R, then the r-sig-finance mailing list would be appropriate (you need to subscribe before posting). I'm not sure if this is enough of a hint for you or not. If not, then trying to formulate a more explicit question might help. (There are some suggestions in Circle 9 of 'The R Inferno'.) Pat On 23/12/2013 17:07, mamush bukana wrote: Dear all, I fit co-integration function between two integrated variables(y1 and y2) over different grid points: for(i in 1:N1){ for(j in 1:N2){ co-ca.jo(data.frame(cbind(y2[i,j,],y1[i,j,])),type=trace, K=2, spec=transitory,ecdet=const,season=NULL,dumvar=NULL) }} I have already extracted grid points with integrated time series. However, when I run the above function, there happens an error Error in solve.default(t(V) %*% SKK %*% V) : system is computationally singular: reciprocal condition number = 1.10221e-35 May you suggest me how to fix this problem please? Thanks in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Patrick Burns pbu...@pburns.seanet.com twitter: @burnsstat @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of: 'Impatient R' 'The R Inferno' 'Tao Te Programming') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 command execution at specific time from within R
Costas Vorlow costas.vorlow at gmail.com writes: I am trying to write a code that executes an R command at specific time intervals. É want R to do that instead of the operating system. Any help/pointer extremely welcome. Don't do it. Just rely on cron [if you're lucky enough to be on Linux or OS X]; else rely on Windows Scheduler. Write a simple script using RScript, schedule. Thousands of people do the sample. Dirk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fwd: Calculating group means
Hi All, Sorry for what I imagine is quite a basic question. I have been trying to do is create latency averages for each state (1-8) for each participant (n=13) in each condition (1-10). I'm not sure what function I would need, or what the most efficient ay of calculating this would be. If you have any help with that I would be very grateful. structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L), conditionNo = c(1L, 1L, 1L, 1L, 1L, 1L), state = c(5L, 8L, 7L, 8L, 1L, 7L), latency = c(869L, 864L, 1004L, 801L, 611L, 679L)), .Names = c(subject, conditionNo, state, latency), row.names = 3:8, class = data.frame) Thanks again, Laura __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fitdistr and mle
Hello, i'm using R for the exploration of a time series and i'm stuck in a problem with the fitting of the distribution. What's the difference between fitdistr and mle? library(MASS) fitting - fitdistr(ret,densfun=normal) print(c(mean(ret),sd(ret))) - The output of fitdistr is: mean sd -1.526547e-05 1.692554e-02 ( 5.105564e-04) ( 3.610179e-04) - library(stats4) loglink - function(media=0, devstd=1){ -sum(dnorm(ret, mean=media, sd=devstd, log=TRUE)) } mle(loglink) - The output of mle is: Call: mle(minuslogl = loglink) Coefficients: media devstd -1.593559e-05 1.695075e-02 Thank you for the help. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Knitr, ggplot and consistent fonts
Hi, chiming in. Pasted the code in R studio and the format parser wouldn't mark the R code chunks. It was because there were line breaks in the middle of chunk options tags. Couldn't test if removing line breaks works, but maybe that's the source of the problem? On Mon, Dec 23, 2013 at 10:37 AM, John Kane jrkrid...@inbox.com wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE, fig.height=2.5, fig.cap=Density plot with no fig.width argument, results='hide', fig.pos='ht'= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figWidth, echo=FALSE, fig.height=2.5, fig.width = 3, fig.cap=Density plot with fig.width=3, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthBig, echo=FALSE, fig.height=2.5, out.width = 12cm, fig.cap=Density plot with out.width=12cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthSmall, echo=FALSE, fig.height=2.5, out.width = 8cm, fig.cap=Density plot with out.width=8cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ \end{document} On Sun, Dec 22, 2013 at 11:59 PM, Duncan Mackay dulca...@bigpond.com wrote: Hi Daniel I tried it in Sweave after modifying it for Sweave and a similar thing for Latex but R crashed. I think there is an embedded character/s before the first chunk and in the first chunk. Duncan Duncan Mackay
Re: [R] Exporting R graphics into Word without losing graph quality
Waterloo Graphics is open-source and can be used from R. Graphics can be copied and pasted in vector format to Word on Windows or Mac. There is also an SVG file save option that produces output with easy-to-use object groupings for editing an Adobe Illustrator/Inkscape. (as well as HTML5/Processing support) http://waterloo.sourceforge.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: Calculating group means
I would suggest using summaryBy() library(doBy) # sample data with you specifications subject - as.factor(rep(seq(13), each = 5)) state - as.factor(sample(c(1:8), 65, replace = TRUE)) condition - as.factor(sample(c(1:10), 65, replace = TRUE)) latency - runif(65, min=750, max = 1100) dat - data.frame(subject, state, condition, latency) summaryBy(latency~subject+state+condition, data = dat, FUN = function(x) mean(x)) Regards, On Mon, Dec 23, 2013 at 6:31 AM, Laura Bethan Thomas [lbt1] l...@aber.ac.uk wrote: Hi All, Sorry for what I imagine is quite a basic question. I have been trying to do is create latency averages for each state (1-8) for each participant (n=13) in each condition (1-10). I'm not sure what function I would need, or what the most efficient ay of calculating this would be. If you have any help with that I would be very grateful. structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L), conditionNo = c(1L, 1L, 1L, 1L, 1L, 1L), state = c(5L, 8L, 7L, 8L, 1L, 7L), latency = c(869L, 864L, 1004L, 801L, 611L, 679L)), .Names = c(subject, conditionNo, state, latency), row.names = 3:8, class = data.frame) Thanks again, Laura __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Charles Determan Integrated Biosciences PhD Candidate University of Minnesota [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: Calculating group means
Hi, You could either try: #dat1 ##dataset aggregate(latency~.,data=dat1,mean) #or library(data.table) dt1 - data.table(dat1,key=c('subject','conditionNo','state')) dt1[,mean(latency),by=c('subject','conditionNo','state')] A.K. On Monday, December 23, 2013 2:20 PM, Laura Bethan Thomas [lbt1] l...@aber.ac.uk wrote: Hi All, Sorry for what I imagine is quite a basic question. I have been trying to do is create latency averages for each state (1-8) for each participant (n=13) in each condition (1-10). I'm not sure what function I would need, or what the most efficient ay of calculating this would be. If you have any help with that I would be very grateful. structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L), conditionNo = c(1L, 1L, 1L, 1L, 1L, 1L), state = c(5L, 8L, 7L, 8L, 1L, 7L), latency = c(869L, 864L, 1004L, 801L, 611L, 679L)), .Names = c(subject, conditionNo, state, latency), row.names = 3:8, class = data.frame) Thanks again, Laura __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Knitr, ggplot and consistent fonts
On 13-12-23 1:07 PM, John Kane wrote: Thanks Duncan. I had the feeling I was doing something wrong but did not realise it was that stupid. showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)') now runs and does what the help page seems to imply: Nothing. From the showNonASCII help page: The elements of x containing non-ASCII characters will be returned invisibly. One gets a result one does not see? Does one have to explicitly capture the result somehow? I really have not the faintest idea of what the example from the help page is doing. returned invisibly means that the result is returned with a flag set so it won't automatically print. If you want to print it, you need to ask. So any of these will work to see the result: x - showNonASCII( ) x or print(showNonASCII( )) or even (though this is one some of us don't like, it still works...) (showNonASCII( )) Duncan Murdoch John Kane Kingston ON Canada -Original Message- From: murdoch.dun...@gmail.com Sent: Mon, 23 Dec 2013 12:51:43 -0500 To: jrkrid...@inbox.com, r...@temple.edu Subject: Re: [R] Knitr, ggplot and consistent fonts On 13-12-23 12:40 PM, John Kane wrote: Thanks Richard. I did not realise such a function existed. Assuming I am using it correctly I do get an error though not where I was expecting it. Anyway the code below returns an error library(tools) showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)) Results Error: unexpected symbol in: showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black You get that error because you're using double quotes around a string containing double quotes, and not escaping them. With that string, using single quotes on the outside should be fine: showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)') Duncan Murdoch John Kane Kingston ON Canada -Original Message- From: r...@temple.edu Sent: Mon, 23 Dec 2013 11:44:42 -0500 To: jrkrid...@inbox.com Subject: Re: [R] Knitr, ggplot and consistent fonts If the problem seems to be non-ASCII characters, then the first investigation step is to use the R functions ?tools::showNonASCII ?tools::showNonASCIIfile On Mon, Dec 23, 2013 at 11:37 AM, John Kane jrkrid...@inbox.com wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to
Re: [R] Knitr, ggplot and consistent fonts
Thanks, I was not getting anything when I printed the x and so thought I was doing something wrong. Instead I just didn't seem to have a non-ASCII character. John Kane Kingston ON Canada -Original Message- From: murdoch.dun...@gmail.com Sent: Mon, 23 Dec 2013 15:52:32 -0500 To: jrkrid...@inbox.com, r...@temple.edu Subject: Re: [R] Knitr, ggplot and consistent fonts On 13-12-23 1:07 PM, John Kane wrote: Thanks Duncan. I had the feeling I was doing something wrong but did not realise it was that stupid. showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)') now runs and does what the help page seems to imply: Nothing. From the showNonASCII help page: The elements of x containing non-ASCII characters will be returned invisibly. One gets a result one does not see? Does one have to explicitly capture the result somehow? I really have not the faintest idea of what the example from the help page is doing. returned invisibly means that the result is returned with a flag set so it won't automatically print. If you want to print it, you need to ask. So any of these will work to see the result: x - showNonASCII( ) x or print(showNonASCII( )) or even (though this is one some of us don't like, it still works...) (showNonASCII( )) Duncan Murdoch John Kane Kingston ON Canada -Original Message- From: murdoch.dun...@gmail.com Sent: Mon, 23 Dec 2013 12:51:43 -0500 To: jrkrid...@inbox.com, r...@temple.edu Subject: Re: [R] Knitr, ggplot and consistent fonts On 13-12-23 12:40 PM, John Kane wrote: Thanks Richard. I did not realise such a function existed. Assuming I am using it correctly I do get an error though not where I was expecting it. Anyway the code below returns an error library(tools) showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)) Results Error: unexpected symbol in: showNonASCII(ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black You get that error because you're using double quotes around a string containing double quotes, and not escaping them. With that string, using single quotes on the outside should be fine: showNonASCII('ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..)), binwidth = 1, colour = black, fill = white)') Duncan Murdoch John Kane Kingston ON Canada -Original Message- From: r...@temple.edu Sent: Mon, 23 Dec 2013 11:44:42 -0500 To: jrkrid...@inbox.com Subject: Re: [R] Knitr, ggplot and consistent fonts If the problem seems to be non-ASCII characters, then the first investigation step is to use the R functions ?tools::showNonASCII ?tools::showNonASCIIfile On Mon, Dec 23, 2013 at 11:37 AM, John Kane jrkrid...@inbox.com wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters.
Re: [R] Inserting color into an irregular grid comprised of polygons
Thanks David, Instead of using terrain.colors or heat.colors, I went with: library(colorRamps) cv - matrix(as.integer(cut(vals2, breaks=100)), dim(vals2)) pal - blue2green2red(100) #a function from colorRamps Do you happen to have any clever ideas for a legend? I could play around with a series of polygons to the side of the plot (...xpd=TRUE), but don't have any better ideas. Eric [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Knitr, ggplot and consistent fonts
I believe you are right. We thank either Gmail or [[alternative HTML version deleted]] for this. I think showNonASCII() is just irrelevant here and pulling us to the wrong direction. It is not reliable to paste code into Email due to the potentially wrong text wrapping. Please consider an email attachment (not sure if an Rnw document can get through), or a Github gist, or pastebin instead, e.g. https://gist.github.com/yihui/8105762 Or ask on SO: http://stackoverflow.com/questions/tagged/r Now let's move back to the original question, to which I have no solution. Regards, Yihui -- Yihui Xie xieyi...@gmail.com Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Mon, Dec 23, 2013 at 10:53 AM, Federico Lasa fel...@gmail.com wrote: Hi, chiming in. Pasted the code in R studio and the format parser wouldn't mark the R code chunks. It was because there were line breaks in the middle of chunk options tags. Couldn't test if removing line breaks works, but maybe that's the source of the problem? On Mon, Dec 23, 2013 at 10:37 AM, John Kane jrkrid...@inbox.com wrote: Same result here with the same error message mentioned in my first post. I tried it in Texmaker which is my usual Latex editor, not that I do much in Latex, and then tried it in RStudio and it is still choking. Interestingly EMACS will process it and produce a pdf but it simply produces. It also provides this warning: : Latex Warning; Reference 'fig:plot-figheight' undefined on page 2 on input line 14. It seems to repeat the same message for each of the other figures. John Kane Kingston ON Canada -Original Message- From: dulca...@bigpond.com Sent: Mon, 23 Dec 2013 22:28:33 +1000 To: daniel.haugstv...@gmail.com, r-help@r-project.org Subject: Re: [R] Knitr, ggplot and consistent fonts Hi Dan I think you still have problems with embedded characters or some problems in char code page conversion or the like. Not knowing knitr but Sweave I cobbled the figures manually and ran the sweave file to produce the latex file. Latex was consistently stopping at the \caption and \ref functions I tried to see what was happening I added hyperref when I copied the text to hyperref latex bailed up I tried a minimal latex file without problems I put the \title etc in the preamble. Some compilers need this Duncan From: Daniel Haugstvedt [mailto:daniel.haugstv...@gmail.com] Sent: Monday, 23 December 2013 20:10 To: Duncan Mackay Cc: John Kane; R Subject: Re: [R] Knitr, ggplot and consistent fonts I am really sorry for posting a non-working example. It is running when I cut the code from my previous mail into a clean session in RStudio (OSX). However, I suspect that you are right. I did cut and paste some code from a forum yesterday which had characters that had to be replaced. I gave emacs a try, but could not find the problem there either. The code below was pasted though textEdit and converted to plain text. I hope this takes care of any embedded characters. \documentclass{article} \begin{document} setup, include=FALSE, cache=FALSE= library(knitr) library(ggplot2) @ \title{Knitr and ggplot2} \author{Daniel Haugstvedt} \maketitle There are four plots in this article. Figure \ref{fig:plot-figHeight} uses the argument fig.height=2.5 while Figures \ref{fig:plot-figWidth} used both fig.height=2.5 and fig.width=3. The later option makes the font too big. An alternative approach is used in Figures \ref{fig:plot-figOutWidthBig} and \ref{fig:plot-figOutWidthSmall}. There the argument out.width is set to 12 and 8 cm respectively. This stops the problem of excessively large fonts for figures with smaller width, but there is still no consistency across plots in terms o font size. plot-figHeight, echo=FALSE, fig.height=2.5, fig.cap=Density plot with no fig.width argument, results='hide', fig.pos='ht'= df = data.frame(x = rnorm(100), y = 1:100) ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figWidth, echo=FALSE, fig.height=2.5, fig.width = 3, fig.cap=Density plot with fig.width=3, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) + xlab(Improvement, %) + ylab(Density) + theme_classic() @ plot-figOutWidthBig, echo=FALSE, fig.height=2.5, out.width = 12cm, fig.cap=Density plot with out.width=12cm, fig.pos='ht'= ggplot(df, aes(x = x)) + geom_histogram(aes(y = ..density..), binwidth = 1, colour = black, fill = white) +
Re: [R] Inserting color into an irregular grid comprised of polygons
I can't think of a straightforward way. You might be able to use the image.plot() function in package fields by using legend.only=TRUE to add the legend to your existing plot. David From: Morway, Eric [mailto:emor...@usgs.gov] Sent: Monday, December 23, 2013 3:46 PM To: dcarl...@tamu.edu Cc: R mailing list Subject: Re: [R] Inserting color into an irregular grid comprised of polygons Thanks David, Instead of using terrain.colors or heat.colors, I went with: library(colorRamps) cv - matrix(as.integer(cut(vals2, breaks=100)), dim(vals2)) pal - blue2green2red(100) #a function from colorRamps Do you happen to have any clever ideas for a legend? I could play around with a series of polygons to the side of the plot (...xpd=TRUE), but don't have any better ideas. Eric [[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] svycoxph
The svycoxph function in the survey package loads the survival package and produces objects of class svycoxph and coxph. The print.coxph function - print(coxph.object, conf.int = 0.95) - in the survival package lists the values of the coxph object including the hazard ratios with 95% CIs. When applied to svycoxph/coxph objects, print(svycoxph.object, conf.int = 0.95) does not list the 95% CIs. Using the call print.coxph(svycoxph.object, conf.int = 0.95) returns the error that print.coxph can¹t be found. I have tried various arguments in print(predict(svycoxph.object, se = T, type = ?)), but without returning the CIs. Any suggestions on the correct syntax will be appreciated. Nathan -- Nathan Pace, MD, MStat Department of Anesthesiology University of Utah 801.581.6393 n.l.p...@utah.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: Calculating group means
On 12/23/2013 11:31 PM, Laura Bethan Thomas [lbt1] wrote: Hi All, Sorry for what I imagine is quite a basic question. I have been trying to do is create latency averages for each state (1-8) for each participant (n=13) in each condition (1-10). I'm not sure what function I would need, or what the most efficient ay of calculating this would be. If you have any help with that I would be very grateful. structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L), conditionNo = c(1L, 1L, 1L, 1L, 1L, 1L), state = c(5L, 8L, 7L, 8L, 1L, 7L), latency = c(869L, 864L, 1004L, 801L, 611L, 679L)), .Names = c(subject, conditionNo, state, latency), row.names = 3:8, class = data.frame) Hi Laura, You can do it like this: # make up enough data to do the calculation lbtdat-data.frame(subject=rep(1:13,each=160), condition=rep(rep(rep(1:10,each=8),2),13), state=rep(rep(1:8,20),13), latency=sample(600:1100,2080,TRUE)) by(lbtdat$latency,list(lbtdat$subject, lbtdat$condition,lbtdat$state),mean) but you are going to get a rather long list of means. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] svycoxph
Answered my own question. In survey, summary does it. On 2312//2013, 5:31 PM, Nathan Pace n.l.p...@utah.edu wrote: The svycoxph function in the survey package loads the survival package and produces objects of class svycoxph and coxph. The print.coxph function - print(coxph.object, conf.int = 0.95) - in the survival package lists the values of the coxph object including the hazard ratios with 95% CIs. When applied to svycoxph/coxph objects, print(svycoxph.object, conf.int = 0.95) does not list the 95% CIs. Using the call print.coxph(svycoxph.object, conf.int = 0.95) returns the error that print.coxph can¹t be found. I have tried various arguments in print(predict(svycoxph.object, se = T, type = ?)), but without returning the CIs. Any suggestions on the correct syntax will be appreciated. Nathan -- Nathan Pace, MD, MStat Department of Anesthesiology University of Utah 801.581.6393 n.l.p...@utah.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fwd: Calculating group means
Jim: Did you forget about with() ? Instead of: by(lbtdat$latency,list(lbtdat$subject, lbtdat$condition,lbtdat$state),mean) ##do with(ibtdat,by(latency,list(subject,condition,state),mean)) Bert Gunter Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Mon, Dec 23, 2013 at 6:37 PM, Jim Lemon j...@bitwrit.com.au wrote: On 12/23/2013 11:31 PM, Laura Bethan Thomas [lbt1] wrote: Hi All, Sorry for what I imagine is quite a basic question. I have been trying to do is create latency averages for each state (1-8) for each participant (n=13) in each condition (1-10). I'm not sure what function I would need, or what the most efficient ay of calculating this would be. If you have any help with that I would be very grateful. structure(list(subject = c(1L, 1L, 1L, 1L, 1L, 1L), conditionNo = c(1L, 1L, 1L, 1L, 1L, 1L), state = c(5L, 8L, 7L, 8L, 1L, 7L), latency = c(869L, 864L, 1004L, 801L, 611L, 679L)), .Names = c(subject, conditionNo, state, latency), row.names = 3:8, class = data.frame) Hi Laura, You can do it like this: # make up enough data to do the calculation lbtdat-data.frame(subject=rep(1:13,each=160), condition=rep(rep(rep(1:10,each=8),2),13), state=rep(rep(1:8,20),13), latency=sample(600:1100,2080,TRUE)) by(lbtdat$latency,list(lbtdat$subject, lbtdat$condition,lbtdat$state),mean) but you are going to get a rather long list of means. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.