Re: [R] Read shortcuts of MS Excel files through R
Assuming you are trying to read the contents of the Excel files and not the shortcut itself, try something link this: #C:\users\mark\desktop\A1.xlsx.lnk is a shortcut I created on my desktop to an xlsx document in another directory #The windows type command, along with find gets the path to the actual file from the shortcut cmd-'type c:\\users\\mark\\desktop\\A1.xlsx.lnk|find \\|findstr/b [a-z]:[]' XLFileName-shell(cmd, intern=T) read.xlsx(XLFileName, 1) I hope this helps. --Mark J. Lamias From: Santosh santosh2...@gmail.com To: r-help r-help@r-project.org Sent: Thursday, September 26, 2013 4:54 PM Subject: [R] Read shortcuts of MS Excel files through R Dear Rxperts, Through Windows OS, I created shortcuts (paste as shortcut) to excel spreadsheets ( with xlsx as the file extension). I wasn't able to read the shortcuts through R and using read functions of xlsx package. exf - a1.xlsx.lnk read.xlsx(exf,1) Error in .jcall(RJavaTools, Ljava/lang/Object;, invokeMethod, cl, : java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream read.xlsx2(exf,1) Error in .jcall(RJavaTools, Ljava/lang/Object;, invokeMethod, cl, : java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream Would truly appreciate your suggestions. Regards, Santosh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Having trouble converting a dataframe of character vectors to factors
Great point, William. I agree your approach is the one to take to preserve attributes. Thanks for following up. From: William Dunlap wdun...@tibco.com elp (r-help@r-project.org) r-help@r-project.org Sent: Thursday, February 21, 2013 11:32 AM Subject: RE: [R] Having trouble converting a dataframe of character vectors to factors scs2-data.frame(lapply(scs2, factor)) Calling data.frame() on the output of lapply() can result in changing column names and will drop attributes that the input data.frame may have had. I prefer to modify the original data.frame instead of making a new one from scratch to avoid these problems. Also, calling factor() on a factor will drop any unused levels, which you may not want to do. Calling as.factor will not. Compare the following three methods f1 - function (dataFrame) { dataFrame[] - lapply(dataFrame, factor) dataFrame } f2 - function (dataFrame) { dataFrame[] - lapply(dataFrame, as.factor) dataFrame } f3 - function (dataFrame) { data.frame(lapply(dataFrame, factor)) } on the following data.frame x - data.frame(stringsAsFactors=FALSE, check.names=FALSE, No/Yes = factor(c(Yes,Yes,Yes), levels=c(No,Yes)), Size = ordered(c(Small,Large,Medium), levels=c(Small,Medium,Large)), Name = c(Adam,Bill,Chuck)) attr(x, Date) - as.POSIXlt(2013-02-21) str(x) 'data.frame': 3 obs. of 3 variables: $ No/Yes: Factor w/ 2 levels No,Yes: 2 2 2 $ Size : Ord.factor w/ 3 levels SmallMedium..: 1 3 2 $ Name : chr Adam Bill Chuck - attr(*, Date)= POSIXlt, format: 2013-02-21 str(f1(x)) # drops unused levels 'data.frame': 3 obs. of 3 variables: $ No/Yes: Factor w/ 1 level Yes: 1 1 1 $ Size : Ord.factor w/ 3 levels SmallMedium..: 1 3 2 $ Name : Factor w/ 3 levels Adam,Bill,..: 1 2 3 - attr(*, Date)= POSIXlt, format: 2013-02-21 str(f2(x)) 'data.frame': 3 obs. of 3 variables: $ No/Yes: Factor w/ 2 levels No,Yes: 2 2 2 $ Size : Ord.factor w/ 3 levels SmallMedium..: 1 3 2 $ Name : Factor w/ 3 levels Adam,Bill,..: 1 2 3 - attr(*, Date)= POSIXlt, format: 2013-02-21 str(f3(x)) # mangles column names, drops unused levels, drops Date attribute 'data.frame': 3 obs. of 3 variables: $ No.Yes: Factor w/ 1 level Yes: 1 1 1 $ Size : Ord.factor w/ 3 levels SmallMedium..: 1 3 2 $ Name : Factor w/ 3 levels Adam,Bill,..: 1 2 3 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Lamias Sent: Wednesday, February 20, 2013 6:51 PM To: Daniel Lopez; R help (r-help@r-project.org) Subject: Re: [R] Having trouble converting a dataframe of character vectors to factors How about this? scs2-data.frame(lapply(scs2, factor)) From: Lopez, Dan lopez...@llnl.gov To: R help (r-help@r-project.org) r-help@r-project.org Sent: Wednesday, February 20, 2013 7:09 PM Subject: [R] Having trouble converting a dataframe of character vectors to factors R Experts, I have a dataframe made up of character vectors--these are results from survey questions. I need to convert them to factors. I tried the following which did not work: scs2-sapply(scs2,as.factor) also this didn't work: scs2-sapply(scs2,function(x) as.factor(x)) After doing either of above I end up with str(scs2) chr [1:10, 1:10] very important very important very important very important ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:10] Q1_1 Q1_2 Q1_3 Q1_4 ... class(scs2) matrix But when I do it one at a time it works: scs2$Q1_1-as.factor(scs2$Q1_1) scs2$Q1_2- as.factor(scs2$Q1_2) What am I doing wrong? How do I accomplish this with sapply or similar function? Data for reproducibility: scs2-structure(list(Q1_1 = c(very important, very important, very important, very important, very important, very important, very important, somewhat important, important, very important), Q1_2 = c(important, somewhat important, very important, important, important, very important, somewhat important, somewhat important, very important, very important), Q1_3 = c(very important, important, very important, very important, important, very important, very important, somewhat important, not important, important), Q1_4 = c(very important, important, very important, very important, important, important, important, very important, somewhat important, important), Q1_5 = c(very important, not important, important, very important, not important, important, somewhat important, important, somewhat important, not important), Q1_6 = c(very important, not important, important, very important, somewhat important, very important, very important, very important, important, important), Q1_7 = c
Re: [R] Having trouble converting a dataframe of character vectors to factors
How about this? scs2-data.frame(lapply(scs2, factor)) From: Lopez, Dan lopez...@llnl.gov To: R help (r-help@r-project.org) r-help@r-project.org Sent: Wednesday, February 20, 2013 7:09 PM Subject: [R] Having trouble converting a dataframe of character vectors to factors R Experts, I have a dataframe made up of character vectors--these are results from survey questions. I need to convert them to factors. I tried the following which did not work: scs2-sapply(scs2,as.factor) also this didn't work: scs2-sapply(scs2,function(x) as.factor(x)) After doing either of above I end up with str(scs2) chr [1:10, 1:10] very important very important very important very important ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:10] Q1_1 Q1_2 Q1_3 Q1_4 ... class(scs2) matrix But when I do it one at a time it works: scs2$Q1_1-as.factor(scs2$Q1_1) scs2$Q1_2- as.factor(scs2$Q1_2) What am I doing wrong? How do I accomplish this with sapply or similar function? Data for reproducibility: scs2-structure(list(Q1_1 = c(very important, very important, very important, very important, very important, very important, very important, somewhat important, important, very important), Q1_2 = c(important, somewhat important, very important, important, important, very important, somewhat important, somewhat important, very important, very important), Q1_3 = c(very important, important, very important, very important, important, very important, very important, somewhat important, not important, important), Q1_4 = c(very important, important, very important, very important, important, important, important, very important, somewhat important, important), Q1_5 = c(very important, not important, important, very important, not important, important, somewhat important, important, somewhat important, not important), Q1_6 = c(very important, not important, important, very important, somewhat important, very important, very important, very important, important, important), Q1_7 = c(very important, somewhat important, important, somewhat important, important, important, very important, very important, somewhat important, not important), Q2 = c(Somewhat, Very Much, Somewhat, Very Much, Very Much, Very Much, Very Much, Very Much, Very Much, Very Much), Q3 = c(yes, yes, yes, yes, yes, yes, yes, yes, yes, yes), Q4 = c(None, None, None, None, Confirmed Field of Study, Confirmed Field of Study, Confirmed Field of Study, None, None, None)), .Names = c(Q1_1, Q1_2, Q1_3, Q1_4, Q1_5, Q1_6, Q1_7, Q2, Q3, Q4 ), row.names = c(78L, 46L, 80L, 196L, 188L, 197L, 39L, 195L, 172L, 110L), class = data.frame) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Recommendation for website to format R code
Are you only interested in formatting code from copy and pasting to/from email? If you are interested in formatting your code in Latex/PDF/HTML take a look at the knitr package: http://yihui.name/knitr/ Also, you could check out the formatR package: http://cran.r-project.org/web/packages/formatR/formatR.pdf --Mark Lamias From: C W tmrs...@gmail.com To: r-help r-help@r-project.org Sent: Wednesday, January 23, 2013 9:27 PM Subject: [R] Recommendation for website to format R code Hi list, Could anyone recommend some good website for formatting R code? For example, when you copy paste R code to gmail and back to R, it loses its format, the dash symbol causes errors. I've had someone used it to format my code here on the list, but can't find it anymore. Mike [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A question on list and lapply
How about Dat1 - lapply(subset(Dat, Dat!=P), My_Function) --Mark From: Christofer Bogaso bogaso.christo...@gmail.com To: r-help@r-project.org Sent: Friday, December 14, 2012 1:58 PM Subject: [R] A question on list and lapply Dear all, let say I have following list: Dat - vector(list, length = 26) names(Dat) - LETTERS My_Function - function(x) return(rnorm(5)) Dat1 - lapply(Dat, My_Function) However I want to apply my function 'My_Function' for all elements of 'Dat' except the elements having 'names(Dat) == P'. Here I have specified the name P just for illustration however this will be some name specified by user. Is there any direct way to achieve this, using 'lapply'? Thanks for your help. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] list to matrix?
Try: matrix(unlist(a), ncol=2, byrow=T) --Mark Lamias From: Sam Steingold s...@gnu.org To: r-help@r-project.org Sent: Tuesday, December 4, 2012 3:09 PM Subject: [R] list to matrix? How do I convert a list to a matrix? --8---cut here---start-8--- list(c(5, 101), c(1e+05, 46), c(15, 31), c(2e+05, 17), c(25, 19), c(3e+05, 11), c(35, 12), c(4e+05, 25), c(45, 19), c(5e+05, 16)) as.matrix(a) [,1] [1,] Numeric,2 [2,] Numeric,2 [3,] Numeric,2 [4,] Numeric,2 [5,] Numeric,2 [6,] Numeric,2 [7,] Numeric,2 [8,] Numeric,2 [9,] Numeric,2 --8---cut here---end---8--- thanks! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://palestinefacts.org http://dhimmi.com http://jihadwatch.org http://www.PetitionOnline.com/tap12009/ http://memri.org Rhinoceros has poor vision, but, due to his size, it's not his problem. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reformatting some data
It's not clear to me what it is you are attempting to do, as you switch from a very specific example to some general example with the vague terms var1 var2, and var3. It sounds like you might be trying to do something similar to what would be available in the shape package using the melt function. Try ?melt.data.frame. --Mark Lamias From: Charles Determan Jr deter...@umn.edu To: r-help@r-project.org Sent: Tuesday, December 4, 2012 4:17 PM Subject: [R] reformatting some data Hello, I am trying to reformat some data so that it is organized by group in the columns. The data currently looks like this: group X3.Hydroxybutyrate X3.Hydroxyisovalerate ADP 347 4 4e-04 3e-04 5e-04 353 3 5e-04 3e-04 6e-04 359 4 4e-04 3e-04 6e-04 365 4 6e-04 3e-04 5e-04 371 4 5e-04 3e-04 7e-04 377 2 7e-04 4e-04 7e-04 I would like to reformat it so it is like this: 2 3 4 var1 var2 var3 I realize that there unequal numbers in each group but I would like to none-the-less if possible. Here is a subset of the data: structure(list(group = c(4L, 3L, 4L, 4L, 4L, 2L), X3.Hydroxybutyrate = c(4e-04, 5e-04, 4e-04, 6e-04, 5e-04, 7e-04), X3.Hydroxyisovalerate = c(3e-04, 3e-04, 3e-04, 3e-04, 3e-04, 4e-04), ADP = c(5e-04, 6e-04, 6e-04, 5e-04, 7e-04, 7e-04)), .Names = c(group, X3.Hydroxybutyrate, X3.Hydroxyisovalerate, ADP), row.names = c(347L, 353L, 359L, 365L, 371L, 377L), class = data.frame) Any insight is truly appreciated, Regards, Charles [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reformatting some data
That should read the reshape package -- not the shape package. My apologies. To: Charles Determan Jr deter...@umn.edu; r-help@r-project.org r-help@r-project.org Sent: Tuesday, December 4, 2012 4:36 PM Subject: Re: [R] reformatting some data It's not clear to me what it is you are attempting to do, as you switch from a very specific example to some general example with the vague terms var1 var2, and var3. It sounds like you might be trying to do something similar to what would be available in the shape package using the melt function. Try ?melt.data.frame. --Mark Lamias From: Charles Determan Jr deter...@umn.edu To: r-help@r-project.org Sent: Tuesday, December 4, 2012 4:17 PM Subject: [R] reformatting some data Hello, I am trying to reformat some data so that it is organized by group in the columns. The data currently looks like this: group X3.Hydroxybutyrate X3.Hydroxyisovalerate ADP 347 4 4e-04 3e-04 5e-04 353 3 5e-04 3e-04 6e-04 359 4 4e-04 3e-04 6e-04 365 4 6e-04 3e-04 5e-04 371 4 5e-04 3e-04 7e-04 377 2 7e-04 4e-04 7e-04 I would like to reformat it so it is like this: 2 3 4 var1 var2 var3 I realize that there unequal numbers in each group but I would like to none-the-less if possible. Here is a subset of the data: structure(list(group = c(4L, 3L, 4L, 4L, 4L, 2L), X3.Hydroxybutyrate = c(4e-04, 5e-04, 4e-04, 6e-04, 5e-04, 7e-04), X3.Hydroxyisovalerate = c(3e-04, 3e-04, 3e-04, 3e-04, 3e-04, 4e-04), ADP = c(5e-04, 6e-04, 6e-04, 5e-04, 7e-04, 7e-04)), .Names = c(group, X3.Hydroxybutyrate, X3.Hydroxyisovalerate, ADP), row.names = c(347L, 353L, 359L, 365L, 371L, 377L), class = data.frame) Any insight is truly appreciated, Regards, Charles [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to read SPSS file in R
The following works just fine for me, using the built-in SPSS dataset nhis2000_subset.sav. library(foreign) a=read.spss(C:\\Program Files\\IBM\\SPSS\\Statistics\\21\\Samples\\English\\nhis2000_subset.sav, to.data.frame=T) names(a) [1] STRATUM PSU WTFA_SA SEX AGE_P REGION SMKNOW VITANY VITMUL HERBSUPP VIGFREQW [12] MODFREQW STRFREQW DESIREWT MOVE1 LIFT age_cat You do not need to specify a comma delimiter on your read.spss statement since the file is already in a native SPSS dataset format -- not a CSV file. --Mark Lamias From: F86 farad...@gmail.com To: r-help@r-project.org Sent: Monday, December 3, 2012 10:55 AM Subject: [R] How to read SPSS file in R Dear R-users, I have som troubles with .sav file. How is it possible for us R-users to read SPSS files. I know that is possible, I tried the following: library(foreign) Corp-read.spss(/Users/kama/Analysis/Corporation.sav, header=TRUE, sep=,) Error in read.spss(/Users/kama/Analysis/Corporation.sav, header = TRUE, : unused argument(s) (header = TRUE, sep = ,) Corp-read.spss(/Users/kama/Analysis/Corporation.sav) re-encoding from UTF-8 Any suggestions please? Regards, Faradj Stockholm University -- View this message in context: http://r.789695.n4.nabble.com/How-to-read-SPSS-file-in-R-tp4651896.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] knitr error with Lyx
R Users, I just upgraded my version of R from R-2.15.0 to R-2.15.2 and installed the latest versions of LyX and MikTex running Windows 7 Ultimate, 64-bit OS. Prior to the upgrade, I was using Lyx with knitr to generate a document with no problems. However, after the upgrade, and using the same LyX document, I'm receiving the following error when I attempt to compile the document: \end{verbatim} The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., `\hobx'), type `I' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined. I have determined that the error is caused when printing the anova results from the anova statement in my R source code, but can't seem to resolve the issue. Here is an example code chunk that creates the error: NonCP1, fig.width=6, fig.height=4, out.width='.8\\linewidth' ,par=FALSE= #Read in data y=c( 67, 73, 83, 89, 65, 91, 87, 86, 155, 127, 147, 212, 108, 100, 90, 153, 140, 142, 121, 150, 33, 8, 46, 54 ) temp=as.factor(c(rep(seq(360, 380, 10), each=4), rep(seq(380, 360, -10), each=4))) coat=as.factor(rep(seq(1, 4), 6)) replicate=as.factor(rep(seq(1, 6), each=4)) #Obtain Factorial/Incorrect Model o=lm(y~temp*coat) ano=anova(o) ano @ Removing the ano=anova(o) or ano lines in the code chunk allows the document to compile with no problem. Does anyone else have this problem or did I do something wrong when I migrated to the newer versions? Thanks, in advance for any help! Sincerely yours, Mark J. Lamias [[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 error with Lyx
Thanks, Yihui! Luckily I kept R-2.15.0 and left it untouched (so I can continue to use that for now). If it helps any, I was able to go back into Lyx and change the path to point to R-2.15.0 and I also changed the windows path environment variable to point to the old version. After doing this, LyX worked fine with no problem on the code below. Changing the paths back to the new version R-2.15.2, generates the error below. If anyone else has any idea how to resolve this, either through R or a Lyx/LaTeX fix, I'd be all ears. Thanks, again for your response, Yihui! Sincerely yours, Mark J. Lamias From: Yihui Xie x...@yihui.name Cc: r-help@r-project.org r-help@r-project.org Sent: Thursday, November 29, 2012 2:02 PM Subject: Re: [R] knitr error with Lyx Quite a few people have had this problem, but since I'm unable to reproduce it, I'm not exactly sure how to fix it either. A few references that might be helpful to you: http://stackoverflow.com/q/12448507/559676 https://github.com/yihui/knitr/issues/413 It is very likely to be a pure LaTeX problem. Letting MikTeX install the missing LaTeX packages on the fly might solve the problem. Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA R Users, I just upgraded my version of R from R-2.15.0 to R-2.15.2 and installed the latest versions of LyX and MikTex running Windows 7 Ultimate, 64-bit OS. Prior to the upgrade, I was using Lyx with knitr to generate a document with no problems. However, after the upgrade, and using the same LyX document, I'm receiving the following error when I attempt to compile the document: \end{verbatim} The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., `\hobx'), type `I' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined. I have determined that the error is caused when printing the anova results from the anova statement in my R source code, but can't seem to resolve the issue. Here is an example code chunk that creates the error: NonCP1, fig.width=6, fig.height=4, out.width='.8\\linewidth' ,par=FALSE= #Read in data y=c( 67, 73, 83, 89, 65, 91, 87, 86, 155, 127, 147, 212, 108, 100, 90, 153, 140, 142, 121, 150, 33, 8, 46, 54 ) temp=as.factor(c(rep(seq(360, 380, 10), each=4), rep(seq(380, 360, -10), each=4))) coat=as.factor(rep(seq(1, 4), 6)) replicate=as.factor(rep(seq(1, 6), each=4)) #Obtain Factorial/Incorrect Model o=lm(y~temp*coat) ano=anova(o) ano @ Removing the ano=anova(o) or ano lines in the code chunk allows the document to compile with no problem. Does anyone else have this problem or did I do something wrong when I migrated to the newer versions? [[elided Yahoo spam]] Sincerely yours, Mark J. Lamias [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can R be embedded in html?
I haven't used it yet, so I can't comment about the stability or appropriateness of it, but R.NET looks somewhat promising for this: http://rdotnet.codeplex.com/ Shiny is another potential way to go. You could also take a look at David Firth's CGIwithR: http://www2.warwick.ac.uk/fac/sci/statistics/staff/academic-research/firth/software/cgiwithr/. --Mark J. Lamias From: Gergely Daróczi gerg...@snowl.net To: jagat.k.sh...@wellsfargo.com Cc: r-help@r-project.org; cha...@bio.ntnu.no Sent: Thursday, November 29, 2012 11:34 AM Subject: Re: [R] Can R be embedded in html? I grab the opportunity to suggest giving a try `pander` package, which holds a forked version of `brew` called `Pandoc.brew`. If you are familiar with `brew`, you could easily create nicely formatted HTML output automatically beside other formats, example: http://rapporter.github.com/pander/#examples But if you want to run those files directly, then RApache is the way to go with `RHandler brew::brew`, although that would end up in a spaghetti code. It's better to keep R and HTML separately in the long run. Best, Gergely On Thu, Nov 29, 2012 at 4:41 PM, jagat.k.sh...@wellsfargo.com wrote: Try R package 'brew'? From its package description Description: brew implements a templating framework for mixing text and R code for report generation. brew template syntax is similar to PHP, Ruby's erb module, Java Server Pages, and Python's psp module. There is also the rApache project and many other useful links mentioned on R Web Interfaces on the R FAQ page. Jagat -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of chawla Sent: Wednesday, November 28, 2012 9:04 AM To: r-help@r-project.org Subject: [R] Can R be embedded in html? Hi I have previously used PHP script in HTML to connect website with the database and do analysis. Is it also possible to execute R scripts within HTML files? Basically I want to create an application where user can input data such as gene list and their expression values, which can be processed by R and result be displayed or made available for download. If there is some guide on how to do this please give the link. Thanks Konika __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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 error with Lyx
Hi, Yihui, Attached is an HTML Diff report of the two files. The left pane contains the R-2.15.0 file. Thanks. --Mark From: Yihui Xie x...@yihui.name To: Mark Lamias mlam...@yahoo.com Cc: r-help@r-project.org r-help@r-project.org Sent: Thursday, November 29, 2012 2:43 PM Subject: Re: [R] knitr error with Lyx That is very helpful! Just to continue debugging, can you save the two versions of the tex files produced from LyX with different versions of R and do a diff on them? It sounds like something has changed from R 2.15.0 to 2.15.2. Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Thu, Nov 29, 2012 at 1:26 PM, Mark Lamias mlam...@yahoo.com wrote: Thanks, Yihui! Luckily I kept R-2.15.0 and left it untouched (so I can continue to use that for now). If it helps any, I was able to go back into Lyx and change the path to point to R-2.15.0 and I also changed the windows path environment variable to point to the old version. After doing this, LyX worked fine with no problem on the code below. Changing the paths back to the new version R-2.15.2, generates the error below. If anyone else has any idea how to resolve this, either through R or a Lyx/LaTeX fix, I'd be all ears. Thanks, again for your response, Yihui! Sincerely yours, Mark J. Lamias C:\Users\Mark\Desktop\Test\2.15.0.tex C:\Users\Mark\Desktop\Test\2.15.2.tex \batchmode \batchmode \makeatletter \makeatletter \def\input@path{{C:/Users/Mark/Desktop//}} \def\input@path{{C:/Users/Mark/Desktop//}} \makeatother \makeatother \documentclass{article} \documentclass{article}\usepackage{graphicx, color} \usepackage{graphicx, color} %% maxwidth is the original width if it is less than linewidth %% otherwise use linewidth (to make sure the graphics do not exceed the margin) \makeatletter \def\maxwidth{ % \ifdim\Gin@nat@width\linewidth \linewidth \else \Gin@nat@width \fi } \makeatother \IfFileExists{upquote.sty}{\usepackage{upquote}}{} \definecolor{fgcolor}{rgb}{0.2, 0.2, 0.2} \newcommand{\hlnumber}[1]{\textcolor[rgb]{0,0,0}{#1}}% \newcommand{\hlnumber}[1]{\textcolor[rgb]{0,0,0}{#1}}% \newcommand{\hlfunctioncall}[1]{\textcolor[rgb]{.5,0,.33}{\textbf{#1}}}% \newcommand{\hlfunctioncall}[1]{\textcolor[rgb]{0.501960784 313725,0,0.329411764705882}{\textbf{#1}}}% \newcommand{\hlstring}[1]{\textcolor[rgb]{.6,.6,1}{#1}}% \newcommand{\hlstring}[1]{\textcolor[rgb]{0.6,0.6,1}{#1}}% \newcommand{\hlkeyword}[1]{\textbf{#1}}% \newcommand{\hlkeyword}[1]{\textcolor[rgb]{0,0,0}{\textbf{#1}}}% \newcommand{\hlargument}[1]{\textcolor[rgb]{.69,.25,.02}{#1}}% \newcommand{\hlargument}[1]{\textcolor[rgb]{0.6901960784313 73,0.250980392156863,0.0196078431372549}{#1}}% \newcommand{\hlcomment}[1]{\textcolor[rgb]{.18,.6,.34}{#1}}% \newcommand{\hlcomment}[1]{\textcolor[rgb]{0.18039215686274 5,0.6,0.341176470588235}{#1}}% \newcommand{\hlroxygencomment}[1]{\textcolor[rgb]{.44,.48,.7}{#1}}% \newcommand{\hlroxygencomment}[1]{\textcolor[rgb]{0.4392156 8627451,0.47843137254902,0.701960784313725}{#1}}% \newcommand{\hlformalargs}[1]{\hlargument{#1}}% \newcommand{\hlformalargs}[1]{\textcolor[rgb]{0.69019607843 1373,0.250980392156863,0.0196078431372549}{#1}}% \newcommand{\hleqformalargs}[1]{\hlargument{#1}}% \newcommand{\hleqformalargs}[1]{\textcolor[rgb]{0.690196078 431373,0.250980392156863,0.0196078431372549}{#1}}% \newcommand{\hlassignement}[1]{\textbf{#1}}% \newcommand{\hlassignement}[1]{\textcolor[rgb]{0,0,0}{\textbf{#1}}}% \newcommand{\hlpackage}[1]{\textcolor[rgb]{.59,.71,.145}{#1}}% \newcommand{\hlpackage}[1]{\textcolor[rgb]{0.58823529411764 7,0.709803921568627,0.145098039215686}{#1}}% \newcommand{\hlslot}[1]{\textit{#1}}% \newcommand{\hlslot}[1]{\textit{#1}}% \newcommand{\hlsymbol}[1]{#1}% \newcommand{\hlsymbol}[1]{\textcolor[rgb]{0,0,0}{#1}}% \newcommand{\hlprompt}[1]{\textcolor[rgb]{.5,.5,.5}{#1}}% \newcommand{\hlprompt}[1]{\textcolor[rgb]{0.2,0.2,0.2}{#1}}% \usepackage{color}% \newsavebox{\hlnormalsizeboxclosebrace}% \newsavebox{\hlnormalsizeboxopenbrace}% \newsavebox{\hlnormalsizeboxbackslash}% \newsavebox{\hlnormalsizeboxlessthan}% \newsavebox{\hlnormalsizeboxgreaterthan}% \newsavebox{\hlnormalsizeboxdollar}% \newsavebox{\hlnormalsizeboxunderscore}% \newsavebox{\hlnormalsizeboxand}% \newsavebox{\hlnormalsizeboxhash}% \newsavebox{\hlnormalsizeboxat}% \newsavebox{\hlnormalsizeboxpercent}% \newsavebox{\hlnormalsizeboxhat}% \newsavebox{\hlnormalsizeboxsinglequote}% \newsavebox{\hlnormalsizeboxbacktick}% \setbox\hlnormalsizeboxopenbrace=\hbox{\begin{normalsize}\v erb.{.\end{normalsize}}% \setbox\hlnormalsizeboxclosebrace=\hbox{\begin{normalsize
Re: [R] binning by frequency
You might find the binning function in the sm package helpful here. --Mark Lamias From: Santosh santosh2...@gmail.com To: r-help r-help@r-project.org Sent: Tuesday, November 27, 2012 9:59 AM Subject: [R] binning by frequency Dear Rxperts, is there way to identify intervals from continuous data (having some kind of a pattern) and then pick the value of most frequency? a1 - round(rnorm(50,mean=0,0.1),2) a2 - round(rnorm(50,mean=1,0.2),1) a3 - round(rnorm(50,mean=5,1),0) a4 - round(rnorm(50,mean=14,4),0) a5 - round(rnorm(50,mean=30,8),0) b1 - rbind(a1,a2,a3,a4,a5) hist(b1,brea=100) # shows intervals and values with varying frequency. unlike the mean values of a1 a5 above, I don't know the nominal values. I would like an algorithm to identify intervals and pick the value with most frequency. I tried cut, split and was not successful. Any suggestions/tips are highly welcome. Thanks and regards, Santosh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Help in splitting the records
In the example below, I don't see any $$$ separators. Are you sure this is supposed to be the separate or just a single dollar sign? If this is the case, you don't specify what is to happen when multiple separators appear next to each other. From your example, it appears that two separators are to be treated as one? From: arunkumar akpbond...@gmail.com To: r-help@r-project.org Sent: Monday, November 26, 2012 5:51 AM Subject: [R] Help in splitting the records Hi I have set of records seperated by a separator say $$$ i want to get the values in a dataframe. eq qwer$$12$$qwre ewrtr$7789$ewwe I want the output as\ V1 V2 V3 qwer 12 qwre ewrtr 7789 ewwwe Please help me - Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/Help-in-splitting-the-records-tp4650827.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to Label Cases in Scatterplots?
You could use something like this: #Generate 26 simulated data points y=rnorm(26) x=1:26 your.labels=letters #Plot data plot(x, y, xlim=c(min(x), max(x)+.25), ylim=c(min(y), max(y)+.25)) #Label points text(x+.15, y+.15, your.labels) You could also use the textxy function in the calibrate package as show here: http://www.r-bloggers.com/r-tutorial-series-labeling-data-points-on-a-plot/. From: john55 johannes...@gmail.com To: r-help@r-project.org Sent: Saturday, November 24, 2012 11:04 AM Subject: [R] How to Label Cases in Scatterplots? Hi everyone, i´m trying to graphically display distributions with r and i´m working with makrodata from the WVS. the command i´m using is plot (Makrodata$v11, Makrodata$v12, xlab=Democracy Score Economist, ylab= share religious people) i´m having an additional variable that identifies respectively labels the cases with its country name. how can i implement that variable, so it identifies the various cases in the scatterplot and looks like the spss screenshot i posted below? http://r.789695.n4.nabble.com/file/n4650650/Unbenannt.gif thanks in advance! -- View this message in context: http://r.789695.n4.nabble.com/How-to-Label-Cases-in-Scatterplots-tp4650650.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Weighted least squares
I'm guessing that you have more elements in your weights vector than you have observations? It's hard to tell without seeing your data. See below: #Generate fake data y=rnorm(10) X1=rnorm(10) X2=rnorm(10) X3=rnorm(10) #Create a 10 element vector of weights wts=abs(rnorm(10)) #weighted lm works fine lm(y~X1+X2+X3, weights=wts) #Add an additional element to weight vector wts=c(wts, abs(rnorm(1))) #weighted lm throws warning message lm(y~X1+X2+X3, weights=wts) --Mark J. Lamias From: rbowman16 roosevelt.bow...@gmail.com To: r-help@r-project.org Sent: Wednesday, November 21, 2012 9:34 AM Subject: [R] Weighted least squares Hi everyone, I admit I am a bit of an R novice, and I was hoping someone could help me with this error message: Warning message: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : extra arguments weigths are just disregarded. My equation is: lm( Y ~ X1 + X2 + X3, weigths = seq(0.1, 1, by = 0.1)) -- View this message in context: http://r.789695.n4.nabble.com/Weighted-least-squares-tp4650292.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Deviation standard variance
What about something like this: #Create dummy data mydf=data.frame(matrix(rnorm(1000), ncol=100)) #Obtain summary stats my.vars=apply(mydf, MARGIN=2, FUN=var) my.std=sqrt(my.vars) #Plot summary stats plot(my.vars, col=red) points(my.std, col=blue) From: Elli ellilti_...@hotmail.com To: r-help@r-project.org Sent: Tuesday, November 20, 2012 1:32 PM Subject: Re: [R] Deviation standard variance I have a data set consisting of 364 variables and I need to graph the standard deviation and variance of each variable as only the function sd () or var () is not enough. And I want to know how I can graph this? -- View this message in context: http://r.789695.n4.nabble.com/Deviation-standard-variance-tp4650181p4650198.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] kinitr
This is how I learned everything about knitr: http://yihui.name/knitr/ Yihui is great and his site gives you pretty much all the information you need to get you started. From: Muhuri, Pradip (SAMHSA/CBHSQ) pradip.muh...@samhsa.hhs.gov To: 'R. Michael Weylandt' michael.weyla...@gmail.com Cc: r-help@r-project.org r-help@r-project.org Sent: Tuesday, November 20, 2012 9:10 AM Subject: Re: [R] kinitr Dear Michael, I really appreciated that you have sent me the link info - Jeromy Anglim's Blog. I was exactly looking for this kind of resources about R Markdown and knitr. All this would be of immense help. Thank you so much. Pradip Pradip K. Muhuri, PhD Statistician Substance Abuse Mental Health Services Administration The Center for Behavioral Health Statistics and Quality Division of Population Surveys 1 Choke Cherry Road, Room 2-1071 Rockville, MD 20857 Tel: 240-276-1070 Fax: 240-276-1260 e-mail: pradip.muh...@samhsa.hhs.gov The Center for Behavioral Health Statistics and Quality your feedback. Please click on the following link to complete a brief customer survey: http://cbhsqsurvey.samhsa.gov -Original Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Tuesday, November 20, 2012 8:36 AM To: Muhuri, Pradip (SAMHSA/CBHSQ) Cc: r-help@r-project.org Subject: Re: [R] kinitr On Tue, Nov 20, 2012 at 1:57 AM, Muhuri, Pradip (SAMHSA/CBHSQ) pradip.muh...@samhsa.hhs.gov wrote: Hello, I am an Intro-level R and ggplot2 user and looking for resources to self teach dynamic report generation in R using knitr. Any advice would be highly appreciated. http://jeromyanglim.blogspot.co.uk/2012/05/getting-started-with-r-markdown-knitr.html Michael Weylandt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Greek letters on title
Try this: titleline=expression(paste(Time evolution with , alpha, =0.2)) plot(x, main=titleline,col=orange) --Mark J. Lamias From: bgnumis bgnu...@gmail.com To: r-help@r-project.org Sent: Tuesday, November 20, 2012 3:47 PM Subject: [R] Greek letters on title Hi all, I want to plot a series x and I want to put on title Time evolution with alpha=0.2, e.g., plot(x, main=Time evotion with alpha=0.2,col=orange) Is there any posibility to put the greek letter and avoid written the word? Many 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. [[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] Greek letters on title
May may also find this helpful, especially if you know LaTex: http://yihui.name/en/2011/04/produce-authentic-math-formulas-in-r-graphics/ To: bgnumis bgnu...@gmail.com; r-help@r-project.org r-help@r-project.org Sent: Tuesday, November 20, 2012 6:22 PM Subject: Re: [R] Greek letters on title Try this: titleline=expression(paste(Time evolution with , alpha, =0.2)) plot(x, main=titleline,col=orange) --Mark J. Lamias From: bgnumis bgnu...@gmail.com To: r-help@r-project.org Sent: Tuesday, November 20, 2012 3:47 PM Subject: [R] Greek letters on title Hi all, I want to plot a series x and I want to put on title Time evolution with alpha=0.2, e.g., plot(x, main=Time evotion with alpha=0.2,col=orange) Is there any posibility to put the greek letter and avoid written the word? Many 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking for a test of standard normality
The Anderson-Darling Test and the Shapiro-Wilk test have considerably more power. I'd refer you to a non-R related discussion board for statistics related questions. Perhaps the following might be more useful: http://stats.stackexchange.com/questions/8184/most-powerful-gof-test-for-normality Sincerely yours, Mark J. Lamias From: Rolf Turner rolf.tur...@xtra.co.nz To: Herschtal Alan alan.hersch...@petermac.org Cc: r-help@r-project.org Sent: Thursday, November 8, 2012 10:16 PM Subject: Re: [R] Looking for a test of standard normality Others may correct me, but I cannot imagine any test of standard normality giving appreciably more power than is given by the Kolmogorov-Smirnov test. I also wonder about the point of testing for (standard) normality in the first place. There is a quote --- I think it refers to testing for heteroscedasticity, but I believe it applies equally to testing for normality --- about such testing being analogous to going out of the harbour in a rowing dinghy to see if it's safe for an ocean liner to put to sea. cheers, Rolf Turner On 09/11/12 13:23, Herschtal Alan wrote: Dear list members, I am looking for a goodness of test that will tell me if a sample is likely to have come from a standard normal distribution. I can find plenty of omnibus tests for normality in the nor.test package, but none of them appear to allow me to test against the specific alternative that the data are not standard normal. My back up option is to use a Kolmogorov-Smirnov test, but my impression is that that is not a very powerful test. Any suggestions? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Autofilling a large matrix in R
If you are after all the possible percentages with two decimal places, why don't you use this: seq(from=0, to=100, by=.01)/100 I'm not really sure what you are trying to do in terms of rows and columns, however. Can you be a bit more specific on what each row/column is? Are you trying to group the numbers so that all the entries in a row add up to 100% and then, once it does, split the following entries onto the next row until they add up to 100%, etc.? Thanks. From: wwreith reith_will...@bah.com To: r-help@r-project.org Sent: Friday, October 12, 2012 10:30 AM Subject: [R] Autofilling a large matrix in R I wish to create a matrix of all possible percentages with two decimal place percision. I then want each row to sum to 100%. I started with the code below with the intent to then subset the data based on the row sum. This works great for 2 or 3 columns, but if I try 4 or more columns the number of rows become to large. I would like to find a way to break it down into some kind of for loop, so that I can remove the rows that don't sum to 100% inside the for loop rather than outside it. My first thought was to take list from 1:10, 11:20, etc. but that does not get all of the points. g-as.matrix(expand.grid(rep(list(1:100), times=3))) Any thoughts how to split this into pieces? -- View this message in context: http://r.789695.n4.nabble.com/Autofilling-a-large-matrix-in-R-tp4645991.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Barplot problem
Here is an example you can use: #Generate random normal variables to use as dummy data for Fisher's Alpha alphaBCI-rnorm(100) #Assume you have 5 sites, each with 20 data points sites-rep(c(Site 1, Site 2, Site 3, Site 4, Site 5), each=20) #Making sites a factor will produce the stratified boxplots sites-as.factor(sites) #Produce boxplot boxplot(alphaBCI~sites) From: André Silva berthol...@gmail.com To: r-help@r-project.org Sent: Friday, April 20, 2012 8:28 PM Subject: [R] Barplot problem Hello, I have little experience with r, so I wonder if someone could help me? I need to plot a diversity measure (Fisher`s alpha) for different sites. I calculated the values using the following commands: Data(BCI) alphaBCI - fisher.alpha(BCI) I need boxplots showing the data variation between sites. Then I tried: boxplot(as.data.frame(alphaBCI)) However, it does not appear the box plots for different sites but only the boxplots for alpha, se, df. Residual and code? Do anyone know the right expression? Thank you very much, Bert [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to calculate a variance and covariance matrix for a vector
cov(A) will compute a covariance matrix of the columns of a matrix A.  cov(a, b) will compute a covariance of the vectors a and b.  here are some examples:  #create random vectors a=rnorm(10) b=rnorm(10)   a  [1] -0.3110384 -2.6201009 -1.3078118 1.3384743 2.4032381 -0.7245201  [7] -0.2274577 -1.4619624 2.2165118 1.3621709  b  [1] -1.1648495 -2.3013411 1.5335541 -0.2165172 1.1157774 1.0360323  [7] -0.8309283 -0.3403514 0.3640117 -0.6497384 #create a matrix A=cbind(a,b)  A               a         b  [1,] -0.3110384 -1.1648495  [2,] -2.6201009 -2.3013411  [3,] -1.3078118 1.5335541  [4,] 1.3384743 -0.2165172  [5,] 2.4032381 1.1157774  [6,] -0.7245201 1.0360323  [7,] -0.2274577 -0.8309283  [8,] -1.4619624 -0.3403514  [9,] 2.2165118 0.3640117 [10,] 1.3621709 -0.6497384  cov(a,b)  Covariance cov(a,b) [1] 0.7481056  #Covariance matrix cov(A)  cov(A)          a        b a 2.8529990 0.7481056 b 0.7481056 1.3910519  By the way, the covariance of two scalars will be zero, since the scalars are constants.   I hope this helps.  Sincerely yours,  Mark J. Lamias From: huang jialin huangps...@gmail.com To: Doran, Harold hdo...@air.org Cc: r-help@r-project.org r-help@r-project.org Sent: Monday, March 12, 2012 12:08 PM Subject: Re: [R] how to calculate a variance and covariance matrix for a vector Doran, Thanks for your advice. Sincerely, Jialin Huang On Mon, Mar 12, 2012 at 10:56 AM, Doran, Harold hdo...@air.org wrote: Always start with the help page. But, the best way to get help on this list is to construct some toy data. Even if imperfect, people will work to help you. Maybe show us some of your actual data. ** ** Of course, if a and b1 are really scalars, I donât think there is such a thing as the covariance between two scalars ** ** ** ** * * ** ** *From:* huang jialin [mailto:huangps...@gmail.com] *Sent:* Monday, March 12, 2012 11:53 AM *To:* Doran, Harold *Cc:* r-help@r-project.org *Subject:* Re: [R] how to calculate a variance and covariance matrix for a vector ** ** Hi, ** ** Thanks for your response. ** ** I tried to use cov() before, but got NA all over the place. ** ** a and b1 are scalars in the example. So that is the problem. I will start over from the formula. ** ** Thanks again. ** ** Sincerely, Jialin Huang ** ** On Mon, Mar 12, 2012 at 10:47 AM, Doran, Harold hdo...@air.org wrote:*** * Can you provide sample data? This suggests that a and b1, for example, are scalars. If that is what you actually have then you cannot produce a covariance between two scalars. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of huang jialin Sent: Monday, March 12, 2012 11:43 AM To: r-help@r-project.org Subject: [R] how to calculate a variance and covariance matrix for a vector Hello, I have a vector {a, b1, b2, b3, b4}. How can I calculate the following matrix: var(a) cov(a, b1) cov(a, b2) cov(a, b3) cov(a, b4) cov(a, b1) var(b1) cov(a, b2) cov(a, b3) cov(a, b4) ... ... cov(a, b1) cov(a, b2) cov(a, b3) cov(a, b4) var(b4) I would very appreciate your inputs. Thank you very much. Sincerely, Jialin Huang    [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ** **    [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Running Total
Modifying the method others have already proposed:  x - c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L) cbind(x, cumsum(x==0))  --Mark Lamias From: Edward Patzelt patze...@umn.edu To: jim holtman jholt...@gmail.com Cc: r-help@r-project.org Sent: Monday, March 5, 2012 1:59 PM Subject: Re: [R] Running Total Actually in looking at this I need it to only add if a 0 occurs instead of a 1. On Mon, Mar 5, 2012 at 12:57 PM, jim holtman jholt...@gmail.com wrote: cumsum is probably what you want: x - c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, + 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, + 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, + 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, + 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, + 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, + 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L) cbind(x, cumsum(x))    x  [1,] 1 1  [2,] 1 2  [3,] 0 2  [4,] 1 3  [5,] 1 4  [6,] 1 5  [7,] 1 6  [8,] 1 7  [9,] 0 7  [10,] 1 8  [11,] 0 8  [12,] 1 9  [13,] 1 10  [14,] 1 11  [15,] 1 12  [16,] 1 13  [17,] 0 13 On Mon, Mar 5, 2012 at 1:51 PM, Edward Patzelt patze...@umn.edu wrote: I'm am trying to create a vector that has a running total that adds each time a 1 occurs. here's the code and data c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L) total - {}; for(i in 1:length(dat$Valid)){ total[i] - ifelse(dat$Valid[i-1]==1, total[i] + 1, total[i]) } Cheers, -- Edward H. Patzelt Research Assistant â TRiCAM Lab University of Minnesota â Psychology/Psychiatry VA Medical Center S355 Elliot Hall: 612-626-0072 www.psych.umn.edu/research/tricam     [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. -- Edward H. Patzelt Research Assistant â TRiCAM Lab University of Minnesota â Psychology/Psychiatry VA Medical Center S355 Elliot Hall: 612-626-0072 www.psych.umn.edu/research/tricam    [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there an easier way to iterate over multiple data frames in R?
Depending upon what you are trying to do with them, how about storing the dataframes as a multidimensional array of size 4x3x3 in the case below. After that you can use the sapply function with the appropriate MARGIN argument specified: For example mydfs - as.array(list(df1, df2, df3)) sapply(X=mydfs, MARGIN=c(1,2), FUN=mean) [,1] [,2] [,3] V1 0.8206239 -0.51637848 -0.9025252 V2 -0.2828919 0.41837384 -0.4042646 V3 -0.8996891 -0.06284681 -0.2459261 --Mark Lamias From: Kaiyin Zhong kindlych...@gmail.com To: r-help r-help@r-project.org Sent: Wednesday, November 23, 2011 10:34 AM Subject: [R] Is there an easier way to iterate over multiple data frames in R? for (d in paste('df', 1:3, sep='')) { + assign(d, as.data.frame(replicate(3, rnorm(4 + } dats = list(df1,df2,df3) for (i in 1:length(dats)) { + names(dats[[i]]) = c('w', 'l', 'h') + } dats [[1]] w l h 1 1.24319239 -0.05543649 0.05409178 2 0.05124331 -1.89346950 0.33896273 3 -1.69686777 -0.35963008 -0.91720034 4 1.30786112 -0.23953238 0.94139356 [[2]] w l h 1 -1.238519 -0.12352187 -1.2577607 2 1.180469 2.38836107 2.9139199 3 1.494369 -0.07088712 0.2372746 4 1.942535 1.47911615 1.1431675 [[3]] w l h 1 1.0198692 -1.4222194 1.9486072 2 0.3057461 1.7630326 -0.6501801 3 -0.5576854 -1.1637263 -0.1782680 4 0.6625268 0.6913202 0.9588915 i = 1 for (n in paste('df', 1:3, sep='')) { + assign(n, dats[[i]]) + i = i+1 + } df1 w l h 1 1.24319239 -0.05543649 0.05409178 2 0.05124331 -1.89346950 0.33896273 3 -1.69686777 -0.35963008 -0.91720034 4 1.30786112 -0.23953238 0.94139356 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-latex syntax highlighting?
I use pgfSweave so that I can embed R code and output in LaTeX; pgfSweave depends on the formatR package to format the code, and the highlight package to highlight R code; graphics are based on tikzDevice, which has better quality than R's PDF or postscript output, in my opinion. Check out the developer's page here: http://yihui.name/en/2011/05/sweave-and-pgfsweave-in-lyx-2-0-x-experimental/ abd http://www.r-bloggers.com/how-to-start-using-pgfsweave-in-lyx-in-one-minute/ From: Giovanni Azua brave...@gmail.com To: r-help@r-project.org Sent: Wednesday, November 23, 2011 9:33 AM Subject: [R] R-latex syntax highlighting? Hello, Can anyone provide or point me to a good setup for the listings latex package that would produce nice R-syntax highlighting? I am using an example I found in internet for setting up listings like this: \lstset{ language=R, basicstyle=\scriptsize\ttfamily, commentstyle=\ttfamily\color{gray}, numbers=left, numberstyle=\ttfamily\color{red}\footnotesize, stepnumber=1, numbersep=5pt, backgroundcolor=\color{white}, showspaces=false, showstringspaces=false, showtabs=false, frame=single, tabsize=2, captionpos=b, breaklines=true, breakatwhitespace=false, title=\lstname, escapeinside={}, keywordstyle={}, morekeywords={} } But I know that using the color latex package it can look a lot nicer and I guess some people might have configured that before and are willing to share it? I'm also interested in the a similar problem best way to put R code with syntax highlighting into a presentation. I use Apple's Keynote. Many thanks in advance, Best regards, Giovanni [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] one sample Wilcoxon test using 'coin'
The wilcoxon test in coin are meant only for Testing the equality of the distributions of a numeric response in *two or more* independent groups against shift alternatives whereas the wilcoxon test in the base pacakge Performs *one-* and two-sample Wilcoxon tests on vectors of data; the latter is also known as âMann-Whitneyâ test.   So, wilcoxon_test and wilcoxonsign_test in coin will not work for one-sample. Why not just use wilcox.test?  Mark J. Lamias From: Holger Taschenberger holger.taschenber...@mpi-bpc.mpg.de To: r-help@r-project.org Sent: Monday, October 31, 2011 11:12 AM Subject: [R] one sample Wilcoxon test using 'coin' Hi, R allows me to run a one sample Wilcoxon test like this: wilcox.test(c(1,3.5,2.1,4,1.5,5), mu=2, exact=TRUE) The function 'wilcoxsign_test' from the package 'coin' should (I suppose) be able to calculate exact p values even if there are ties in the ranks. However, I couldn't find information on how to run a one sample test using 'wilcoxsign_test' like in the example above. Can anybody help?     Thanks,         Holger __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] MLE estimation
Check out Casella and Berger's Statistical Inference. ISBN 978-81-315-0394-2 or http://en.wikipedia.org/wiki/Maximum_likelihood as an online reference. --Mark J. Lamias From: Ning Cheng wakinchaue...@gmail.com To: r-help@r-project.org Sent: Sunday, February 27, 2011 3:19 PM Subject: [R] MLE estimation Dear List, This problem is more a statistic one than a R one. Any one can recommend me some references website or online paper on maximum likelihood estimation?I'm now working on that,while still doubt how to prove that the estimated parameters are normal distributed. Thanks for your time and help! Best, Ning __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R version of SAS/IntrNet
Does an R package exist that is similar to SAS/Intrnet (http://support.sas.com/documentation/onlinedoc/intrnet/index.html) that will allow users to take parameters passed to it by a web request, produce results and return them to the web-browser in HTML format? I tried looking through the package descriptions, but didnt' see anything like this. Any direction or suggestions you could provide would be greatly appreciated. Thanks. Sincerely yours, Mark J. Lamias Statistical Consultant Survey Methodologist [[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] Improving loop performance
R-users, I have the following piece of code which I am trying to run on a dataframe (aga2) with about a half million records. While the code works, it is extremely slow. I've read some of the help archives indicating that I should allocate space to the p1 and ags1 vectors, which I have done, but this doesn't seem to improve speed much. Would anyone be able to provide me with advice on how I might be able to speed this up? p1 - character(dim(aga2)[1]) ags - character(dim(aga2)[1]) for (i in 1:dim(aga2)[1]) { if (aga2$first.exon[i]==TRUE) { p1[i]-as.character(aga2[i, AP]) ags[i]-as.character(aga2[i, AS]) } else { p1[i]-paste(p1[i-1], aga2[i, AP], sep=,) ags[i]-paste(ags[i-1], aga2[i, AS], sep=,) } } Thanks. --Mark Lamias [[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] Fw: Improving loop performance
I will clarify my problem as others has asked for more detail: I have a dataframe, aga2, that looks like this: Row.ID AgilentProbe GeneSymbol GeneID Exons AgilentStart first.geneid first.exon last.geneid last.exon 8 1348 A_23_P116898 A2M 2 34 9112685 TRUE TRUE TRUE TRUE 62 19410 A_23_P95594 NAT1 9 4 18124656 TRUE TRUE TRUE TRUE 39 10323 A_23_P31798 NAT2 10 2 18302422 TRUE TRUE TRUE TRUE 21 5353 A_23_P162918 SERPINA3 12 5 94150936 TRUE TRUE FALSE FALSE 22 A_23_P162913 SERPINA3 12 5 94150800 FALSE FALSE FALSE FALSE 98 29990 A_32_P151937 SERPINA3 12 5 94150720 FALSE FALSE FALSE TRUE 33 9516 A_23_P2920 SERPINA3 12 7 94158435 FALSE TRUE FALSE TRUE 96 29595 A_32_P124727 SERPINA3 12 8 94160018 FALSE TRUE TRUE TRUE 57 18176 A_23_P80570 AADAC 13 5 153028473 TRUE TRUE TRUE TRUE 46 16139 A_23_P56529 AAMP 14 9 218838396 TRUE TRUE TRUE TRUE For the above example, I would like to end up with a vector, probe1, like this, based upon the AgilentProbe values: A_23_P116898 A_23_P95594 A_23_P31798 A_23_P162918 A_23_P162918,A_23_P162913, A_23_P162918,A_23_P162913,A_32_P151937 A_23_P2920 A_32_P124727 A_23_P80570 A_23_P56529 I build up each element of the vector based upon the value of last.exon. If the value of last.exon is FALSE, I'd like to obtain the previous value of AgilentProbe and concatenate it with the current value, and then move on to the next element. As stated previously, this code works, but it is very slow with larger datasets: probe1 - character(dim(aga2)[1]) agstart - character(dim(aga2)[1]) for (i in 1:dim(aga2)[1]) { if (aga2$first.exon[i]==TRUE) { probe1[i]-as.character(aga2[i, AgilentProbe]) agstart[i]-as.character(aga2[i, AgilentStart]) } else { probe1[i]-paste(probe1[i-1], aga2[i, AgilentProbe], sep=,) agstart[i]-paste(agstart[i-1], aga2[i, AgilentStart], sep=,) } } I tried a few of the previous suggestions (and tried modifying them), but they didn't seem to quite do the trick. Any assistance would be greatly appreciated. Thanks a million. --Mark Lamias - Forwarded Message From: jim holtman jholt...@gmail.com To: Mark Lamias mlam...@yahoo.com Cc: r-help@r-project.org Sent: Tue, May 11, 2010 12:46:26 PM Subject: Re: [R] Improving loop performance It was supposed to be 'head(p1, -1)' instead of 'tail(p1, -1)' On Tue, May 11, 2010 at 12:17 PM, Mark Lamias mlam...@yahoo.com wrote: R-users, I have the following piece of code which I am trying to run on a dataframe (aga2) with about a half million records. While the code works, it is extremely slow. I've read some of the help archives indicating that I should allocate space to the p1 and ags1 vectors, which I have done, but this doesn't seem to improve speed much. Would anyone be able to provide me with advice on how I might be able to speed this up? p1 - character(dim(aga2)[1]) ags - character(dim(aga2)[1]) for (i in 1:dim(aga2)[1]) { if (aga2$first.exon[i]==TRUE) { p1[i]-as.character(aga2[i, AP]) ags[i]-as.character(aga2[i, AS]) } else { p1[i]-paste(p1[i-1], aga2[i, AP], sep=,) ags[i]-paste(ags[i-1], aga2[i, AS], sep=,) } } Thanks. --Mark Lamias [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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.