Re: [R] ggplot2, building a simple formula interface
Hi, Try print(p) instead of plot(p) HTH, baptiste 2009/12/29 Bryan Hanson han...@depauw.edu: I¹m trying to build a simple formula interface to work with a function using ggplot2. The following scheme ³works² up until the plot(p) request, at which point there are complaints about xlim¹s and a blank graphics window. Looking at str(p) I do see the limits are NULL, plus layer 1 claims to have an empty data frame (but df is reproduced correctly). I'm sure I'm missing something really obvious; alas my ggplot2 book is at work and it's cold outside! simple - function(formula, data, ...){ mf - model.frame(formula = formula, data = data) } res - rnorm(100) f1 - rep(c(C, D, D, C), 25) f2 - rep(c(A, B), 50) mydata - data.frame(res, f1, f2) df - simple(~ res + f1, mydata) p - ggplot(df, aes(f1, res)) + geom_boxplot() plot(p) Thanks, Bryan * Bryan Hanson Acting Chair Professor of Chemistry Biochemistry DePauw University, Greencastle IN USA sessionInfo() R version 2.10.1 (2009-12-14) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] datasets tools grid graphics grDevices utils stats methods base other attached packages: [1] ggplot2_0.8.5 digest_0.4.2 reshape_0.8.3 proto_0.3-8 mvbutils_2.5.0 ChemoSpec_1.43 [7] R.utils_1.2.4 R.oo_1.6.5 R.methodsS3_1.0.3 rgl_0.87 lattice_0.17-26 mvoutlier_1.4 [13] plyr_0.1.9 RColorBrewer_1.0-2 chemometrics_0.5 som_0.3-4 robustbase_0.5-0-1 rpart_3.1-45 [19] pls_2.1-0 pcaPP_1.7 mvtnorm_0.9-8 nnet_7.3-1 mclust_3.4 MASS_7.3-4 [25] lars_0.9-7 e1071_1.5-22 class_7.3-1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] subsetting by groups, with conditions
Hi, I think you can also use plyr for this, dft - read.table(textConnection(P1idVeg1Veg2AreaPoly2 P2ID 1 p p 1 1 1 p p 1.5 2 2 p p 2 3 2 p h 3.5 4), header=T) library(plyr) ddply(dft, .(P1id), function(.df) { .ddf - subset(.df, as.character(Veg1)==as.character(Veg2)) .ddf[which.max(.ddf$AreaPoly2), ] }) HTH, baptiste 2009/12/29 Seth W Bigelow sbige...@fs.fed.us: I have a data set similar to this: P1id Veg1 Veg2 AreaPoly2 P2ID 1 p p 1 1 1 p p 1.5 2 2 p p 2 3 2 p h 3.5 4 For each group of Poly1id records, I wish to output (subset) the record which has largest AreaPoly2 value, but only if Veg1=Veg2. For this example, the desired dataset would be P1id Veg1 Veg2 AreaPoly2 P2ID 1 p p 1.5 2 2 p p 2 3 Can anyone point me in the right direction on this? Dr. Seth W. Bigelow Biologist, USDA-FS Pacific Southwest Research Station 1731 Research Park Drive, Davis California [[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] graph shading is overlaying axes
On 12/28/2009 10:38 PM, Dean1 wrote: How can I resolve this problem?... As a general example, plot (1:4) polygon(c(0,0,5,5),c(0,5,5,0), border=lavenderblush1, col = lavenderblush1) ###see how this overlays the axes lines #I have tried... for (k in 1:4) axis(k, lwd.ticks=0, label=F) #...but this misses the corners Hi Dean, In addition to what Jim Holtman wrote, you can try the fullaxis function in the plotrix package. 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] R2
Nancy - Please notice that ** is not an R operator. The caret (^) is the exponentiation operator in R. - Phil On Tue, 29 Dec 2009, Nancy Adam wrote: Hi everyone, I tried to write the code of computing R2 for a regression system but I failed. This is the code I use for computing RMSE: my_svm_model - function(myformula, mydata, mytestdata) { mymodel - svm(myformula, data=mydata) mytest - predict(mymodel, mytestdata) error - mytest - mytestdata[,1] -sqrt(mean(error**2)) } can anyone please tell me what I have to change to compute R2 instead of RMSE? Many thanks, Nancy _ [[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] Histogram/BoxPlot Panel
Dear All, I am given 15 different data sets and I would like to generate a panel showing all of them. Each dataset will be presented either as a boxplot or as a histogram. There are several possible ways to achieve this (as far as I know) (1) using plot and mfrow() (2) using lattice (3) using ggplot/ggplot2 I am not very experienced (to be euphemistic) about (2) and (3). My question then is: how would you try to organize these 15 histograms/boxplots into a single figure? Can anyone provide me with a simple example (with artificial data) for (2) and (3) (or point me to some targeted online resource)? Any suggestion is welcome. Many thanks Lorenzo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Histogram/BoxPlot Panel
Hi, Here is some artificial data followed by minimal ggplot2 and lattice examples, makeUpData - function(){ data.frame(x=sample(letters[1:4], 100, repl=TRUE), y=rnorm(100)) } datasets - replicate(15, makeUpData(), simplify=FALSE) names(datasets) - paste(dataset, seq_along(datasets), sep=) str(datasets) require(reshape) ## combine the datasets in one long format data.frame m - melt(datasets, meas=c(y)) str(m) require(ggplot2) ggplot(m)+ geom_boxplot(mapping=aes(x, value))+ facet_wrap(~L1) # or more concisely qplot(x, value, data=m, geom=boxplot, facets=~L1) require(lattice) bwplot(value~x | L1, data=m) HTH, baptiste 2009/12/29 Lorenzo Isella lorenzo.ise...@gmail.com: Dear All, I am given 15 different data sets and I would like to generate a panel showing all of them. Each dataset will be presented either as a boxplot or as a histogram. There are several possible ways to achieve this (as far as I know) (1) using plot and mfrow() (2) using lattice (3) using ggplot/ggplot2 I am not very experienced (to be euphemistic) about (2) and (3). My question then is: how would you try to organize these 15 histograms/boxplots into a single figure? Can anyone provide me with a simple example (with artificial data) for (2) and (3) (or point me to some targeted online resource)? Any suggestion is welcome. Many thanks Lorenzo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Histogram/BoxPlot Panel
I forgot the base graphics way, ## divide the window in 4x4 cells par(mfrow=n2mfrow(length(datasets))) ## loop over the list of datasets and plot each one be.quiet - lapply(datasets, function(ii) boxplot(y~x, data=ii)) ggplot2 has a website with many examples, http://had.co.nz/ggplot2/ as well as a book. Lattice also has a dedicated book, and a companion website with the figures, http://r-forge.r-project.org/projects/lmdvr/ HTH, baptiste 2009/12/29 baptiste auguie baptiste.aug...@googlemail.com: Hi, Here is some artificial data followed by minimal ggplot2 and lattice examples, makeUpData - function(){ data.frame(x=sample(letters[1:4], 100, repl=TRUE), y=rnorm(100)) } datasets - replicate(15, makeUpData(), simplify=FALSE) names(datasets) - paste(dataset, seq_along(datasets), sep=) str(datasets) require(reshape) ## combine the datasets in one long format data.frame m - melt(datasets, meas=c(y)) str(m) require(ggplot2) ggplot(m)+ geom_boxplot(mapping=aes(x, value))+ facet_wrap(~L1) # or more concisely qplot(x, value, data=m, geom=boxplot, facets=~L1) require(lattice) bwplot(value~x | L1, data=m) HTH, baptiste 2009/12/29 Lorenzo Isella lorenzo.ise...@gmail.com: Dear All, I am given 15 different data sets and I would like to generate a panel showing all of them. Each dataset will be presented either as a boxplot or as a histogram. There are several possible ways to achieve this (as far as I know) (1) using plot and mfrow() (2) using lattice (3) using ggplot/ggplot2 I am not very experienced (to be euphemistic) about (2) and (3). My question then is: how would you try to organize these 15 histograms/boxplots into a single figure? Can anyone provide me with a simple example (with artificial data) for (2) and (3) (or point me to some targeted online resource)? Any suggestion is welcome. Many thanks Lorenzo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R2
Nancy, There is a function in the caret package called defaultSummary that will compute both RMSE and R2 for you. Max On Dec 28, 2009, at 11:51 PM, Nancy Adam nancyada...@hotmail.com wrote: Hi everyone, I tried to write the code of computing R2 for a regression system but I failed. This is the code I use for computing RMSE: my_svm_model - function(myformula, mydata, mytestdata) { mymodel - svm(myformula, data=mydata) mytest - predict(mymodel, mytestdata) error - mytest - mytestdata[,1] -sqrt(mean(error**2)) } can anyone please tell me what I have to change to compute R2 instead of RMSE? Many thanks, Nancy _ [[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] Histogram/BoxPlot Panel
Hi: To make a more legible ordering of the plots, it might be a good idea to make m$L1 an ordered factor rather than a character variable: m$L1 - ordered(m$L1, levels = paste('dataset', 1:15, sep = '')) # Lattice bwplot(value ~ x | L1, data = m, as.table = TRUE) # ggplot2 ggplot(m)+ geom_boxplot(mapping=aes(x, value))+ facet_wrap(~L1) Nice example! HTH, Dennis On Tue, Dec 29, 2009 at 3:48 AM, baptiste auguie baptiste.aug...@googlemail.com wrote: Hi, Here is some artificial data followed by minimal ggplot2 and lattice examples, makeUpData - function(){ data.frame(x=sample(letters[1:4], 100, repl=TRUE), y=rnorm(100)) } datasets - replicate(15, makeUpData(), simplify=FALSE) names(datasets) - paste(dataset, seq_along(datasets), sep=) str(datasets) require(reshape) ## combine the datasets in one long format data.frame m - melt(datasets, meas=c(y)) str(m) require(ggplot2) ggplot(m)+ geom_boxplot(mapping=aes(x, value))+ facet_wrap(~L1) # or more concisely qplot(x, value, data=m, geom=boxplot, facets=~L1) require(lattice) bwplot(value~x | L1, data=m) HTH, baptiste 2009/12/29 Lorenzo Isella lorenzo.ise...@gmail.com: Dear All, I am given 15 different data sets and I would like to generate a panel showing all of them. Each dataset will be presented either as a boxplot or as a histogram. There are several possible ways to achieve this (as far as I know) (1) using plot and mfrow() (2) using lattice (3) using ggplot/ggplot2 I am not very experienced (to be euphemistic) about (2) and (3). My question then is: how would you try to organize these 15 histograms/boxplots into a single figure? Can anyone provide me with a simple example (with artificial data) for (2) and (3) (or point me to some targeted online resource)? Any suggestion is welcome. Many thanks Lorenzo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.
[R] problem reading from serial connection since 2.10.0
Dear list, I have a balance connected to the serial port of a windows machine (COM1) and I read the text output of the balance with scan(COM1, what=character, sep=\n, n=1) after calling the previous line I press the print key on the balance which triggers sending one line of text to the serial connection and with R 2.9.2 I get something like Read 1 item + 32.004 mg Now with R 2.10.1 (and previously with 2.10.0) I have to press the print key on the balance twice to get the same result, thus apparently I have to send two lines of text to make scan() reading only one. But this is only when reading from the serial port, not when reading from a text file on disk. The same is true for 2.10.1 on Linux (I did not try 2.9.2 nor 2.10.0 on Linux). I can't figure out from the documentation nor the NEWS whether something should be specified differently when calling scan since 2.10.0. Any ideas what this behaviour comes from? Here the sessionInfo() for the three cases I have tested: R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices utils datasets [6] methods base respectively: R version 2.10.1 (2009-12-14) i386-pc-mingw32 locale: [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C [5] LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base respectively: R version 2.10.1 (2009-12-14) x86_64-unknown-linux-gnu locale: [1] LC_CTYPE=de_DE.UTF-8 LC_NUMERIC=C [3] LC_TIME=de_DE.UTF-8LC_COLLATE=de_DE.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=de_DE.UTF-8 [7] LC_PAPER=de_DE.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils methods base other attached packages: [1] lattice_0.17-26 RODBC_1.3-1 loaded via a namespace (and not attached): [1] grid_2.10.1 Thanks a lot! Tom __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to append new data to saved data on disk efficiently
Hi, I currently combine multiple processed data (data frame) into a list and save the list as .rda using the save command. When new data come, I load the rda file, process the new data into a data frame, append the data frame to the end of the list, and save the whole list to the disk. The loading and saving steps are quite time consuming. Since I don't need to change the old data in the list when new data come, I wonder if there is an efficient way to update the rda efficiently, e.g. appending the new data to the rda file directly without loading the whole rda file? Any suggestions would be appreciated. thanks Jeff __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Newbie needs to count elements in a row
Hi, I have a n*m matrix and would like to count the number of elements not equal to NA in a ROW. e.g. x 1 2 3 NA 10 y 2 NA 8 9 NA Which function can I use to obtain 4 for row x and 3 for row y? Could you help me? I found some functions for columns but not for rows... Thank you very much! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Newbie needs to count elements in a row
Try this: rowSums(!is.na(x)) On Tue, Dec 29, 2009 at 11:49 AM, Verena Weber verenawe...@gmx.de wrote: Hi, I have a n*m matrix and would like to count the number of elements not equal to NA in a ROW. e.g. x 1 2 3 NA 10 y 2 NA 8 9 NA Which function can I use to obtain 4 for row x and 3 for row y? Could you help me? I found some functions for columns but not for rows... Thank you very much! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Newbie needs to count elements in a row
For a single row where mat is your matrix and r is the row sum(!is.na(mat[r,])) For every row in the matrix rowSums(!is.na(mat)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Verena Weber Sent: Tuesday, December 29, 2009 8:50 AM To: r-help@r-project.org Subject: [R] Newbie needs to count elements in a row Hi, I have a n*m matrix and would like to count the number of elements not equal to NA in a ROW. e.g. x 1 2 3 NA 10 y 2 NA 8 9 NA Which function can I use to obtain 4 for row x and 3 for row y? Could you help me? I found some functions for columns but not for rows... Thank you very much! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2009). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R on amazon's EC2 cloud?
On Sun, Dec 27, 2009 at 3:33 PM, Carlos J. Gil Bellosta c...@datanalytics.com wrote: I tried Amazon EC2 with R recently and wrote an entry about it to a blog I collaborate with: http://analisisydecision.es/probando-r-sobre-el-ec2-de-amazon/ (Unfortunately, it is in Spanish...) Google's translation is pretty readable and useful... http://translate.google.com/translate?js=yprev=_thl=enie=UTF-8layout=1eotf=1u=http%3A%2F%2Fanalisisydecision.es%2Fprobando-r-sobre-el-ec2-de-amazon%2Fsl=estl=en Michael [[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] Weird keyboard/buffer issue using OSX Client
When using up-arrow to retrieve the last executed command, or browse my history, each command becomes suffixed with a few lines worth of spaces. It's annoying having to backspace over this many spaces or manually move the cursor to perform edits. I'm currently using R 2.10.10 GUI 1.30 on Mac OSX 10.6. If I retrieve a command from my history using the history interface, the spaces are included. I dont remember the root cause of this-I don't think it was brought upon by an upgrade. Here are things I've done to try and troubleshoot: reset all of the settings I could find from within R delete my workspace delete any hidden files delete the command history file delete my preferences completely remove/uninstall R upgrade from 32 to 64 bit R somewhere along the lines I missed a preference or a hidden file. Here's a screenshot showing the issue. The screenshot was taken immediately after pressing up-arrow. http://www.neilkodner.com/images/skitch/R_mystery-20091229-093157.jpg Hopefully someone knows what to do about this. [[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] nls error message
Jim Bouldin wrote: When I try to run the following non-linear regression with variables index1 and prl3: beta = 4 nls(index1~beta*(1/prl3),start = list(beta = 4)) I get this error message: Error in nls(index1 ~ beta * (1/prl3), start = list(beta = 4)) : REAL() can only be applied to a 'numeric', not a 'logical' Please see the posting guide. For reproducibility, we'd need prl3 and index1. I've got no clue as to the REAL() to which this is referring. Any help appreciated. Thanks in advance. Try traceback(). Uwe Ligges Jim Bouldin Research Ecologist Department of Plant Sciences, UC Davis Davis CA, 95616 530-554-1740 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] svm regression/classification
Hi Nancy, Comments in line: On Sun, Dec 27, 2009 at 3:34 AM, Nancy Adam nancyada...@hotmail.com wrote: Hi everyone, Can anyone please tell whether there is a difference between the code for using svm in regression and code for using svm in classification? This is my code for regression, should I change it to do classification?: I'm not sure how to answer your question ... are you asking how you can explicitly tell the `svm` function to do classification vs. regression? Or are you asking if classification is better suited for your problem than regression? Are you trying to predict a label or some range of real valued numbers? Can you show us your `y` vector? -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 append new data to saved data on disk efficiently
You can keep each dataframe as a separate file and process them that way. You can look into storing in a relational database or using filehash. It all depends on how you want to process the data later. On Tue, Dec 29, 2009 at 8:40 AM, Hao Cen h...@andrew.cmu.edu wrote: Hi, I currently combine multiple processed data (data frame) into a list and save the list as .rda using the save command. When new data come, I load the rda file, process the new data into a data frame, append the data frame to the end of the list, and save the whole list to the disk. The loading and saving steps are quite time consuming. Since I don't need to change the old data in the list when new data come, I wonder if there is an efficient way to update the rda efficiently, e.g. appending the new data to the rda file directly without loading the whole rda file? Any suggestions would be appreciated. thanks Jeff __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://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.
Re: [R] R2
** works as exponentiation for me: 3**2 [1] 9 On Tue, Dec 29, 2009 at 6:10 AM, Phil Spector spec...@stat.berkeley.edu wrote: Nancy - Please notice that ** is not an R operator. The caret (^) is the exponentiation operator in R. - Phil On Tue, 29 Dec 2009, Nancy Adam wrote: Hi everyone, I tried to write the code of computing R2 for a regression system but I failed. This is the code I use for computing RMSE: my_svm_model - function(myformula, mydata, mytestdata) { mymodel - svm(myformula, data=mydata) mytest - predict(mymodel, mytestdata) error - mytest - mytestdata[,1] -sqrt(mean(error**2)) } can anyone please tell me what I have to change to compute R2 instead of RMSE? Many thanks, Nancy _ [[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] how can I use R functions in Fortran 90
Anny Huang annylhu...@gmail.com wrote: Is there a way that I can import R functions into Fortran? Especially, I want to generate random numbers from some not-so-common distributions (e.g. inverted chi square) but did not find any routines written in Fortran that deal with distributions other than uniform and normal. If you are interested in pure Fortran code for the problem, you could look at routine G01FCF here: http://gams.nist.gov/search.cgi?Pattern=chi+squareBoolean=ANDMatch=FullLimit=100Show=Yes GAMS (the Guide to Available Mathematical Software) has a lot of good code. -- Mike Prager, NOAA, Beaufort, NC * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R2
Gabor Grothendieck wrote: ** works as exponentiation for me: 3**2 [1] 9 Yes, but see ?** that it is just documented in a note and has been deprecated in S since 20 years... Uwe Ligges On Tue, Dec 29, 2009 at 6:10 AM, Phil Spector spec...@stat.berkeley.edu wrote: Nancy - Please notice that ** is not an R operator. The caret (^) is the exponentiation operator in R. - Phil On Tue, 29 Dec 2009, Nancy Adam wrote: Hi everyone, I tried to write the code of computing R2 for a regression system but I failed. This is the code I use for computing RMSE: my_svm_model - function(myformula, mydata, mytestdata) { mymodel - svm(myformula, data=mydata) mytest - predict(mymodel, mytestdata) error - mytest - mytestdata[,1] -sqrt(mean(error**2)) } can anyone please tell me what I have to change to compute R2 instead of RMSE? Many thanks, Nancy _ [[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] [BioC] make.cdf.package: Error: cannot allocate vector of size 1 Kb
This problem may well be due to the repeated R_alloc calls, and might be fixable by refactoring the code, but I am not sure that is the answer here. This package is designed for the 3' biased arrays (and works well enough for them), and isn't intended to be used for the newer random primer arrays. The makecdfenv/affy packages have been supplanted by the pdInfoBuilder/oligo packages for the newer generation of arrays. Crispin Miller's group was able to get makecdfenv to work by stripping out the background probes first, and have cdf packages available on their website if the end user insists on using affy for this array: http://xmap.picr.man.ac.uk/download which by the way appears to be down now. Anyway, the supported methods of analyzing these chip types are listed in the workflows page http://www.bioconductor.org/docs/workflows/oligoarrays/ and you will note that makecdfenv/affy is not one of them. Best, Jim Martin Morgan mtmor...@fhcrc.org 12/28/09 2:09 PM Peng Yu wrote: My machine has 8GB memory. I had quit all other programs that might take a lot of memory when I try the script (before I post the first message in this thread). The cdf file is of only 741 MB. It is strange to me to see the error. For me this tops out at about 13 gigs. The reason is I think in the C-level implementation details. R_alloc is called repeatedly during file parsing, where likely the author intends to Calloc / Free. Martin On Mon, Dec 28, 2009 at 2:38 AM, Wolfgang Huber whu...@embl.de wrote: Dear Peng Yu how big is the RAM of your computer? You could try with closing all other applications before running this script. You could try on a server with more RAM. I tried downloading the file whose URL who give below, but gave up after some failed rounds with the extraordinarily annoying and intrusive registration procedure that Affymetrix has set up for this. Let us know how it goes with the suggestions above, if they don't help, I'd try again with that. Best wishes Wolfgang I run the following example. The cdf file is downloaded from the following link. I'm wondering what the problem is with make.cdf.package. http://www.affymetrix.com/Auth/support/downloads/library_files/MoEx-1_0-st-v1.text.cdf.zip $ Rscript MoEx-1_0-st-v1.cdf.R library(makecdfenv) Loading required package: Biobase Welcome to Bioconductor Vignettes contain introductory material. To view, type 'openVignette()'. To cite Bioconductor, see 'citation(Biobase)' and for packages 'citation(pkgname)'. Loading required package: affy Loading required package: affyio sessionInfo() R version 2.10.0 (2009-10-26) x86_64-unknown-linux-gnu locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] makecdfenv_1.24.0 affyio_1.14.0 affy_1.24.2 Biobase_2.6.1 loaded via a namespace (and not attached): [1] preprocessCore_1.8.0 make.cdf.package('MoEx-1_0-st-v1.text.cdf', species='Mus_musculus') Reading CDF file. Error: cannot allocate vector of size 1 Kb Execution halted ___ Bioconductor mailing list bioconduc...@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/bioconductor Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- Wolfgang Huber EMBL http://www.embl.de/research/units/genome_biology/huber/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 ___ Bioconductor mailing list bioconduc...@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/bioconductor Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor ** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] question on avoiding the use of loops when working with large multidimensional arrays
Hi, I’m new to R and object-oriented programming. I work primarily with satellite datasets using IDL. I used IDL to ingest my data, run a spectral mixture algorithm and output a timeseries of a snow index in 16-bit integer band interleaved by line format (for most of China). In R, I read in the timeseries using the caTools package and my goal is to figure out how to extract slices of my data cube (details on dimensions below) and apply functions written in R without the use of a loop. The code below is an example of what I’m doing now and I’m sure there must be a better way. Thank you in advance for your help, which is greatly appreciated. I have spent some time with the R help materials, but unfortunately the learning curve is still steep my first week into R. # Reading in my data using caTools mydata=read.ENVI(rsma_subset_3s.bil,headerfile=paste (rsma_subset_3s.bil,.hdr,sep=)) dim(mydata) [1] 37 103 208 # my data is a 16-bit Integer in Band Interleaved by Line (bil) format # mydata [x,y,z] is latitude,longitude,value of an index per band (time) # what I want to do is create a ts object and run a function called bfast # on slices of the array without going through a loop because the actual size the of data # is [2400,1200,208] and looping takes a long time # The example loop below will run but takes a long time and I have numbers hardwired # in to loop over, which I’d like to avoid for (i in 1:37) { + for (j in 1:103) + # create ts object with proper time, frequency + slice - ts(mydata[i,j,1:208],start=c(2000,4),end=c (2009,4),frequency=23); + fit - bfast(slice,h=0.15,max.iter=1); + plot(fit) # just plotting to see if it’s working, but I will actually be extracting + # variables out of ‘fit’ + } } # I would also like to replace the numeric values of columns, rows, bands using # “length” so that in the future, I don’t have numbers hardwired in but I don’t think I’m # doing this correctly for a multidimensional array. Can the “dimnames” be used as an # alternate to do this? Kind regards, Cheney __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Problems when using lag() in plm package
Hi, I've been trying out the plm package, which seems like a great boon to those who want to analyze panel data in R. I haven't started to use the estimation functions themselves - for now I am just interested in having a robust way to deal with lags in unbalanced panel data, since it is such a royal pain to deal with all the special cases. However, In my tests, I found behavior that seems strange at a minimum, and potentially a bug, and I would like to understand it better. I demonstrate these using an example, which I include below. Basically, I want the function to deal correctly with a panel that contains a unit (unit 1 in the example), that has a gap (missing entry for a particular point in time (year 4 in the example)). What the example demonstrates is that the outcome when the unit 1 observations are lagged is different based on whether year 4 is present in the observations on *unit 2*. If year 4 is present for unit 2, the lagged pseries is suitable for binding to the original data frame, with missing values at the correct locations. The names() for the lagged series are incorrect, but I don't really care about them. So this is basically the behavior I had hoped to see. However, if year 4 is not present in unit2, the gap is not detected. A cbind() with the original series is now incorrect data, although the names() of the lagged series could now be interpreted as correct in the strictest sense. However, if this is the expected behavior, that means that all estimation functions will have to examine the names() of each series, which seems like a lot of work. My question then is: How should I interpret these results? Are gaps in the data disallowed? And if so, should the creation of a pdata.frame with gaps result in an error? MY EXAMPLE FOLLOWS: # Construct pdata.frame with gap in unit 1, at year 4 pdu - pdata.frame( + data.frame( + i=c(rep(1,6),rep(2,3)), + t=c(1:3,5:7,2:4), + x=1:9 + ) + ) # Using cbind() to view the series with its lagged # counterpart produces the expected result cbind( pdu$i, pdu$t, pdu$x , lag(pdu$x)) [,1] [,2] [,3] [,4] 1-1111 NA 1-21221 1-31332 1-5154 NA 1-61654 1-71765 2-2227 NA 2-32387 2-42498 # The labels of the lagged series do not seem correct # (the second NA should be labeled as 1-4, not as 1-3), lag(pdu$x) 1-1 1-2 1-3 1-5 1-6 1-7 2-2 2-3 NA 1 2 NA 4 5 NA 7 8 attr(,class) [1] integer # Again, construct pdata.frame with (the same) gap in # unit 1, but now, that time observation (4), is # not present in unit 2 either pdu - pdata.frame( + data.frame( + i=c(rep(1,6),rep(2,3)), + t=c(1:3,5:7,1:3), + x=1:9 + ) + ) # Now the cbin() of the two series seems wrong cbind( pdu$i, pdu$t, pdu$x , lag(pdu$x)) [,1] [,2] [,3] [,4] 1-1111 NA 1-21221 1-31332 1-51443 1-61554 1-71665 2-1217 NA 2-22287 2-32398 # But the labels of the lagged series could be # interpreted as being correct in this case lag(pdu$x) 1-1 1-2 1-3 1-5 1-6 1-7 2-1 2-2 NA 1 2 3 4 5 NA 7 8 attr(,class) [1] integer Best regards, Magnus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R2
On Tue, 29 Dec 2009, Phil Spector wrote: Nancy - Please notice that ** is not an R operator. The caret (^) is the exponentiation operator in R. - Phil Actually, no, 2**3 [1] 8 Indeed ^ is the preferred exponentiation operator, but ** has 'always' been allowed. See the following note in ?^ Note: ‘**’ is translated in the parser to ‘^’, but this was undocumented for many years. It appears as an index entry in Becker _et al_ (1988), pointing to the help for ‘Deprecated’ but is not actually mentioned on that page. Even though it has been deprecated in S for 20 years, it is still accepted. I added that note in May 2008 (and it is not intended to be a reference to current versions of S-PLUS, since we cannot keep checking that, but that Svr4 accepted it). On Tue, 29 Dec 2009, Nancy Adam wrote: Hi everyone, I tried to write the code of computing R2 for a regression system but I failed. This is the code I use for computing RMSE: my_svm_model - function(myformula, mydata, mytestdata) { mymodel - svm(myformula, data=mydata) mytest - predict(mymodel, mytestdata) error - mytest - mytestdata[,1] -sqrt(mean(error**2)) } can anyone please tell me what I have to change to compute R2 instead of RMSE? Many thanks, Nancy _ [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Remove double quotation marks
Dear All, I am not sure how to remove double quotation marks in a string, e.g., paste(variable, 1). Can anybody please help me solve it? Thank you in advance. Lisa -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990502.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Remove double quotation marks
On 29/12/2009 1:16 PM, Lisa wrote: Dear All, I am not sure how to remove double quotation marks in a string, e.g., paste(variable, 1). Can anybody please help me solve it? Thank you in advance. I think you need to tell us what is wrong with what you get from that. When I look at the result: cat(paste(variable, 1), \n) variable 1 I see no quotation marks. (If you use print() you'll see some, but they aren't part of the string, they are just used in the default display by print().) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] apply a function over a factor
Dear R experts, I would like to substitute the values of a vector, say A, with the average values taken over a factor For example, lets assume A [1] 1 2 3 4 5 6 7 8 9 10 B [1] 1 2 2 4 4 4 7 7 7 7 Levels: 1 2 4 7 I need to have 1.0 2.5 2.5 5.0 5.0 5.0 8.5 8.5 8.5 8.5 8.5 Thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Remove double quotation marks
Thank you for your reply. But in the following case, “cat()” or “print()” doesn’t work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Duncan Murdoch wrote: On 29/12/2009 1:16 PM, Lisa wrote: Dear All, I am not sure how to remove double quotation marks in a string, e.g., paste(variable, 1). Can anybody please help me solve it? Thank you in advance. I think you need to tell us what is wrong with what you get from that. When I look at the result: cat(paste(variable, 1), \n) variable 1 I see no quotation marks. (If you use print() you'll see some, but they aren't part of the string, they are just used in the default display by print().) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990516.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply a function over a factor
have a look at ?ave(), e.g., A - 1:10 B - factor(c(1,2,2,4,4,4,7,7,7,7)) ave(A, B) I hope it helps. Best, Dimitris farida...@gmail.com wrote: Dear R experts, I would like to substitute the values of a vector, say A, with the average values taken over a factor For example, lets assume A [1] 1 2 3 4 5 6 7 8 9 10 B [1] 1 2 2 4 4 4 7 7 7 7 Levels: 1 2 4 7 I need to have 1.0 2.5 2.5 5.0 5.0 5.0 8.5 8.5 8.5 8.5 8.5 Thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply a function over a factor
Thanks! That's what I need. On Tue, Dec 29, 2009 at 1:33 PM, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: have a look at ?ave(), e.g., A - 1:10 B - factor(c(1,2,2,4,4,4,7,7,7,7)) ave(A, B) I hope it helps. Best, Dimitris farida...@gmail.com wrote: Dear R experts, I would like to substitute the values of a vector, say A, with the average values taken over a factor For example, lets assume A [1] 1 2 3 4 5 6 7 8 9 10 B [1] 1 2 2 4 4 4 7 7 7 7 Levels: 1 2 4 7 I need to have 1.0 2.5 2.5 5.0 5.0 5.0 8.5 8.5 8.5 8.5 8.5 Thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] extract value from first column based on value in second column
Hi all, I have two columns of data, the first consists of parameter estimates and the second probability estimates. I would like to extract the value from the first column based on the max value of column two, but not sure how to do this other than by extracting the value and then manually finding the value in the first column. Anyone know how to do this? Basically, I need to find the row number for the maximum in column two and use that value to extract the value at the same row number in column one. Thanks for any help, Wade [[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] Remove double quotation marks
On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, “cat()” or “print()” doesn’t work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] extract value from first column based on value in second column
Will something like this work for you: x - cbind(runif(10), runif(10)) x [,1] [,2] [1,] 0.26550866 0.2059746 [2,] 0.37212390 0.1765568 [3,] 0.57285336 0.6870228 [4,] 0.90820779 0.3841037 [5,] 0.20168193 0.7698414 [6,] 0.89838968 0.4976992 [7,] 0.94467527 0.7176185 [8,] 0.66079779 0.9919061 [9,] 0.62911404 0.3800352 [10,] 0.06178627 0.7774452 x[which.max(x[,2]),1] [1] 0.6607978 On Tue, Dec 29, 2009 at 1:48 PM, Wade Wall wade.w...@gmail.com wrote: Hi all, I have two columns of data, the first consists of parameter estimates and the second probability estimates. I would like to extract the value from the first column based on the max value of column two, but not sure how to do this other than by extracting the value and then manually finding the value in the first column. Anyone know how to do this? Basically, I need to find the row number for the maximum in column two and use that value to extract the value at the same row number in column one. Thanks for any help, Wade [[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.htmlhttp://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.
[R] (no subject)
Hi, I wonder how to pass several functions and their arguments as arguments to a function. For example, the main function is f = function(X ) { process(X) ... process(X) } I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2), g3(X, par3). par1, par2 and par3 are parameters and of different types. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] pass functions and arguments to function
Hi, I wonder how to pass several functions and their arguments as arguments to a function. For example, the main function is f = function(X ) { process1(X) ... process2(X) } I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2), g3(X, par3). par1, par2 and par3 are parameters and of different types. I would like to pass g1, g2, g3 and their arguments to f and g1, g2, g3 may appear to be in different orders. So that final effect of the passing is f = function(X ) { process1(X) g1(X, par1) g2(X, par2) g3(X, par3) process2(X) } If I pass g2(X, par2),g3(X, par3), g1(X, par1) to f, I would expect to get the effect of f = function(X ) { process1(X) g2(X, par2) g3(X, par3) g1(X, par1) process2(X) } Appreciate any suggestions. thanks Jeff ps please ignore my previous blank subject email. It was accidentally sent before the letter was completed. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] as.numeric is truncating!
I am trying to convert a string to a double using as.numeric However, R is truncating the results! Options(digits) is set to 7. Can anyone shed some light on this? Thanks! b[1] [1] 116.28125 summary(b[1]) Length Class Mode 1 character character c - as.numeric(b[1]) c [1] 116.2812 -- View this message in context: http://n4.nabble.com/as-numeric-is-truncating-tp990546p990546.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] as.numeric is truncating!
ticspd wrote: I am trying to convert a string to a double using as.numeric However, R is truncating the results! Options(digits) is set to 7. Can anyone shed some light on this? Thanks! b[1] [1] 116.28125 summary(b[1]) Length Class Mode 1 character character c - as.numeric(b[1]) c [1] 116.2812 Try the following: ?round (Note: and look in the Details section). as.numeric(116.28135) Set options(digits=8) and do the print again. R is not truncating; it is following certain rounding rules on printing the number given the required numbers of digits to show. Berend -- View this message in context: http://n4.nabble.com/as-numeric-is-truncating-tp990546p990568.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] lmer: how to lmer with no intercept
Hello, How do I fit a mixed effect model with no intercept using lmer()? Is the following syntax correct? lmer(y ~ -1+x1+x2+(-1+x1+x2|id), data=dt) Thanks, Julia -- View this message in context: http://n4.nabble.com/lmer-how-to-lmer-with-no-intercept-tp990493p990493.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plotting power function to practice data
Hello, I have practice data of motor action in the format: S | Cond. | Time +-+ 01 | c | 1.23 01 | nc| 0.89 02 | c | 2.15 02 | nc| 1.80 . I want to look at the learning curves graphically. I will appreciate pointers to relevant functions / packages. Thanks in advance, dror [[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] Newbie needs to count elements in a row
Could you just transpose the matrix? Otherwise you can write a simple function that should work. Try this -(mat1 - matrix(c(1, 2, 3, NA, 10, 2, NA, 8, 9, NA),nrow=2)) gl - function(x)length(x[!is.na(x)] apply(mat1, 1, gl) == -- On Tue, 12/29/09, Verena Weber verenawe...@gmx.de wrote: From: Verena Weber verenawe...@gmx.de Subject: [R] Newbie needs to count elements in a row To: r-help@r-project.org Received: Tuesday, December 29, 2009, 8:49 AM Hi, I have a n*m matrix and would like to count the number of elements not equal to NA in a ROW. e.g. x 1 2 3 NA 10 y 2 NA 8 9 NA Which function can I use to obtain 4 for row x and 3 for row y? Could you help me? I found some functions for columns but not for rows... [[elided Yahoo spam]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Remove double quotation marks
?get something like: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) x - 5 cbind(v1, v2, get(paste('v', x, sep=''))) v1 v2 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 On Tue, Dec 29, 2009 at 3:54 PM, Lisa lisa...@gmail.com wrote: Thank you for your help. But here I just want to combine some vectors by column based on the numbers determined by other R script. For example, I have five vectors: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) If I am going to combine the first two vectors, and one more other vector determined by my other R script, say, vector 5. Then my R script is x - 5 cbind(v1, v2, paste(v, x, sep = )) The output is v1 v2 [1,] 0 1 v5 [2,] 1 1 v5 [3,] 0 0 v5 This is not what I want. I want to get this: v1 v2 v5 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 Can you give me further suggestions or comments? Thanks a lot. Lisa Barry Rowlingson wrote: On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, cat() or print() doesnt work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990586.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.htmlhttp://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.
Re: [R] Remove double quotation marks
Thanks. I also need column name v5. Lisa jholtman wrote: ?get something like: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) x - 5 cbind(v1, v2, get(paste('v', x, sep=''))) v1 v2 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 On Tue, Dec 29, 2009 at 3:54 PM, Lisa lisa...@gmail.com wrote: Thank you for your help. But here I just want to combine some vectors by column based on the numbers determined by other R script. For example, I have five vectors: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) If I am going to combine the first two vectors, and one more other vector determined by my other R script, say, vector 5. Then my R script is x - 5 cbind(v1, v2, paste(v, x, sep = )) The output is v1 v2 [1,] 0 1 v5 [2,] 1 1 v5 [3,] 0 0 v5 This is not what I want. I want to get this: v1 v2 v5 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 Can you give me further suggestions or comments? Thanks a lot. Lisa Barry Rowlingson wrote: On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, cat() or print() doesnt work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990586.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.htmlhttp://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. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990591.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Remove double quotation marks
It seems from your example that you're assuming all of the vectors have the same length. If this is the case, then a data.frame might be your friend. df - data.frame( v1 = c(0, 1, 0), v2 = c(1, 1, 0), v3 = c(2, 1, 2), v4 = c(2, 2, 1), v5 = c(0, 1, 1) ) x - 5 get.var - c(v1, v2, paste(v, x, sep=)) df[, get.var] Or, if you know your variables in the data.frame will be named sequentially df[, c(1, 2, x)] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Lisa Sent: Tuesday, December 29, 2009 3:55 PM To: r-help@r-project.org Subject: Re: [R] Remove double quotation marks Thank you for your help. But here I just want to combine some vectors by column based on the numbers determined by other R script. For example, I have five vectors: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) If I am going to combine the first two vectors, and one more other vector determined by my other R script, say, vector 5. Then my R script is x - 5 cbind(v1, v2, paste(v, x, sep = )) The output is v1 v2 [1,] 0 1 v5 [2,] 1 1 v5 [3,] 0 0 v5 This is not what I want. I want to get this: v1 v2 v5 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 Can you give me further suggestions or comments? Thanks a lot. Lisa Barry Rowlingson wrote: On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, cat() or print() doesn't work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990586.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2009). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Effect of na.omit()
I had an NA in one row of my data frame, so I called na.omit(). But I do not understand where that row disappeared to. fri=na.omit(fri) fri Date.OnlyDAY Hour Min15 Quarter Arrival.Val Arrival4 109/05/2008 Friday833 3 328 210/24/2008 Friday 2186 4 287 310/31/2008 Friday833 4 205 410/31/2008 Friday834 4 205 510/31/2008 Friday835 4 123 1233 08/28/2009 Friday0 2 3 123 1234 09/18/2009 Friday 2292 3 82 1235 09/18/2009 Friday 2393 3 205 fri[1235,] Date.Only DAY Hour Min15 Quarter Arrival.Val Arrival4 NA NA NA NANA NA NA NA fri[1234,] Date.OnlyDAY Hour Min15 Quarter Arrival.Val Arrival4 1235 09/18/2009 Friday 2393 3 205 So, the index numbers of the rows do not seem to have been updated. They are not part of my data frame (I think), so why didn't the rows renumber themselves? Thanks, Jim Rome __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Remove double quotation marks
Your script works well. Thank you very mcuh. Lisa Nutter, Benjamin wrote: It seems from your example that you're assuming all of the vectors have the same length. If this is the case, then a data.frame might be your friend. df - data.frame( v1 = c(0, 1, 0), v2 = c(1, 1, 0), v3 = c(2, 1, 2), v4 = c(2, 2, 1), v5 = c(0, 1, 1) ) x - 5 get.var - c(v1, v2, paste(v, x, sep=)) df[, get.var] Or, if you know your variables in the data.frame will be named sequentially df[, c(1, 2, x)] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Lisa Sent: Tuesday, December 29, 2009 3:55 PM To: r-help@r-project.org Subject: Re: [R] Remove double quotation marks Thank you for your help. But here I just want to combine some vectors by column based on the numbers determined by other R script. For example, I have five vectors: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) If I am going to combine the first two vectors, and one more other vector determined by my other R script, say, vector 5. Then my R script is x - 5 cbind(v1, v2, paste(v, x, sep = )) The output is v1 v2 [1,] 0 1 v5 [2,] 1 1 v5 [3,] 0 0 v5 This is not what I want. I want to get this: v1 v2 v5 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 Can you give me further suggestions or comments? Thanks a lot. Lisa Barry Rowlingson wrote: On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, cat() or print() doesn't work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990586.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2009). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990599.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Effect of na.omit()
On 29-Dec-09 21:11:38, James Rome wrote: I had an NA in one row of my data frame, so I called na.omit(). But I do not understand where that row disappeared to. fri=na.omit(fri) fri Date.OnlyDAY Hour Min15 Quarter Arrival.Val Arrival4 109/05/2008 Friday833 3 328 210/24/2008 Friday 2186 4 287 310/31/2008 Friday833 4 205 410/31/2008 Friday834 4 205 510/31/2008 Friday835 4 123 1233 08/28/2009 Friday0 2 3 123 1234 09/18/2009 Friday 2292 3 82 1235 09/18/2009 Friday 2393 3 205 fri[1235,] Date.Only DAY Hour Min15 Quarter Arrival.Val Arrival4 NA NA NA NANA NA NA NA fri[1234,] Date.OnlyDAY Hour Min15 Quarter Arrival.Val Arrival4 1235 09/18/2009 Friday 2393 3 205 So, the index numbers of the rows do not seem to have been updated. They are not part of my data frame (I think), so why didn't the rows renumber themselves? Thanks, Jim Rome Because the numbers which are displayed at the left of the rows are not the row numbers of the structure being displayed, but they are in fact row *names*! These are so assigned (by default) when the dataframe is created. Example: DF - data.frame(col1=c(1,2,3,4),col2=c(2,3,4,5),col3=c(3,4,5,6)) DF # col1 col2 col3 # 1123 # 2234 # 3345 # 4456 row.names(DF) # [1] 1 2 3 4 DF[c(1,3,4),] # col1 col2 col3 # 1123 # 3345 # 4456 row.names(DF) - c(A,B,C,D) DF # col1 col2 col3 # A123 # B234 # C345 # D456 DF[c(1,3,4),] # col1 col2 col3 # A123 # C345 # D456 So the (1,2,3,4) row-names - (1,3,4) are treated exactly like the row-names (A,B,C,D) - (A,C,D). If you want to re-number the rows after eliminating some rows (with na.omit) then you could do row.names(fri) - (1:nrow(fri)) Example: DF1 - DF[c(1,3,4),] DF1 # col1 col2 col3 # A123 # C345 # D456 row.names(DF1) - (1:nrow(DF1)) DF1 # col1 col2 col3 # 1123 # 2345 # 3456 However, often it is very useful to keeep the original numbering (i.e. the numerical row-names), since this is then a record of which rows in the dataframe got used. For example, in a regression with some missing data coded as NA, the model-matrix will retain the original numbering, so yhou can identify which cases (rows) got used by looking at the row.names() of the model matrix. Since these are returned as numeric values, the result can be used as an index into the original dataset. Hoping this helps, Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 29-Dec-09 Time: 21:33:10 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] as.numeric is truncating!
ah perfect .. digits = 8 is actually 8 digits TOTAL, not 8 digits after the decimal point! setting the default to 15 works for me thank you! Berend Hasselman wrote: ticspd wrote: I am trying to convert a string to a double using as.numeric However, R is truncating the results! Options(digits) is set to 7. Can anyone shed some light on this? Thanks! b[1] [1] 116.28125 summary(b[1]) Length Class Mode 1 character character c - as.numeric(b[1]) c [1] 116.2812 Try the following: ?round (Note: and look in the Details section). as.numeric(116.28135) Set options(digits=8) and do the print again. R is not truncating; it is following certain rounding rules on printing the number given the required numbers of digits to show. Berend -- View this message in context: http://n4.nabble.com/as-numeric-is-truncating-tp990546p990594.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Outage in Copenhagen tomorrow
This came in at 11:21 today: From 30/12-2009 at 15.30 untill 31/12-2009 at 08.00, ALL IT services at SUND-IT will be shut down! ALL forms of electronic communication will be affected at SUND; VPN, Webmail, Mail, Print, Network drives, Servers ie. Furthermore, Panum, CSS, Teilum, Museion and Biocenteret will have no access to the Internet. The time of restoration of normal IT services, will be updated at http://it.sund.ku.dk the 30. December at 20.00 and 22.00. This is a planned upgrade of firewalls, which can’t be implemented without impacting IT services. (Timings are CET) Apart from my personal activities (mail and remote access to servers and desktop systems), this is also going to block access to bugs.r-project.org. Hopefully, things will return to normal afterwards. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] The RSQLite version of dbGetQuery drops colums
Hi Magnus, Magnus Torfason zulutime.net at gmail.com writes: I just noticed (the hard way of course) that when a query returns 0 rows, the columns in the resulting data.frame get dropped as well. See the following example code (where conn is an active connection to an SQLite db): dbGetQuery(conn, select 1 as hey, 2 as ho where 1) hey ho 1 1 2 dbGetQuery(conn, select 1 as hey, 2 as ho where 0) data frame with 0 columns and 0 rows I believe that the second query should return a 0x2 data.frame instead, that is, the same value as: I agree that keeping the column dimension is sensible. I will see about fixing that for the next release. Any thoughts? Is this a bug, and are the developers of RSQLite reading this? A much better forum for RSQLite issues is the r-sig-db list. + seth __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] pass functions and arguments to function
On 29/12/2009 3:08 PM, Hao Cen wrote: Hi, I wonder how to pass several functions and their arguments as arguments to a function. For example, the main function is f = function(X ) { process1(X) ... process2(X) } I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2), g3(X, par3). par1, par2 and par3 are parameters and of different types. I would like to pass g1, g2, g3 and their arguments to f and g1, g2, g3 may appear to be in different orders. So that final effect of the passing is Just pass them. If you know there are three functions, set up f as f - function(X, f1, f2, f3, par1, par2, par3) { process1(X) f1(X, par1) f2(X, par2) f3(X, par3) process2(X) } and call it as f(X, g1, g2, g3, par1, par2, par3) If you don't know how many functions there will be, put them in a list: f - function(X, fs, pars) { process1(X) for (i in 1:length(fs)) fs[[i]](pars[[i]]) process2(X) } and call it as f(X, list(g1, g2, g3), list(par1, par2, par3)) Duncan Murdoch f = function(X ) { process1(X) g1(X, par1) g2(X, par2) g3(X, par3) process2(X) } If I pass g2(X, par2),g3(X, par3), g1(X, par1) to f, I would expect to get the effect of f = function(X ) { process1(X) g2(X, par2) g3(X, par3) g1(X, par1) process2(X) } Appreciate any suggestions. thanks Jeff ps please ignore my previous blank subject email. It was accidentally sent before the letter was completed. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] pass functions and arguments to function
Thanks. I don't know how many functions there will be. What if g1, g2, g3 have variable number of parameters? say g1 has parg1a, parg1b, and g3 has parg3a, parg3b, parg3c, parg4d. f - function(X, fs, pars) { process1(X) for (i in 1:length(fs)) fs[[i]](pars[[i]]) # doesn't work here process2(X) } On Tue, December 29, 2009 4:57 pm, Duncan Murdoch wrote: On 29/12/2009 3:08 PM, Hao Cen wrote: Hi, I wonder how to pass several functions and their arguments as arguments to a function. For example, the main function is f = function(X ) { process1(X) ... process2(X) } I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2), g3(X, par3). par1, par2 and par3 are parameters and of different types. I would like to pass g1, g2, g3 and their arguments to f and g1, g2, g3 may appear to be in different orders. So that final effect of the passing is Just pass them. If you know there are three functions, set up f as f - function(X, f1, f2, f3, par1, par2, par3) { process1(X) f1(X, par1) f2(X, par2) f3(X, par3) process2(X) } and call it as f(X, g1, g2, g3, par1, par2, par3) If you don't know how many functions there will be, put them in a list: f - function(X, fs, pars) { process1(X) for (i in 1:length(fs)) fs[[i]](pars[[i]]) process2(X) } and call it as f(X, list(g1, g2, g3), list(par1, par2, par3)) Duncan Murdoch f = function(X ) { process1(X) g1(X, par1) g2(X, par2) g3(X, par3) process2(X) } If I pass g2(X, par2),g3(X, par3), g1(X, par1) to f, I would expect to get the effect of f = function(X ) { process1(X) g2(X, par2) g3(X, par3) g1(X, par1) process2(X) } Appreciate any suggestions. thanks Jeff ps please ignore my previous blank subject email. It was accidentally sent before the letter was completed. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] plotting circles with symbols()
Hello, I am not able to plot a circle of a given radius using symbols(). In the example below, the circle appears too large: plot(0, 0, xlim = c(-1, 1), ylim = c(-1, 1)) symbols(0, 0, circles = 1, inches = FALSE, add = TRUE) What's happening? Ery __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] pass functions and arguments to function
On 29/12/2009 5:24 PM, Hao Cen wrote: Thanks. I don't know how many functions there will be. What if g1, g2, g3 have variable number of parameters? say g1 has parg1a, parg1b, and g3 has parg3a, parg3b, parg3c, parg4d. pars could be a list of lists of parameters instead of a list of parameters, then the calls could be do.call(fs[[i]], pars[[i]]) But it's very unlikely that you are doing something that's a good idea. Duncan Murdoch f - function(X, fs, pars) { process1(X) for (i in 1:length(fs)) fs[[i]](pars[[i]]) # doesn't work here process2(X) } On Tue, December 29, 2009 4:57 pm, Duncan Murdoch wrote: On 29/12/2009 3:08 PM, Hao Cen wrote: Hi, I wonder how to pass several functions and their arguments as arguments to a function. For example, the main function is f = function(X ) { process1(X) ... process2(X) } I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2), g3(X, par3). par1, par2 and par3 are parameters and of different types. I would like to pass g1, g2, g3 and their arguments to f and g1, g2, g3 may appear to be in different orders. So that final effect of the passing is Just pass them. If you know there are three functions, set up f as f - function(X, f1, f2, f3, par1, par2, par3) { process1(X) f1(X, par1) f2(X, par2) f3(X, par3) process2(X) } and call it as f(X, g1, g2, g3, par1, par2, par3) If you don't know how many functions there will be, put them in a list: f - function(X, fs, pars) { process1(X) for (i in 1:length(fs)) fs[[i]](pars[[i]]) process2(X) } and call it as f(X, list(g1, g2, g3), list(par1, par2, par3)) Duncan Murdoch f = function(X ) { process1(X) g1(X, par1) g2(X, par2) g3(X, par3) process2(X) } If I pass g2(X, par2),g3(X, par3), g1(X, par1) to f, I would expect to get the effect of f = function(X ) { process1(X) g2(X, par2) g3(X, par3) g1(X, par1) process2(X) } Appreciate any suggestions. thanks Jeff ps please ignore my previous blank subject email. It was accidentally sent before the letter was completed. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] test of proportions
Hi r-users, I would like to use prop.test code and I also calculate manually to test the proportions for 2 groups. The problem is the answer for the p-value calculated manually are different from prop.test. Here are the results: ## Manually z value: z= (phat-p)/sqrt(pq/n) = (.084-.081)/sqrt(.081(1-.081)/691)=0.289, pvalue=0.7718 ## Using prop.test code low - c(56,58) tot - c(691,691) prop.test(low, tot, p = c(56/691,58/691), alternative = two.sided, conf.level = 0.95, correct = TRUE) 2-sample test for given proportions with continuity correction data: low out of tot, null probabilities c(56/691, 58/691) X-squared = 0.0096, df = 2, p-value = 0.9952 alternative hypothesis: two.sided null values: prop 1 prop 2 0.08104197 0.08393632 sample estimates: prop 1 prop 2 0.08104197 0.08393632 Thank you so much for any help given. [[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] lmer: how to lmer with no intercept
On Tue, Dec 29, 2009 at 11:46 AM, Julia7 liujul...@yahoo.com wrote: Hello, How do I fit a mixed effect model with no intercept using lmer()? Is the following syntax correct? lmer(y ~ -1+x1+x2+(-1+x1+x2|id), data=dt) Yes. An alternative, which I prefer, is lmer(y ~ 0 + x1 + x2 + (0 + x1 + x2|id), dt) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] plotting circles with symbols()
The circle is not too large; it just uses your x-units for the radius and your plotting region isn't square. Here are some things to try: plot(0, 0, xlim = c(-1, 1), ylim = c(-1, 1)) symbols(0, 0, circles = 1, inches = FALSE, add = TRUE) abline(v = c(-1,1)) # shows that x-units 'fit' abline(h = c(-1,1)) # shows that y-units don't fit par(pty = s) # set up square plot plot(0, 0, xlim = c(-1, 1), ylim = c(-1, 1)) symbols(0, 0, circles = 1, inches = FALSE, add = TRUE) # set the y/x-aspect (see ?plot.window) plot(0, 0, xlim = c(-1, 1), ylim = c(-1, 1), asp = 1) symbols(0, 0, circles = 1, inches = FALSE, add = TRUE) -Peter Ehlers eariasca wrote: Hello, I am not able to plot a circle of a given radius using symbols(). In the example below, the circle appears too large: plot(0, 0, xlim = c(-1, 1), ylim = c(-1, 1)) symbols(0, 0, circles = 1, inches = FALSE, add = TRUE) What's happening? Ery __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Peter Ehlers University of Calgary 403.202.3921 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] test of proportions
You need to learn how to use prop.test properly. Is this a ONE-sample test or TWO-sample test? Perhaps this will help: #hand calculation phat - 58/691 p - 56/691 q - 1-p n - 691 z - (phat-p)/sqrt(p*q/n) z [1] 0.2787970 pnorm(-z)*2 [1] 0.7804006 #prop.test prop.test(x=58, n=691, p=56/691, correct = FALSE) 1-sample proportions test without continuity correction data: 58 out of 691, null probability 56/691 X-squared = 0.0777, df = 1, p-value = 0.7804 alternative hypothesis: true p is not equal to 0.08104197 # Note the 'without' continuity correction part -Peter Ehlers Roslina Zakaria wrote: Hi r-users, � I would like to use prop.test code and I also calculate manually to test the proportions for 2 groups.� The problem is the answer for the p-value�calculated manually are different from prop.test.� Here are the results: � ## Manually � z value: z= (phat-p)/sqrt(pq/n) = (.084-.081)/sqrt(.081(1-.081)/691)=0.289, pvalue=0.7718 � ## Using prop.test code low - c(56,58) tot - c(691,691) prop.test(low, tot, p = c(56/691,58/691), alternative = two.sided, conf.level = 0.95, correct = TRUE) ��� 2-sample test for given proportions with continuity correction data:� low out of tot, null probabilities c(56/691, 58/691) X-squared = 0.0096, df = 2, p-value = 0.9952 alternative hypothesis: two.sided null values: ��� prop 1 prop 2 0.08104197 0.08393632 sample estimates: ��� prop 1 prop 2 0.08104197 0.08393632 � � Thank you so much for any help given. [[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. -- Peter Ehlers University of Calgary 403.202.3921 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] as.numeric is truncating!
ticspd wrote: I am trying to convert a string to a double using as.numeric However, R is truncating the results! No it isn't! As someone phrased it recently, there's a difference between an object and the display of an object. Ceci n'est pas une pipe. Options(digits) is set to 7. So numbers are _printed_ to 7-digit accuracy, yes. (And 116.28125 has 8 digits.) Can anyone shed some light on this? Subtract 116, and enlightenment should follow. Thanks! b[1] [1] 116.28125 summary(b[1]) Length Class Mode 1 character character c - as.numeric(b[1]) c [1] 116.2812 -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] (no subject)
Hi Hao, I suggest you try again, starting by read posting guide at footnote of this email. How about a title for the message? How about identify yourself? bests milton On Tue, Dec 29, 2009 at 2:59 PM, Hao Cen h...@andrew.cmu.edu wrote: Hi, I wonder how to pass several functions and their arguments as arguments to a function. For example, the main function is f = function(X ) { process(X) ... process(X) } I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2), g3(X, par3). par1, par2 and par3 are parameters and of different types. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://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] pass functions and arguments to function
Hi Hao, Ok. Sorry for my last post. bests milton On Tue, Dec 29, 2009 at 3:08 PM, Hao Cen h...@andrew.cmu.edu wrote: Hi, I wonder how to pass several functions and their arguments as arguments to a function. For example, the main function is f = function(X ) { process1(X) ... process2(X) } I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2), g3(X, par3). par1, par2 and par3 are parameters and of different types. I would like to pass g1, g2, g3 and their arguments to f and g1, g2, g3 may appear to be in different orders. So that final effect of the passing is f = function(X ) { process1(X) g1(X, par1) g2(X, par2) g3(X, par3) process2(X) } If I pass g2(X, par2),g3(X, par3), g1(X, par1) to f, I would expect to get the effect of f = function(X ) { process1(X) g2(X, par2) g3(X, par3) g1(X, par1) process2(X) } Appreciate any suggestions. thanks Jeff ps please ignore my previous blank subject email. It was accidentally sent before the letter was completed. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://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] svm regression/classification
Hi steve, Thank you so much for your reply.Im asking about the difference between two cases:1) when I use svm in a regression system and 2) when I use svm in a classification system. Is the code of using svm in these two cases the same?This is the code for a regression system: my_svm_model - function(myformula, mydata, mytestdata) { mymodel - svm(myformula, data=mydata) mytest - predict(mymodel, mytestdata) error - mytest - mytestdata[,1] -sqrt(mean(error**2)) }Many thanks, Nancy Date: Tue, 29 Dec 2009 10:36:36 -0500 Subject: Re: [R] svm regression/classification From: mailinglist.honey...@gmail.com To: nancyada...@hotmail.com CC: r-help@r-project.org Hi Nancy, Comments in line: On Sun, Dec 27, 2009 at 3:34 AM, Nancy Adam nancyada...@hotmail.com wrote: Hi everyone, Can anyone please tell whether there is a difference between the code for using svm in regression and code for using svm in classification? This is my code for regression, should I change it to do classification?: I'm not sure how to answer your question ... are you asking how you can explicitly tell the `svm` function to do classification vs. regression? Or are you asking if classification is better suited for your problem than regression? Are you trying to predict a label or some range of real valued numbers? Can you show us your `y` vector? -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact _ Keep your friends updatedeven when youre not signed in. [[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] R2
Hi everyone, Thanks a lot for the explanation⦠I tried the following code to compute R2 for a regression system but it does not work: my_svm_model - function(myformula, mydata, mytestdata) { mymodel - svm(myformula, data=mydata) k- summary(mymodel) k$r.squared } Can anyone please tell me what I have to change to compute R2? Many thanks, Nancy Date: Tue, 29 Dec 2009 17:28:59 + From: rip...@stats.ox.ac.uk To: spec...@stat.berkeley.edu CC: nancyada...@hotmail.com; r-help@r-project.org Subject: Re: [R] R2 On Tue, 29 Dec 2009, Phil Spector wrote: Nancy - Please notice that ** is not an R operator. The caret (^) is the exponentiation operator in R. - Phil Actually, no, 2**3 [1] 8 Indeed ^ is the preferred exponentiation operator, but ** has 'always' been allowed. See the following note in ?^ Note: ʽ**ʼ is translated in the parser to ʽ^ʼ, but this was undocumented for many years. It appears as an index entry in Becker _et al_ (1988), pointing to the help for ʽDeprecatedʼ but is not actually mentioned on that page. Even though it has been deprecated in S for 20 years, it is still accepted. I added that note in May 2008 (and it is not intended to be a reference to current versions of S-PLUS, since we cannot keep checking that, but that Svr4 accepted it). On Tue, 29 Dec 2009, Nancy Adam wrote: Hi everyone, I tried to write the code of computing R2 for a regression system but I failed. This is the code I use for computing RMSE: my_svm_model - function(myformula, mydata, mytestdata) { mymodel - svm(myformula, data=mydata) mytest - predict(mymodel, mytestdata) error - mytest - mytestdata[,1] -sqrt(mean(error**2)) } can anyone please tell me what I have to change to compute R2 instead of RMSE? Many thanks, Nancy _ [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 _ Keep your friends updatedâeven when youâre not signed in. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010 [[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] Factor and Level Issue
Dear useR's I have a small basic problem which I am hoping to get some help with. I have a data frame, testSeq_df, with 1 row and 500 columns. Each column is a character (a,c,g or t). I want this sequence to have 4 factors (a,c,g,t). When I try the following: for(i in 1:500){ if (length(levels(testSeq_df[,i]))==1) levels(testSeq_df[,i]) - c(a=a,g=g,c=c,t=t)} it replaces all the values in the sequence with a only. So all columns become a. How do I fix this so that the columns retain their original values but still have 4 levels ie. a,c,g,t. Thanks a lot for your help, Vishal On Sat, Dec 26, 2009 at 10:39 AM, Vishal Thapar vishaltha...@gmail.comwrote: Hi David, Thank you so much for the pointer. I get it now. I did try the str(testSeq_df) and since it gave me more than 2 factors for each column, I believed that it was fine. I get the point clearly now. Thanks again for all your help. I really appreciate it. Sincerely, vishal On Sat, Dec 26, 2009 at 8:26 AM, David Winsemius dwinsem...@comcast.netwrote: On Dec 26, 2009, at 3:53 AM, Vishal Thapar wrote: Hi All, Thank you for your replies so far. I was hoping I could get some more input from you on this issue. It seems to me that I have hit a dead end here and would really appreciate some feedback. I have followed all the suggestions you have mentioned but they still this is stuck. Earlier I thought that it was a factor issue but now even that is not the error. Here is the script and the error. Thanks for your help. I have attached the sample test file as well as the training file in case you would like to run it locally. - library(seqinr) library(kernlab) str(mars500_1_df) 'data.frame': 256 obs. of 501 variables: All of which are factors with 4 levels testSeq_fa=read.fasta(temp1.fasta) testSeq_seq=t(getSequence(testSeq_fa)) testSeq_df=as.data.frame(testSeq_seq,stringsAsFactors=FALSE) testSeq_df = cbind(Class=-,testSeq_df) testSeq_df = data.frame(lapply(testSeq_df,factor)) str(testSeq_df) 'data.frame': 20 obs. of 501 variables: $ V9 : Factor w/ 3 levels a,c,t: 2 1 2 1 3 2 3 2 3 1 ... $ V9 : Factor w/ 3 levels a,c,t: 2 1 2 1 3 2 3 2 3 1 ... $ V26 : Factor w/ 3 levels a,g,t: 2 1 1 1 1 3 1 3 1 3 ... ...and about 10 more... So I think you were closer but not quite there yet. for(i in 11:501){if (length(levels(testSeq_df[,i])) == 3) levels(testSeq_df[,i])- c(a=a,g=g,c=c,c=t)} predict(mars500_1,testSeq_df) [1] - - - - + - + - - - - + + + - - - - - + Levels: - + YES, it WAS (and still is) a factor issue. You were shown how to look at objects with str. Why have you not adopted the practice? -- David Winsemius, MD Heritage Laboratories West Hartford, CT -- Vishal Thapar, Ph.D. Post Doctoral Researcher Cold Spring Harbor Lab Williams Bldg 1 Bungtown Road Cold Spring Harbor, NY - 11724 -- Vishal Thapar, Ph.D. Post Doctoral Researcher Cold Spring Harbor Lab Williams Bldg 1 Bungtown Road Cold Spring Harbor, NY - 11724 [[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] Factor and Level Issue
Please ignore my message. I figured it out myself. The way to do it is: levels(testSeq_df[,i]) - list(a=c('a'),c=c('c'),g=('g'),t=c('t')) Thanks, vishal [[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] rJava on Linux
Hi, I seem to have to some problem using the rJava package. Any help is appreciated. I have a sample java file Hello.java public class Hello { public String sayHello() { String result=new String(Hell); return result; } public static void main(String[] args) { } } and these are the commands I use on R: install.packages(rJava) library('rJava') .jinit() h-(java/lang/String,Hello) .jcall(h,S,sayHello) Error in .jcall(h1, S, sayHello) : method sayHello with signature ()Ljava/lang/String; not found Could someone point me in the right direction please? Thanks. PurpleSnow __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] svm regression/classification
Hi Nancy, 2009/12/30 Nancy Adam nancyada...@hotmail.com: Hi steve, Thank you so much for your reply. I’m asking about the difference between two cases: 1) when I use svm in a regression system and 2) when I use svm in a classification system. Is the code of using svm in these two cases the same? Getting the `svm` function to perform classification vs. regression can be controlled by setting its `type` parameter. The help page for the function ?svm suggests that this is automatically picked depending on what type of element your y vector is, eg. it defaults to classification if your `y` is a vector of factors. That having been said, you can set this parameter explicitly so that you're sure of what the function is doing, eg: ## classification: mymodel - svm(myformula, data=mydata, type='C-classification') ## regression mymodel - svm(myformula, data=mydata, type='eps-regression') This is the code for a regression system: my_svm_model - function(myformula, mydata, mytestdata) { mymodel - svm(myformula, data=mydata) mytest - predict(mymodel, mytestdata) error - mytest - mytestdata[,1] -sqrt(mean(error**2)) } That's not really code for a regression system -- as I said above, performing regression vs. classification depends on what type of vector your `y` labels turns out to be, given your formula (unless you explicitly set type='something'). It looks like your `my_svm_model` is a function that calculates (the negative of) the root-mean-squared-error (why negative, btw?). This performance calculation is appropriate for regression, but not for classification. For classification you probably want to report the accuracy of the labels, eg something like: mytest - predict(mymodel, mytestdata, type='C-classification') accuracy - sum(mytest == mytestdata[,1]) / length(mytest) As I said in my earlier email, it's not really appropriate to try, say, regression and report accuracy like as its defined for classification. I'm not sure if I'm answering your question, partly because I'm not really sure what you're really asking, ie. I'm not sure if you're confused as to whether or not you should be doing classification or regression, or do you know which of the two you want to do but you don't understand how to get `svm` to perform the one you want? Please clarify the above point if you still need more help. Hope that helps, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] as.numeric is truncating!
thank you. and for those who didn't get the reference: http://en.wikipedia.org/wiki/Ren%C3%A9_Magritte http://en.wikipedia.org/wiki/Ren%C3%A9_Magritte Peter Dalgaard wrote: ticspd wrote: I am trying to convert a string to a double using as.numeric However, R is truncating the results! No it isn't! As someone phrased it recently, there's a difference between an object and the display of an object. Ceci n'est pas une pipe. Options(digits) is set to 7. So numbers are _printed_ to 7-digit accuracy, yes. (And 116.28125 has 8 digits.) Can anyone shed some light on this? Subtract 116, and enlightenment should follow. Thanks! b[1] [1] 116.28125 summary(b[1]) Length Class Mode 1 character character c - as.numeric(b[1]) c [1] 116.2812 -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/as-numeric-is-truncating-tp990546p990749.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.