Re: [R] number of decimal
Hi, Actually, I have two steps, the first would be to import a csv file (read.csv). There I would need to have the same number of decimals as there are on the original file. Then I would run some analyses and probably export the results, e.g. ANOVA table (write.csv). Here too I would like to have a sufficiently large number of decimals (usually 6). I think it shouldn't be too problematic to export correctly, I could set up the number of decimals using format(), since the object is stored internally (though I will have to figure out for each test how to get to the test and p-values). I usually don't use these values again, I just need to print them. From what I've tested, it even seems that the full precision is also exported! And it looks like the importing save internally all decimals from the input file. So actually, it looks like it was just about the display. I didn't expect that the printing and internal handling of numbers would be different. I thought that the tests would be computed using the printed values. But if it uses the full precision, then everything is fine. All that because of the printing! It's probably a newbie misunderstanding :-) Thanks a lot for all your help! Ivan Le 1/28/2010 17:36, Peter Ehlers a écrit : Ivan, Now I'm no longer sure of just what you want. Are you concerned about the *internal* handling of numbers by R or just about the *printing* of numbers? As Marc has pointed out, internally R will use the full precision that your input allows. Perhaps you're using the F-value from the output of a procedure like aov() as input to further analysis. If so, don't use the printed value; pull the value out of the object with something like fm - aov(y ~ x) Fval - summary(fm)[[1]][1,4] But maybe this is not at all what you're after. -Peter Ehlers Ivan Calandra wrote: First things first: thanks for your help! I see where the confusion is. With formatC and sprintf, I have to store the numbers I want to change into x. I would like a way without applying a function on specific numbers because I can shorten the numbers that way, but it won't give me more decimals for a test for example. What I mean here is that if I have a F-value = 1.225, formatC won't give me the next 3 decimals, it will just add zeros. I need that because for some of my variables, the sample differ only at the 6th decimal (0.05 vs 0.06), and for other ones the order of magnitude is much higher (120.120225 vs 210.665331). So options(digits=6) cannot do the job as I would like. To make myself even clearer, notice that in my example, all numbers have 6 decimals, but a different number of digits. I hope I'm not bothering you with this question, but I believe that the functions you advised me will not do what I need. I really need something that will set up the number of decimals by default, before the numbers are created by any function. Does such an option even exist in R? Or is it that it doesn't make sense to have different numbers of digits? Would it be better to compare 0.05 and 210.665? Therefore options(digits=6) would be enough. Regards, Ivan Le 1/28/2010 16:43, Peter Ehlers a écrit : Ivan Calandra wrote: It looks to me that it does more or less the same as format(). Maybe I didn't explain myself correctly then. I would like to set the number of decimal by default, for the whole R session, like I do with options(digits=6). Except that digits sets up the number of digits (including what is before the .). I'm looking for some option that will let me set the number of digits AFTER the . Example: I have 102.33556677 and 2.999555666 If I set the number of decimal to 6, I should get: 102.335567 and 2.999556. And that for all numbers that will be in/output from R (read.table, write.table, statistic tests, etc) Or is it that I didn't understand everything about formatC() and sprintf()? You didn't: formatC(x, digits=6, format=f) [1] 102.335567 2.999556 sprintf(%12.6f, x) [1] 102.335567 2.999556 -Peter Ehlers Thanks again Ivan Le 1/28/2010 15:12, Peter Ehlers a écrit : ?formatC ?sprintf Ivan Calandra wrote: Hi everybody, I'm trying to set the number of decimals (i.e. the number of digits after the .). I looked into options but I can only set the total number of digits, with options(digits=6). But since I have different variables with different order of magnitude, I would like that they're all displayed with the same number of decimals. I searched for it and found the format() function, with nsmall=6, but it is for a given vector. I would like to set it for the whole session, as with options. Can anyone help me? Thanks in advance Ivan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Conditional plot(Lattice)
Hi All, I am completely new to R. I have the below data and want to create a conditional variable say Prof.H as such that it equals 1 if Prof is 50 and 0 otherwise and create a scatter plot of Value and Dim conditional on the new variable. Area Value Dim Prof 1 1 145.1 9.5 39.0 2 2 128.3 10.1 50.5 3 3 121.3 9.4 55.6 4 4 134.4 11.6 45.0 5 5 106.5 10.3 49.6 6 6 111.5 9.5 44.3 7 7 132.7 11.2 47.4 8 8 126.9 9.0 60.0 Any help is appreciated. Brima -- View this message in context: http://n4.nabble.com/Conditional-plot-Lattice-tp1412674p1412674.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] How to convert timestamps?
Is this what you want: x [1] 1225221868 1225221906 1225221906 1225230997 1225231000 1225231003 1225231152 1225231348 1225231351 [10] 1225231400 as.POSIXct(x,origin='1970-1-1',tz='GMT') [1] 2008-10-28 19:24:28 GMT 2008-10-28 19:25:06 GMT 2008-10-28 19:25:06 GMT [4] 2008-10-28 21:56:37 GMT 2008-10-28 21:56:40 GMT 2008-10-28 21:56:43 GMT [7] 2008-10-28 21:59:12 GMT 2008-10-28 22:02:28 GMT 2008-10-28 22:02:31 GMT [10] 2008-10-28 22:03:20 GMT On Fri, Jan 29, 2010 at 2:24 AM, johannes rara johannesr...@gmail.com wrote: I have timestamps from mysql database: dput(tstamp) c(1225221868L, 1225221906L, 1225221906L, 1225230997L, 1225231000L, 1225231003L, 1225231152L, 1225231348L, 1225231351L, 1225231400L ) How to convert these into normal dates? Thanks, jrara __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] detect brightness of hex color value in R / convert from hex to hsl/hsv space how?
To the R color experts: I need to detect if a chosen background color (as hex e.g. #910322) is light or dark. If it is dark I need to ovelay it with light text and vice versa. Thus I would like to implement the following pseudo code: if (brightness(color) somevalue) textcolor= dark else textcolor=red I am not too familiar with color systems. My idea was to convert the hex value to hsv / hsl space and extract the v or l value. 1) I am not sure if this is the way to go. 2) I do not succeed in it. convertColor {grDevices} or make.rgb {grDevices} did not help me with that. How can I convert hex to hsv/ hsl space How would you detect the (perceived) color brightness? Thanks Mark Mark Heckmann Dipl. Wirt.-Ing. cand. Psych. Vorstraße 93 B01 28359 Bremen Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Classification of supernovae - a challenge
Hi all, I thought I'd just point out, to those not having yet seen this, that today there was a classification challenge posted for astronomy. The web-site is http://www.hep.anl.gov/SNchallenge/ [I have nothing to do with this project so don't ask me any details!] Basically the idea behind is that future surveys of the sky will turn up a large number of supernovae (SNe). The surveys' main goal is to try to understand the mysterious dark energy which seems to make up ~70% of the energy density of the Universe. The number of these SNe that will be detected is expected to be moderately large (~10^5). In the past astronomers have studied these using spectroscopic data which allow you to accurately classify supernovae but that will not be possible in the future. Instead one will have to rely on measurements of flux in broad bands to classify supernovae. This challenge then is to try to classify SNe using photometry only and they have provided training test data on the web sites above. The characteristic features are typically encoded in the shape of the flux curve as a function of time but other aspects might be useful too. There is a description on the web site for more information. Anyway, just thought some of you might find this a fun challenge for you or your students - the deadline is May 1. Cheers, Jarle. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] detect brightness of hex color value in R / convert from hex to hsl/hsv space how?
On Fri, 29 Jan 2010, Mark Heckmann wrote: To the R color experts: I need to detect if a chosen background color (as hex e.g. #910322) is light or dark. If it is dark I need to ovelay it with light text and vice versa. You can use the colorspace package for that. hex2RGB() converts a hex string to RGB coordinates which in turn can be easily converted to systems like HSV or (preferably) HCL (called polarLUV in colorspace). R as(hex2RGB(#910322), polarLUV) LCH [1,] 31.61831 95.14145 6.913428 L corresponds to the luminance (whether a color is light or dark), C is chroma (how colorful the color is compared to a gray with the same luminance), and H is the hue. hth, Z Thus I would like to implement the following pseudo code: if (brightness(color) somevalue) textcolor= dark else textcolor=red I am not too familiar with color systems. My idea was to convert the hex value to hsv / hsl space and extract the v or l value. 1) I am not sure if this is the way to go. 2) I do not succeed in it. convertColor {grDevices} or make.rgb {grDevices} did not help me with that. How can I convert hex to hsv/ hsl space How would you detect the (perceived) color brightness? Thanks Mark ??? Mark Heckmann Dipl. Wirt.-Ing. cand. Psych. Vorstra?e 93 B01 28359 Bremen Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Compilation error with maptools
I had downloaded and installed a number of packages, successfully, when I ran into some problem with maptools: It would eat up CPU and most of all memory. I rebooted, and tried again, only running the terminal after the reboot; with the same result: sp2WB text html latex example sp2tmap text html latex example spCbind-methods text html latex example Out of memory! ERROR: building help failed for package ‘maptools’ * Removing ‘/usr/local/lib/R/site-library/maptools’ The downloaded packages are in ‘/tmp/RtmpG9Vj1D/downloaded_packages’ Warning message: In install.packages(maptools) : installation of package 'maptools' had non-zero exit status I did install it then, using sudo apt-get install r-cran-maptools without problem; it also works. (I am on Ubuntu Karmic; sp and Hmisc, however, install without any problem.) My RAM is 4GB, my swap likewise. Uwe Uwe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] cbind, row names
Hello, I read the help as well as the examples, but I can not figure out why the following code does not produce the *given* row names, x and y: x - 1:20 y - 21:40 rbind( x=cbind(N=length(x), M=mean(x), SD=sd(x)), y=cbind(N=length(y), M=mean(y), SD=sd(y)) ) Could you please help? Thank you Sören __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Explanation w.r.t. rbind, please!
This is what I tried: num.vec - c(12.34,56.78,90.12,34.56) names(num.vec)-c(first,second,third,fourth) num.vec first second third fourth 12.34 56.78 90.12 34.56 seq-(1:4) num.mat-rbind(num.vec,seq) num.mat first second third fourth num.vec 12.34 56.78 90.12 34.56 seq 1.00 2.00 3.00 4.00 num.vec [3:4] third fourth 90.12 34.56 (until here I'm fine) num.mat [seq] [1] 12.34 1.00 56.78 2.00 num.mat [num.vec] [1] NA NA NA NA num.vec [seq] first second third fourth 12.34 56.78 90.12 34.56 num.mat [num.vec] [1] NA NA NA NA num.mat [-seq] [1] 90.12 3.00 34.56 4.00 (and here I'm lost!) How could I display a row, instead of always seemingly falling back to columns? Uwe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RMySQL, Sweave and the annoying TRUE echo
Hi, A small (but annoying) problem with RMySQL library. When a connection is closed, it echoes 'TRUE' to the console. Like this: R mysqlCloseConnection(con) [1] TRUE The real problem comes when I use RMySQL with Sweave, since the TRUE echo gets into my final Sweave document. Even when I explicitly state include=FALSE, echo=FALSE= in the header of the R code chunk. Is there a way to suppress this TRUE echo? TIA / s __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RMySQL, Sweave and the annoying TRUE echo
Try this: invisible(mysqlCloseConnection(con)) On Fri, Jan 29, 2010 at 9:10 AM, Stefan Petersson stefan.peters...@inizio.se wrote: Hi, A small (but annoying) problem with RMySQL library. When a connection is closed, it echoes 'TRUE' to the console. Like this: R mysqlCloseConnection(con) [1] TRUE The real problem comes when I use RMySQL with Sweave, since the TRUE echo gets into my final Sweave document. Even when I explicitly state include=FALSE, echo=FALSE= in the header of the R code chunk. Is there a way to suppress this TRUE echo? TIA / s __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] cbind, row names
This gives what you want: rbind.data.frame( x=cbind(N=length(x), M=mean(x), SD=sd(x)), y=cbind(N=length(y), M=mean(y), SD=sd(y)) ) On Fri, Jan 29, 2010 at 8:49 AM, soeren.vo...@eawag.ch wrote: Hello, I read the help as well as the examples, but I can not figure out why the following code does not produce the *given* row names, x and y: x - 1:20 y - 21:40 rbind( x=cbind(N=length(x), M=mean(x), SD=sd(x)), y=cbind(N=length(y), M=mean(y), SD=sd(y)) ) Could you please help? Thank you Sören __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] cbind, row names
Hi! 29.01.2010 12:49, soeren.vo...@eawag.ch wrote: Hello, I read the help as well as the examples, but I can not figure out why the following code does not produce the *given* row names, x and y: x - 1:20 y - 21:40 rbind( x=cbind(N=length(x), M=mean(x), SD=sd(x)), y=cbind(N=length(y), M=mean(y), SD=sd(y)) ) Maybe because the cbinds in your code produce matrices: is.matrix(cbind(N=length(x), M=mean(x), SD=sd(x))) [1] TRUE Quote ?rbind: For cbind (rbind) the column (row) names are taken from the colnames (rownames) of the arguments if these are matrix-like. HTH, Kimmo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Conditional plot(Lattice)
Tru this: xyplot(Value ~ Dim | ifelse(Prof 50, 1, 0), data = x) On Fri, Jan 29, 2010 at 5:25 AM, Brima adamsteve2...@yahoo.com wrote: Hi All, I am completely new to R. I have the below data and want to create a conditional variable say Prof.H as such that it equals 1 if Prof is 50 and 0 otherwise and create a scatter plot of Value and Dim conditional on the new variable. Area Value Dim Prof 1 1 145.1 9.5 39.0 2 2 128.3 10.1 50.5 3 3 121.3 9.4 55.6 4 4 134.4 11.6 45.0 5 5 106.5 10.3 49.6 6 6 111.5 9.5 44.3 7 7 132.7 11.2 47.4 8 8 126.9 9.0 60.0 Any help is appreciated. Brima -- View this message in context: http://n4.nabble.com/Conditional-plot-Lattice-tp1413264p1413264.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. -- 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] Explanation w.r.t. rbind, please!
On Fri, 2010-01-29 at 18:56 +0800, Uwe Dippel wrote: This is what I tried: num.vec - c(12.34,56.78,90.12,34.56) names(num.vec)-c(first,second,third,fourth) num.vec first second third fourth 12.34 56.78 90.12 34.56 seq-(1:4) num.mat-rbind(num.vec,seq) num.mat first second third fourth num.vec 12.34 56.78 90.12 34.56 seq 1.00 2.00 3.00 4.00 num.vec [3:4] third fourth 90.12 34.56 (until here I'm fine) num.mat [seq] [1] 12.34 1.00 56.78 2.00 num.mat [num.vec] [1] NA NA NA NA num.vec [seq] first second third fourth 12.34 56.78 90.12 34.56 num.mat [num.vec] [1] NA NA NA NA num.mat [-seq] [1] 90.12 3.00 34.56 4.00 (and here I'm lost!) How could I display a row, instead of always seemingly falling back to columns? You're indexing the matrix as if it were a vector. Which is fine, except that in R matrices are indexed by columns, hence the last result your got - you dropped the first 4 entries which are the first two columns, hence you got the last two columns of data. Knowing this you could alter your seq to be seq(1, 8, by = 2): num.mat[seq(1, 8, by = 2)] [1] 12.34 56.78 90.12 34.56 Thank full there is an easier way: ?`[` has the details, look at arguments i and j. num.mat[1,] first second third fourth 12.34 56.78 90.12 34.56 or, without the (col)names unname(num.mat[1,]) [1] 12.34 56.78 90.12 34.56 HTH G Uwe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FracSim set.seed
Hi, I am using the FracSim library to simulate a time series. However, the simulate function ignores my attempt to set the RNG seed I need for reproducible research. The published docs and google have not yielded an answer, so any help greatly received. Thanks, Selwyn ## Example code snippet library(FracSim) ## simulate some 1d fractal data set.seed(1234) sim1 = fracsim.1d(h=0.5,k=1000,n=5000) ## reset the seed set.seed(1234) sim2 = fracsim.1d(h=0.5,k=1000,n=5000) table(sim1$process == sim2$process) ## not identical... [[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] RMySQL, Sweave and the annoying TRUE echo
Stefan Petersson wrote: Hi, A small (but annoying) problem with RMySQL library. When a connection is closed, it echoes 'TRUE' to the console. Like this: R mysqlCloseConnection(con) [1] TRUE The real problem comes when I use RMySQL with Sweave, since the TRUE echo gets into my final Sweave document. Even when I explicitly state include=FALSE, echo=FALSE= in the header of the R code chunk. include=FALSE stops graphs from being included. echo=FALSE stops the R input from being echoed. You want results=hide to stop the results from being shown. So to make that call completely invisible, use echo=FALSE, results=hide= mysqlCloseConnection(con) @ Duncan Murdoch Is there a way to suppress this TRUE echo? TIA / s __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] [SOLVED] RMySQL, Sweave and the annoying TRUE echo
S: Works! Thanx... 2010-01-29 Henrique Dallazuanna wrote: Try this: invisible(mysqlCloseConnection(con)) On Fri, Jan 29, 2010 at 9:10 AM, Stefan Petersson stefan.peters...@inizio.se wrote: Hi, A small (but annoying) problem with RMySQL library. When a connection is closed, it echoes 'TRUE' to the console. Like this: R mysqlCloseConnection(con) [1] TRUE The real problem comes when I use RMySQL with Sweave, since the TRUE echo gets into my final Sweave document. Even when I explicitly state include=FALSE, echo=FALSE= in the header of the R code chunk. Is there a way to suppress this TRUE echo? TIA / s __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Explanation w.r.t. rbind, please!
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Uwe Dippel Sent: Freitag, 29. Januar 2010 11:57 To: r-help@r-project.org Subject: [R] Explanation w.r.t. rbind, please! This is what I tried: num.vec - c(12.34,56.78,90.12,34.56) names(num.vec)-c(first,second,third,fourth) num.vec first second third fourth 12.34 56.78 90.12 34.56 seq-(1:4) num.mat-rbind(num.vec,seq) num.mat first second third fourth num.vec 12.34 56.78 90.12 34.56 seq 1.00 2.00 3.00 4.00 num.vec [3:4] third fourth 90.12 34.56 (until here I'm fine) num.mat [seq] [1] 12.34 1.00 56.78 2.00 What you (probably) want here is num.mat [seq,] num.mat [num.vec] [1] NA NA NA NA num.mat[num.vec,] and so on. You have to use tell R that you want the ROW (that's why the comma is needed) defined by the NAME seq or num.vec (that's why you need ) . Otherwise, R replaces seq by its value 1:4, so num.mat[seq] is identical to num.mat[1:4] (and num.mat[12.34] is NA of course in num.mat[num.vec]) You should have a closer look at ?Extract HTH, Michael num.vec [seq] first second third fourth 12.34 56.78 90.12 34.56 num.mat [num.vec] [1] NA NA NA NA num.mat [-seq] [1] 90.12 3.00 34.56 4.00 (and here I'm lost!) How could I display a row, instead of always seemingly falling back to columns? Uwe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Vectorize multiple loops
Hi, How can we vectorize multiple for loops? E.g. how do you vectorize this: for (i in 1:10){ for(j in 1:25){ for(k in 1:19){ x[i,j,k]=i*k-j } } } THanks KC __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotmath: suprscript on scalable delimiter?
ComRades, How do you put a superscript on a scalable delimiter? I want to put 'b' as the power of the expression in the following plot: t - 1:25 K - 0.2 y - ((1-exp(-K*t))/(1-exp(-K*t)*exp(K)))^3 plot(t,y,l,main=K=0.2, b=3) text(15,5,expression(bgroup((,frac(1-e^-Kt,1-e^-Kt*e^K), Plotmath examples in demo(plotmath) do not include this. I've tried a few things to no avail and I did an RSiteSearch(superscript delimiter) with zero results. Thx Rubén Dr. Rubén Roa-Ureta AZTI - Tecnalia / Marine Research Unit Txatxarramendi Ugartea z/g 48395 Sukarrieta (Bizkaia) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] use zoo package with multiple column data sets
Readers, I am trying to use the zoo package with an array of data: file1: hh:mm:ss1 hh:mm:ss2 hh:mm:ss3 hh:mm:ss4 file2: hh:mm:ss11 55 hh:mm:ss22 66 hh:mm:ss33 77 hh:mm:ss44 88 I wanted to merge these data set so I tried the following commands: library(chron) library(zoo) z1-read.zoo(path/to/file1.csv,header=TRUE,sep=,,FUN=times) z2-read.zoo(path/to/file2.csv,header=TRUE,sep=,,FUN=times) z3-(na.approx(merge(z1,z2),time(z1))) plot(z3$z1,z3$z2[3]) Warning message: some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique in: zoo(rval, ix) z3-(na.approx(merge(z1,z2),time(z1))) Error in merge.zoo(z1, z2) : series cannot be merged with non-unique index entries in a series I have read the document vignette 'zoo' but section 2.1 does not show an example of the syntax for the command 'order.by'. How to use the zoo package where the variable z2 contains many columns of data? Yours, rhelpatconference.jabber.org r251 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Vectorize multiple loops
Try this: aperm(outer(i %o% k, j, FUN = -), c(1, 3, 2)) On Fri, Jan 29, 2010 at 9:58 AM, Kohleth Chia kohl...@gmail.com wrote: Hi, How can we vectorize multiple for loops? E.g. how do you vectorize this: for (i in 1:10){ for(j in 1:25){ for(k in 1:19){ x[i,j,k]=i*k-j } } } THanks KC __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.
[R] Step function
Hi All, Does the step function work in this model? I tried to run the following model but no result obtained. The computer is hanging and I killed the job several times. Below is the code. library(survival) m.fit=clogit(y~x1+x2+x3+x4, data=ftest) summary(m.fit) final- step(m.fit) Thanks in advance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotmath: suprscript on scalable delimiter?
On 29.01.2010 13:03, Rubén Roa wrote: ComRades, How do you put a superscript on a scalable delimiter? I want to put 'b' as the power of the expression in the following plot: t- 1:25 K- 0.2 y- ((1-exp(-K*t))/(1-exp(-K*t)*exp(K)))^3 plot(t,y,l,main=K=0.2, b=3) text(15,5,expression(bgroup((,frac(1-e^-Kt,1-e^-Kt*e^K), text(15,5,expression(bgroup((,frac(1-e^-Kt,1-e^-Kt*e^K),))^3)) Uwe Ligges Plotmath examples in demo(plotmath) do not include this. I've tried a few things to no avail and I did an RSiteSearch(superscript delimiter) with zero results. Thx Rubén Dr. Rubén Roa-Ureta AZTI - Tecnalia / Marine Research Unit Txatxarramendi Ugartea z/g 48395 Sukarrieta (Bizkaia) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] use zoo package with multiple column data sets
See FAQ #1 of the zoo faq: vignette(zoo-faq) On Fri, Jan 29, 2010 at 7:12 AM, e-letter inp...@gmail.com wrote: Readers, I am trying to use the zoo package with an array of data: file1: hh:mm:ss 1 hh:mm:ss 2 hh:mm:ss 3 hh:mm:ss 4 file2: hh:mm:ss 11 55 hh:mm:ss 22 66 hh:mm:ss 33 77 hh:mm:ss 44 88 I wanted to merge these data set so I tried the following commands: library(chron) library(zoo) z1-read.zoo(path/to/file1.csv,header=TRUE,sep=,,FUN=times) z2-read.zoo(path/to/file2.csv,header=TRUE,sep=,,FUN=times) z3-(na.approx(merge(z1,z2),time(z1))) plot(z3$z1,z3$z2[3]) Warning message: some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique in: zoo(rval, ix) z3-(na.approx(merge(z1,z2),time(z1))) Error in merge.zoo(z1, z2) : series cannot be merged with non-unique index entries in a series I have read the document vignette 'zoo' but section 2.1 does not show an example of the syntax for the command 'order.by'. How to use the zoo package where the variable z2 contains many columns of data? Yours, rhelpatconference.jabber.org r251 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] AFT-model with time-varying covariates and left-truncation
On Thu, Jan 28, 2010 at 2:32 PM, Philipp Rappold philipp.rapp...@gmail.com wrote: Dear Prof. Broström, Dear R-mailinglist, first of all thanks a lot for your great effort to incorporate time-varying covariates into aftreg. It works like a charm so far and I'll update you with detailled benchmarks as soon as I have them. I have one more questions regarding Accelerated Failure Time models (with aftreg): You mention that left truncation in combination with time-varying covariates only works if ...it can be assumed that the covariate values during the first non-observable interval are the same as at the beginning of the first interval under observation.. My question is: Is there a way to use an AFT model where one has no explicit assumption about what values the covariates have before the subject enters the study (see example below if unclear)? For me personally it would already be a great help to know if this is statistically feasible in general, however I'm also interested if it can me modelled with aftreg. The AFT model with time-fixed acceleration factor a is S(t; a) = S_0(at) for some S_0. With a time-varying a = a(t), this becomes S(t; a) = S_0(\int_0^t a(s) ds), and in order to evaluate that you need the full history of a at each t 0. EXAMPLE (to make sure we're talking about the same thing): Suppose I want to model the lifetime of two wearparts A and B with temperature as a covariate. For some reason, I can only observe the temperature at three distinct times t1, t2, t3 where they each have a certain age (5 hours, 6 hours, 7 hours respectively). Of course, I have a different temperature for each part at each observation t1, t2, t3. Unfortunately at t1 both parts have not been used for the first time and already have a certain age (5 hours) and I cannot observe what the temperature was before (at ages 1hr, 2hr, ...). The important thing here is whether you have left-truncated _lifetimes_ or not. Your example is about missing observation(s) on a covariate, which is a different problem. But a problem. And not only for the AFT model, but for the PH model as well. Göran Thanks a lot for your help! All the best Philipp __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Göran Broström __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Lyapunov Discrete Time Equation
Dear all, I need to solve the following Lyapunov Matrix equation: C=ACA' + B, with A and B given square symmetric matrices. Does anyone knows of a package that can solve the lyapunov matrix equation in R? Or even a C/Fortran implementation? I did not find one on netlib. Thank you. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] liblapack
Dear all, I am trying to put together in a package some functions that maybe of interest to other. A particular function of the package uses zgges from Lapack with a .Fortran call. Since R does not load all symbols from liblapack, I load all the liblapack symbols (lazyload, it is) with a .First.lib hook in the zzz.R file: .First.lib - function(lib, pkg) dyn.load(/usr/lib/liblapack.dylib, now = FALSE). This is ok for my system (OSX 10.6), but it won't work on Linux and Windows. Of course, it won't work if the location of liblapack is different from /usr/lib. Is there a way load liblapack conditionally on the specific system and the location of the library? Thank you in advance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] use zoo package with multiple column data sets
Assuming my documentation is correct, my version shows faq 1 to refer to duplicate times but if file2 is: 01:01:0111 55 01:01:0422 66 01:01:0733 77 01:01:1044 88 I cannot see what is duplicate? If I create two new files: file3: 01:01:0111 01:01:0422 01:01:0733 01:01:1044 file4: 01:01:0155 01:01:0466 01:01:0777 01:01:1088 The previous commands work: z1-read.zoo(path/to/file1.csv,header=TRUE,sep=,,FUN=times) z2-read.zoo(path/to/file3.csv,header=TRUE,sep=,,FUN=times) z3-(na.approx(merge(z1,z2),time(z1))) plot(z3$z1,z3$z2) and: z1-read.zoo(path/to/file1.csv,header=TRUE,sep=,,FUN=times) z2-read.zoo(path/to/file4.csv,header=TRUE,sep=,,FUN=times) z3-(na.approx(merge(z1,z2),time(z1))) plot(z3$z1,z3$z2) Shouldn't I be able to have one file containing all the columns I want to make graphs, instead of having to create numerous files of only two columns of data? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Hard drive memory
prem_R mtechprem at gmail.com writes: I heard form my friend there is a way to run R in system hard disk space not in the RAM .By that we may not run out of memory and have problem attached with the same.Someone could help me in this.Thanks. Your question is posed extremely vaguely. It's conceivable that you will find something useful in the Large memory and out-of-memory data section in the High Performance Computing task view: http://cran.r-project.org/web/views/HighPerformanceComputing.html If that doesn't help you will have to be much more explicit about what you are trying to do (how big is your data set, what version of R, operating system, hardware, etc., what operations are you trying to run ...) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 function with grouped columns
Try this: y - c(v1, v2, v3, v4) rowf - gl(2, 1, 16) colf - gl(2, 8, 16, labels=1:0) dat - data.frame(y) aggregate(dat[1], list(Row=rowf, Col=colf), mean) -Peter Ehlers Jack Siegrist wrote: I have a data set of many rows and many columns in which both the rows and the columns have associated grouping factors. Is there a way to do what 'aggregate' does but in the other dimension? The way I have been doing this is to use 'aggregate' on the data in the usual way and then rotate the result and apply 'aggregate' again. This works but is a little messy and I was wondering if there is some built-in way to do this easier. An example of what I have been doing is below. #Four observations of four variables v1 - c(1, 8, 5, 3) v2 - c(5, 5, 6, 5) v3 - c(3, 2, 9, 4) v4 - c(4, 1, 1, 1) myData - data.frame(v1=v1, v2=v2, v3=v3, v4=v4) myData #The observations have either property 1 or property 2 rowFactor - data.frame(RowTraits=factor(c(1, 2, 1, 2))) rowFactor #The variables have a property that is either present or absent colFactor - data.frame(ColTraits=factor(c(1, 1, 0, 0))) colFactor #Getting the means for the columns by row groups is easy MeanByRowTraits - aggregate (myData, rowFactor[1], mean) MeanByRowTraits #But now to get the means for the rows by column groups is awkward rotateData - data.frame(t(MeanByRowTraits[2:5])) colnames(rotateData) - c(levels(rowFactor[,1])) rotateData #This is the kind of result I want in the end aggregate (rotateData, colFactor[1], mean) -- Peter Ehlers University of Calgary __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 R-squared and P-value from lm results
Hi, R Users I find a problem in extracting the R-squared and P-value from the lm results described below (in Italic), *Residual standard error: 2.25 on 17 degrees of freedom* *Multiple R-squared: 0.001069, Adjusted R-squared: -0.05769 * *F-statistic: 0.01819 on 1 and 17 DF, p-value: 0.8943 * * * Any suggestions will be appreciated. Thanks. Wenjun [[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] detect brightness of hex color value in R / convert from hex to hsl/hsv space how?
Perhaps some variation of SetTextContrastColor - function(color) { ifelse( mean(col2rgb(color)) 127, black, white) } Mark Heckmann wrote: To the R color experts: I need to detect if a chosen background color (as hex e.g. #910322) is light or dark. If it is dark I need to ovelay it with light text and vice versa. Thus I would like to implement the following pseudo code: if (brightness(color) somevalue) textcolor= dark else textcolor=red I am not too familiar with color systems. My idea was to convert the hex value to hsv / hsl space and extract the v or l value. 1) I am not sure if this is the way to go. 2) I do not succeed in it. convertColor {grDevices} or make.rgb {grDevices} did not help me with that. How can I convert hex to hsv/ hsl space How would you detect the (perceived) color brightness? Thanks Mark ––– Mark Heckmann Dipl. Wirt.-Ing. cand. Psych. Vorstraße 93 B01 28359 Bremen Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com [[alternative HTML version deleted]] -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 R-squared and P-value from lm results
On 1/29/2010 9:04 AM, wenjun zheng wrote: Hi, R Users I find a problem in extracting the R-squared and P-value from the lm results described below (in Italic), *Residual standard error: 2.25 on 17 degrees of freedom* *Multiple R-squared: 0.001069, Adjusted R-squared: -0.05769 * *F-statistic: 0.01819 on 1 and 17 DF, p-value: 0.8943 * * * Any suggestions will be appreciated. Thanks. ?summary.lm In particular, see the 'Value' section which describes the components of the list returned when an lm() object is summarized. Notice the r.squared and coefficients components of the returned list. Wenjun [[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. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Error on using lag function
Peter, I decided to directly remove the NA's but when I tested it yes I wrote fromLast = TRUE so I might have checked erroneously sorry and thanks again I am going to keep this in mind because I might need it at some point, I have many cases where I need to handle missing values differently. - Anna Lippel -- View this message in context: http://n4.nabble.com/Error-on-using-lag-function-tp1399935p1415489.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] extract R-squared and P-value from lm results
x - 1:10 y - 2 + 1.5 * rnorm(10, x, 2) m - lm(y ~ x) summary(m)$r.squared [1] 0.6056889 anova(m)$'Pr(F)' [1] 0.0080142NA Components of the summary() and anova() methods of lm() can be extracted. See names(summary(m)) names(anova(m)) to see the components one can extract. HTH, Dennis On Fri, Jan 29, 2010 at 6:04 AM, wenjun zheng wjzhen...@gmail.com wrote: Hi, R Users I find a problem in extracting the R-squared and P-value from the lm results described below (in Italic), *Residual standard error: 2.25 on 17 degrees of freedom* *Multiple R-squared: 0.001069, Adjusted R-squared: -0.05769 * *F-statistic: 0.01819 on 1 and 17 DF, p-value: 0.8943 * * * Any suggestions will be appreciated. Thanks. Wenjun [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems with fitdistr
vikrant wrote: Yes I do have zeros in my data. But I m not able to understand y inclusion of zeros results in error messages, because range for x in weibull distribution is x=0. Can you please clarify this doubt? Well, that's a matter of definition (and is a problem if the shape parameter is = 1). fitdistr() seems to take the range to be x 0. As I said, when no start values are provided, fitdistr() will have a 'problem' with zeros because the first thing it does is log(x), easy to see in the code. But try pelwei() in package lmom, as suggested by Jonathan Hosking. -Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 R-squared and P-value from lm results
Thanks, I get it. Wenjun, ZHENG 2010/1/29 Dennis Murphy djmu...@gmail.com x - 1:10 y - 2 + 1.5 * rnorm(10, x, 2) m - lm(y ~ x) summary(m)$r.squared [1] 0.6056889 anova(m)$'Pr(F)' [1] 0.0080142NA Components of the summary() and anova() methods of lm() can be extracted. See names(summary(m)) names(anova(m)) to see the components one can extract. HTH, Dennis On Fri, Jan 29, 2010 at 6:04 AM, wenjun zheng wjzhen...@gmail.com wrote: Hi, R Users I find a problem in extracting the R-squared and P-value from the lm results described below (in Italic), *Residual standard error: 2.25 on 17 degrees of freedom* *Multiple R-squared: 0.001069, Adjusted R-squared: -0.05769 * *F-statistic: 0.01819 on 1 and 17 DF, p-value: 0.8943 * * * Any suggestions will be appreciated. Thanks. Wenjun [[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. -- Wenjun [[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] Odp: extract R-squared and P-value from lm results
Hi r-help-boun...@r-project.org napsal dne 29.01.2010 15:04:39: Hi, R Users I find a problem in extracting the R-squared and P-value from the lm results described below (in Italic), *Residual standard error: 2.25 on 17 degrees of freedom* *Multiple R-squared: 0.001069, Adjusted R-squared: -0.05769 * *F-statistic: 0.01819 on 1 and 17 DF, p-value: 0.8943 * * * Any suggestions will be appreciated. Thanks. What about filling such question in CRAN search facility. When I put your subject line into it I got many relevant hits. If you want to see how summary(fit) is structured than use str(summary(fit)) If I remember it correctly summary(fit)$r.sqared but you can easily find it yourself. Regards Petr Wenjun [[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] Create matrix with subset from unlist
Hello all, I'm trying to create a 2x2 matrix, 32 times after unlist() so that I can convert the list to matrix. I've looked through the R archive but couldn't find the answer. There is what I've done. f - system(ls *.txt, intern=TRUE) x - lapply(f, read.table) x [[1]] V1V2 1 -27.3 14.4 2 29.0 -38.1 [[2]] V1 V2 1 14.4 29.0 2 -38.1 -3.4 [[3]] V1V2 1 29.0 -38.1 2 -3.4 55.1 [[4]] V1 V2 1 -38.1 -3.4 2 55.1 -1.0 [[5]] V1 V2 1 -3.4 55.1 2 -1.0 21.9 [[6]] V1V2 1 55.1 -1.0 2 21.9 -10.9 ... xx - unlist(x) V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -27.3 29.0 14.4 -38.1 14.4 -38.1 29.0 -3.4 29.0 -3.4 -38.1 55.1 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -38.1 55.1 -3.4 -1.0 -3.4 -1.0 55.1 21.9 55.1 21.9 -1.0 -10.9 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -1.0 -10.9 21.9 -7.8 21.9 -7.8 -10.9 -48.2 -10.9 -48.2 -7.8 -44.9 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -7.8 -44.9 -48.2 -43.8 -48.2 -43.8 -44.9 -10.3 -44.9 -10.3 -43.8 44.2 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -43.8 44.2 -10.3 -0.5 -10.3 -0.5 44.2 96.7 44.2 96.7 -0.5 -32.0 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -0.5 -32.0 96.7 -0.2 96.7 -0.2 -32.0 -38.6 -32.0 -38.6 -0.2 73.6 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -0.2 73.6 -38.6 -17.5 -38.6 -17.5 73.6 -57.8 73.6 -57.8 -17.5 10.7 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -17.5 10.7 -57.8 -33.4 -57.8 -33.4 10.7 46.1 10.7 46.1 -33.4 26.7 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -33.4 26.7 46.1 -37.3 46.1 -37.3 26.7 1.2 26.7 1.2 -37.3 36.3 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -37.3 36.3 1.2 39.6 1.2 39.6 36.3 31.0 36.3 -27.3 39.6 14.4 V11 V12 V21 V22 V11 V12 V21 V22 39.6 29.0 31.0 -38.1 31.0 -3.4 -27.3 55.1 The output should be [[1]] [,1] [,2] [1,]-27.314.4 [2,] 29.0-38.1 [[2]] [,1] [,2] [1,] 14.429.0 [2,] -38.1-3.4 [[3]] [,1] [,2] [1,]29.0-38.1 [2,]-3.4 55.1 ... Thanks and much appreciated! Muhammad __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] color palette for points, lines, text / interactive Rcolorpicker?
If you use tcltk package package, you can do: as.character(.Tcl(tk_chooseColor)) Best, Philippe Greg Snow wrote: I don't know of any existing palettes that meet your conditions, but here are a couple of options for interactive exploration of colorsets (this is quick and dirty, there are probably some better orderings, base colors, etc.): colpicker - function( cols=colors() ) { n - length(cols) nr - ceiling(sqrt(n)) nc - ceiling( n/nr ) imat - matrix(c(seq_along(cols), rep(NA, nr*nc-n) ), ncol=nc, nrow=nr) image( seq.int(nr),seq.int(nc), imat, col=cols, xlab='', ylab='' ) xy - locator() cols[ imat[ cbind( round(xy$x), round(xy$y) ) ] ] } colpicker() ## another approach library(TeachingDemos) cols - colors() n - length(cols) par(xpd=TRUE) # next line only works on windows HWidentify( (1:n) %% 26, (1:n) %/% 26, label=cols, col=cols, pch=15, cex=2 ) # next line works on all platforms with tcltk HTKidentify( (1:n) %% 26, (1:n) %/% 26, label=cols, col=cols, pch=15, cex=2 ) # reorder cols.rgb - col2rgb( cols ) d - dist(t(cols.rgb)) clst - hclust(d) colpicker(cols[clst$order]) HWidentify( (1:n) %% 26, (1:n) %/% 26, label=cols[clst$order], col=cols[clst$order], pch=15, cex=2 ) ## or HTKidentify cols.hsv - rgb2hsv( cols.rgb ) d2 - dist(t(cols.hsv)) clst2 - hclust(d2) HWidentify( (1:n) %% 26, (1:n) %/% 26, label=cols[clst2$order], col=cols[clst2$order], pch=15, cex=2 ) ## or HTKidentify Hope this helps, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Explanation w.r.t. rbind, please!
Meyners,Michael,LAUSANNE,AppliedMathematics wrote: What you (probably) want here is num.mat [seq,] num.mat [num.vec] [1] NA NA NA NA num.mat[num.vec,] and so on. You have to use tell R that you want the ROW (that's why the comma is needed) defined by the NAME seq or num.vec (that's why you need ) . Thanks, I had been exactly there before, and it didn't work neither. Now it works. I do understand the need for the rows *now*. Uwe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 with multy level sorting
Hi all I have a dataframe like I coppied below ff a b d 110 5 7 220 4 9 3 3 8 10 4 5 68 5 6 35 67373 74528 9 83 2 8 while I am trying to sort multy coloums at once I am not able to get that like ina order of first column a next column d after that column b here I tried with o - order(a,d,b) but it returns an error can any one help me to sort this multy-columns atonce thanks in advance kiran [[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] For loop into a vectorized form?
How to vectorize this for loop and how can I assign result to vector instead of using print function? mylist - list(a = letters[1:3], b = LETTERS[1:3], c = c(1, 2, 3)) for (i in seq_along(mylist[[1]])) { for (j in seq_along(mylist[[2]])) { print(mylist[[1]][i]) print(mylist[[2]][j]) print(mylist[[3]]) } } Run version: mylist - list(a = letters[1:3], b = LETTERS[1:3], c = c(1, 2, 3)) mylist $a [1] a b c $b [1] A B C $c [1] 1 2 3 for (i in seq_along(mylist[[1]])) { + for (j in seq_along(mylist[[2]])) { + print(mylist[[1]][i]) + print(mylist[[2]][j]) + print(mylist[[3]]) + } + } [1] a [1] A [1] 1 2 3 [1] a [1] B [1] 1 2 3 [1] a [1] C [1] 1 2 3 [1] b [1] A [1] 1 2 3 [1] b [1] B [1] 1 2 3 [1] b [1] C [1] 1 2 3 [1] c [1] A [1] 1 2 3 [1] c [1] B [1] 1 2 3 [1] c [1] C [1] 1 2 3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Error on using lag function
anna wrote: Hello everyone, I have a vector P and I want to replace each of its missing values by its next element, for example: P[i] = NA -- P[i] = P[i+1] You can also try P[which(is.na(P))]- P[which(is.na(P))+1] or avoiding duplicate calculations index.Pna-which(is.na(P)) P[index.Pna] - P[index.Pna+1] You are left with having to decide what to do if the last element of P is NA. Berend -- View this message in context: http://n4.nabble.com/Error-on-using-lag-function-tp1399935p1415529.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] use zoo package with multiple column data sets
Please provide a reproducible examples. You can use the following style: Lines - 01:01:0111 55 + 01:01:0422 66 + 01:01:0733 77 + 01:01:1044 88 library(zoo) library(chron) z - read.zoo(textConnection(Lines), FUN = times) z V2 V3 01:01:01 11 55 01:01:04 22 66 01:01:07 33 77 01:01:10 44 88 On Fri, Jan 29, 2010 at 8:34 AM, e-letter inp...@gmail.com wrote: Assuming my documentation is correct, my version shows faq 1 to refer to duplicate times but if file2 is: 01:01:01 11 55 01:01:04 22 66 01:01:07 33 77 01:01:10 44 88 I cannot see what is duplicate? If I create two new files: file3: 01:01:01 11 01:01:04 22 01:01:07 33 01:01:10 44 file4: 01:01:01 55 01:01:04 66 01:01:07 77 01:01:10 88 The previous commands work: z1-read.zoo(path/to/file1.csv,header=TRUE,sep=,,FUN=times) z2-read.zoo(path/to/file3.csv,header=TRUE,sep=,,FUN=times) z3-(na.approx(merge(z1,z2),time(z1))) plot(z3$z1,z3$z2) and: z1-read.zoo(path/to/file1.csv,header=TRUE,sep=,,FUN=times) z2-read.zoo(path/to/file4.csv,header=TRUE,sep=,,FUN=times) z3-(na.approx(merge(z1,z2),time(z1))) plot(z3$z1,z3$z2) Shouldn't I be able to have one file containing all the columns I want to make graphs, instead of having to create numerous files of only two columns of data? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Create matrix with subset from unlist
Hi: The problem, I'm guessing, is that you need to assign each of the matrices to an object. There's undoubtedly a slick apply family solution for this (which I want to see, BTW!), but here's the brute force method using a loop: nms - paste('x', 1:32, sep = ) for(i in seq_along(nms)) assign(nms[i], x[[i]]) HTH, Dennis On Fri, Jan 29, 2010 at 6:30 AM, Muhammad Rahiz muhammad.ra...@ouce.ox.ac.uk wrote: Hello all, I'm trying to create a 2x2 matrix, 32 times after unlist() so that I can convert the list to matrix. I've looked through the R archive but couldn't find the answer. There is what I've done. f - system(ls *.txt, intern=TRUE) x - lapply(f, read.table) x [[1]] V1V2 1 -27.3 14.4 2 29.0 -38.1 [[2]] V1 V2 1 14.4 29.0 2 -38.1 -3.4 [[3]] V1V2 1 29.0 -38.1 2 -3.4 55.1 [[4]] V1 V2 1 -38.1 -3.4 2 55.1 -1.0 [[5]] V1 V2 1 -3.4 55.1 2 -1.0 21.9 [[6]] V1V2 1 55.1 -1.0 2 21.9 -10.9 ... xx - unlist(x) V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -27.3 29.0 14.4 -38.1 14.4 -38.1 29.0 -3.4 29.0 -3.4 -38.1 55.1 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -38.1 55.1 -3.4 -1.0 -3.4 -1.0 55.1 21.9 55.1 21.9 -1.0 -10.9 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -1.0 -10.9 21.9 -7.8 21.9 -7.8 -10.9 -48.2 -10.9 -48.2 -7.8 -44.9 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -7.8 -44.9 -48.2 -43.8 -48.2 -43.8 -44.9 -10.3 -44.9 -10.3 -43.8 44.2 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -43.8 44.2 -10.3 -0.5 -10.3 -0.5 44.2 96.7 44.2 96.7 -0.5 -32.0 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -0.5 -32.0 96.7 -0.2 96.7 -0.2 -32.0 -38.6 -32.0 -38.6 -0.2 73.6 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -0.2 73.6 -38.6 -17.5 -38.6 -17.5 73.6 -57.8 73.6 -57.8 -17.5 10.7 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -17.5 10.7 -57.8 -33.4 -57.8 -33.4 10.7 46.1 10.7 46.1 -33.4 26.7 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -33.4 26.7 46.1 -37.3 46.1 -37.3 26.7 1.2 26.7 1.2 -37.3 36.3 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -37.3 36.3 1.2 39.6 1.2 39.6 36.3 31.0 36.3 -27.3 39.6 14.4 V11 V12 V21 V22 V11 V12 V21 V22 39.6 29.0 31.0 -38.1 31.0 -3.4 -27.3 55.1 The output should be [[1]] [,1] [,2] [1,]-27.314.4 [2,] 29.0-38.1 [[2]] [,1] [,2] [1,] 14.429.0 [2,] -38.1-3.4 [[3]] [,1] [,2] [1,]29.0-38.1 [2,]-3.4 55.1 ... Thanks and much appreciated! Muhammad __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with multy level sorting
On Jan 29, 2010, at 9:34 AM, venkata kirankumar wrote: Hi all I have a dataframe like I coppied below ff a b d 110 5 7 220 4 9 3 3 8 10 4 5 68 5 6 35 67373 74528 9 83 2 8 while I am trying to sort multy coloums at once I am not able to get that like ina order of first column a next column d after that column b here I tried with o - order(a,d,b) a, b and d are not objects. They are columns within ff. with( ff, order(a,b,d)) #[1] 8 3 4 5 1 2 7 6 but it returns an error can any one help me to sort this multy-columns atonce The ordering of that dataframe would be (almost) uniquely determined by ordering on the first column. Even the one duplicate (3) gets resolved with reference to the second column. ff[with(ff, order(a,b,d)), ] a b d 8 3 2 8 3 3 8 10 4 5 6 8 5 6 3 5 1 10 5 7 2 20 4 9 7 45 28 9 6 73 7 3 thanks in advance kiran [[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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Suppress output from getGEO
Dear R-ers, I am using getGEO to download expression data from the Gene Expression Omnibus. With default settings, when a file is downloaded and parsed, lots of dotted lines are printed in the terminal, like this: .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. downloaded 50.2 Mb but many more! I tried to suppress this rather unhelpful behavior with capture.output and sink, as below, but to no effect: capture.output(getGEO(GEO=GEO)) # GEO is some GEO id sink('/dev/null'); getGEO(GEO=GEO); sink() Is this an issue with getGEO, or some underlying function? How can I avoid having the terminal spammed? Could the function responsible for this annoying output be modified to put an end to this? Best regards, Craig __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Suppress output from getGEO
On 29/01/2010 10:04 AM, Craig P. Pyrame wrote: Dear R-ers, I am using getGEO to download expression data from the Gene Expression Omnibus. With default settings, when a file is downloaded and parsed, lots of dotted lines are printed in the terminal, like this: .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. downloaded 50.2 Mb but many more! I tried to suppress this rather unhelpful behavior with capture.output and sink, as below, but to no effect: capture.output(getGEO(GEO=GEO)) # GEO is some GEO id sink('/dev/null'); getGEO(GEO=GEO); sink() Is this an issue with getGEO, or some underlying function? How can I avoid having the terminal spammed? Could the function responsible for this annoying output be modified to put an end to this? getGEO is a Bioconductor package. Feel free to insult the helpful people there if you want to alienate them, but please don't crosspost here. 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.
Re: [R] Create matrix with subset from unlist
On Jan 29, 2010, at 9:45 AM, Dennis Murphy wrote: Hi: The problem, I'm guessing, is that you need to assign each of the matrices to an object. There's undoubtedly a slick apply family solution for this (which I want to see, BTW!), I don't have a method that would assign names but you could populate an array of sufficient size and dimension. I populated a three-element list with his data: dput(x) list(structure(list(V1 = c(-27.3, 29), V2 = c(14.4, -38.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(14.4, -38.1), V2 = c(29, -3.4)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(29, -3.4), V2 = c(-38.1, 55.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2))) xx - array( , dim=c(2,2,3)) xx[,,1:3] - sapply(x, data.matrix) xx , , 1 [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 , , 2 [,1] [,2] [1,] 14.4 29.0 [2,] -38.1 -3.4 , , 3 [,1] [,2] [1,] 29.0 -38.1 [2,] -3.4 55.1 Without the more complex structure ready to accept the 2x2 arrays I got this: sapply(x, data.matrix) [,1] [,2] [,3] [1,] -27.3 14.4 29.0 [2,] 29.0 -38.1 -3.4 [3,] 14.4 29.0 -38.1 [4,] -38.1 -3.4 55.1 -- David. but here's the brute force method using a loop: nms - paste('x', 1:32, sep = ) for(i in seq_along(nms)) assign(nms[i], x[[i]]) HTH, Dennis On Fri, Jan 29, 2010 at 6:30 AM, Muhammad Rahiz muhammad.ra...@ouce.ox.ac.uk wrote: Hello all, I'm trying to create a 2x2 matrix, 32 times after unlist() so that I can convert the list to matrix. I've looked through the R archive but couldn't find the answer. There is what I've done. f - system(ls *.txt, intern=TRUE) x - lapply(f, read.table) x [[1]] V1V2 1 -27.3 14.4 2 29.0 -38.1 [[2]] V1 V2 1 14.4 29.0 2 -38.1 -3.4 [[3]] V1V2 1 29.0 -38.1 2 -3.4 55.1 [[4]] V1 V2 1 -38.1 -3.4 2 55.1 -1.0 [[5]] V1 V2 1 -3.4 55.1 2 -1.0 21.9 [[6]] V1V2 1 55.1 -1.0 2 21.9 -10.9 ... xx - unlist(x) V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -27.3 29.0 14.4 -38.1 14.4 -38.1 29.0 -3.4 29.0 -3.4 -38.1 55.1 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -38.1 55.1 -3.4 -1.0 -3.4 -1.0 55.1 21.9 55.1 21.9 -1.0 -10.9 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -1.0 -10.9 21.9 -7.8 21.9 -7.8 -10.9 -48.2 -10.9 -48.2 -7.8 -44.9 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -7.8 -44.9 -48.2 -43.8 -48.2 -43.8 -44.9 -10.3 -44.9 -10.3 -43.8 44.2 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -43.8 44.2 -10.3 -0.5 -10.3 -0.5 44.2 96.7 44.2 96.7 -0.5 -32.0 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -0.5 -32.0 96.7 -0.2 96.7 -0.2 -32.0 -38.6 -32.0 -38.6 -0.2 73.6 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -0.2 73.6 -38.6 -17.5 -38.6 -17.5 73.6 -57.8 73.6 -57.8 -17.5 10.7 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -17.5 10.7 -57.8 -33.4 -57.8 -33.4 10.7 46.1 10.7 46.1 -33.4 26.7 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -33.4 26.7 46.1 -37.3 46.1 -37.3 26.7 1.2 26.7 1.2 -37.3 36.3 V11 V12 V21 V22 V11 V12 V21 V22 V11 V12 V21 V22 -37.3 36.3 1.2 39.6 1.2 39.6 36.3 31.0 36.3 -27.3 39.6 14.4 V11 V12 V21 V22 V11 V12 V21 V22 39.6 29.0 31.0 -38.1 31.0 -3.4 -27.3 55.1 The output should be [[1]] [,1] [,2] [1,]-27.314.4 [2,] 29.0-38.1 [[2]] [,1] [,2] [1,] 14.429.0 [2,] -38.1-3.4 [[3]] [,1] [,2] [1,]29.0-38.1 [2,]-3.4 55.1 ... Thanks and much appreciated! Muhammad __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 draw a border for multiple graphs in one page
Hi, I am struggling to create a 2 by 2 multiple graphs in one page. I used par(mfrow=c(2,2)) to divide the screen into 4. In each screen I draw a pie chart (They are all same). For example, my data is like this Concentration value A1 69 A2 8 G1 51 G2 1 G3 68 G4 1 M 17 A1, A2... is different levels of the variable called concentration. Folllowing are their values. I uesd the R code below: colors - c(orange,red,purple,pink,blue,yellow,green) lbls - round(value/sum(value)*100,1) lbls - paste(lbls,%,sep=) postscript(file=H:/test.eps, height = 8, width = 8,onefile = FALSE, paper = special) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) dev.off() My question is How do I remove the outside frame. It seems that Box() can only generate four sided boders. Or is there any way that I can draw the inner border without using box(). Another question is how can I align the text in the legend? You can see when I concatenate the concentration level and the percentage, it looks unclear. Is it possible that percentage can be right aligned? I am not sure if you can generate the same figure as mine using the above code, so I attached my graph in case you can't get it. Thank you very much. John [[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] How to draw a border for multiple graphs in one page
Hi, I am struggling to create a 2 by 2 multiple graphs in one page. I used par(mfrow=c(2,2)) to divide the screen into 4. In each screen I draw a pie chart (They are all same). For example, my data is like this Concentration value A1 69 A2 8 G1 51 G2 1 G3 68 G4 1 M 17 A1, A2... is different levels of the variable called concentration. Folllowing are their values. I uesd the R code below: colors - c(orange,red,purple,pink,blue,yellow,green) lbls - round(value/sum(value)*100,1) lbls - paste(lbls,%,sep=) postscript(file=H:/test.eps, height = 8, width = 8,onefile = FALSE, paper = special) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) dev.off() My question is How do I remove the outside frame. It seems that Box() can only generate four sided boders. Or is there any way that I can draw the inner border without using box(). Another question is how can I align the text in the legend? You can see when I concatenate the concentration level and the percentage, it looks unclear. Is it possible that percentage can be right aligned? I am not sure if you can generate the same figure as mine using the above code, so I attached my graph in case you can't get it. Thank you very much. John test.eps Description: PostScript document __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to draw a border for multiple graphs in one pager
Hi, I am struggling to create a 2 by 2 multiple graphs in one page. I used par(mfrow=c(2,2)) to divide the screen into 4. In each screen I draw a pie chart (They are all same). For example, my data is like this Concentration value A1 69 A2 8 G1 51 G2 1 G3 68 G4 1 M 17 A1, A2... is different levels of the variable called concentration. Folllowing are their values. I uesd the R code below: colors - c(orange,red,purple,pink,blue,yellow,green) lbls - round(value/sum(value)*100,1) lbls - paste(lbls,%,sep=) postscript(file=H:/piechart.eps, height = 8, width = 8,onefile = FALSE, paper = special) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) par(mfrow=c(2,2),mar=c(0,0,0,0)) pie(value,labels=lbls,col=colors,radius=0.5) box(bty=o,col = 'black') leg - paste(concentration,lbls,sep=, ) legend(-1,0.85,leg,cex=0.8,fill=colors) dev.off() My question is How do I remove the outside frame. It seems that Box() can only generate four sided boders. Or is there any way that I can draw the inner border without using box(). Another question is how can I align the text in the legend? You can see when I concatenate the concentration level and the percentage, it looks unclear. Is it possible that percentage can be right aligned? I am not sure if you can generate the same figure as mine using the above code, so I attached my graph in case you can't get it. Thank you very much. John piechart.eps Description: PostScript document __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Suppress output from getGEO
Duncan Murdoch wrote: getGEO is a Bioconductor package. Feel free to insult the helpful people there if you want to alienate them, but please don't crosspost here. Duncan Murdoch Duncan, Do you consider this sort of output from a function helpful in any way? I don't, and I can't see how anyone could, this must be some sort of mistake, bug, whatever you call it. While it's possibly getGEO to create this output, it's also not unlikely that the output is actually generated by some underlying function that has nothing to do with Bioconductor. I can imagine a function that has this 'convenient' feature of printing dots while loading data, but the files loaded by getGEO are so large (for example, 50MB) that the 'convenience' is turned into annoyance. I included r-help precisely because I suspect it's not Bioconductor's fault in this case. Besides, I think you might want to make efforts to be less aggressive. I don't think my use of words in my previous message was inappropriate, but yours seems to be. I apologize if my post hurt your feelings, and now expect you do the same, Best regards, Craig __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Error on using lag function
thanks Berend, that's a very smart to do it :) - Anna Lippel -- View this message in context: http://n4.nabble.com/Error-on-using-lag-function-tp1399935p1415584.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] [Fwd: Re: Suppress output from getGEO]
Original Message Subject:Re: [R] Suppress output from getGEO Date: Fri, 29 Jan 2010 10:29:54 -0500 From: Duncan Murdoch murd...@stats.uwo.ca To: Craig P. Pyrame crap...@gmail.com References: 4b62f906.90...@gmail.com 4b62fb32.4040...@stats.uwo.ca 4b62fe12.7040...@gmail.com [...] Besides, I think you might want to make efforts to be less aggressive. I don't think my use of words in my previous message was inappropriate, but yours seems to be. I apologize if my post hurt your feelings, and now expect you do the same, You want aggressive? Go fuck yourself. 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.
Re: [R] color palette for points, lines, text / interactive Rcolorpicker?
Below is a 'pretty-poor' version of a color picker I wrote using the code on the color chart page I cited. It's slightly 'pretty' in terms of layout, but 'poor' in terms of usability and flexibility. Still, it is more useful to me than the nearly-null set of alternatives I have found in R. Maybe someone else can do better. [Some lines below have been broken by my mail client.] # Using code from http://research.stowers-institute.org/efg/R/Color/Chart/ colorpicker - function(n, order=c(index, hue), cols=colors(), value=c(name, index)) { ## n: max number of colors to pick (default: as many are selected in identify) ## order: how to order the colors in cols ## cols: vector of colors ## value: return color names or indices in cols? SetTextContrastColor - function(color) { ifelse( mean(col2rgb(color)) 127, black, white) } # Define this array of text contrast colors that corresponds to each # member of the colors() array. TextContrastColor - unlist( lapply(cols, SetTextContrastColor) ) ncolors - length(cols) if (missing(n)) n - ncolors # store coordinates of centers x - vector(integer, length=0) y - vector(integer, length=0) ind - vector(integer, length=0) nr - ceiling(sqrt(ncolors)) nc - ceiling( ncolors/nr ) order - match.arg(order) value - match.arg(value) if (order==index) { # 1a. Plot matrix of R colors, in index order, nc per row. # This example plots each row of rectangles one at a time. plot( c(1,nc), c(0,nr), type=n, ylab=, xlab=, axes=FALSE, ylim=c(nr,0)) title(R colors (index order): LT click to select; RT click to end) for (j in 0:(nr-1)) { base - j*nc remaining - length(cols) - base RowSize - ifelse(remaining nc, remaining, nc) x - c(x, 1:RowSize) y - c(y, rep(j, RowSize)) ind - c(ind, base + (1:RowSize)) rect((1:RowSize)-0.5,j-0.5, (1:RowSize)+0.5,j+0.5, border=black, col=cols[base + (1:RowSize)]) text((1:RowSize), j, paste(base + (1:RowSize)), cex=0.7, col=TextContrastColor[base + (1:RowSize)]) } } else ## if (order==hue) { # 1b. Plot matrix of R colors, in hue order, nc per row. # This example plots each rectangle one at a time. RGBColors - col2rgb(cols[1:length(cols)]) HSVColors - rgb2hsv( RGBColors[1,], RGBColors[2,], RGBColors[3,], maxColorValue=255) HueOrder - order( HSVColors[1,], HSVColors[2,], HSVColors[3,] ) plot(0, type=n, ylab=, xlab=, axes=FALSE, ylim=c(nr,0), xlim=c(1,nc)) title(R colors (HSV order): LT click to select; RT click to end) for (j in 0:(nr-1)) { for (i in 1:nc) { k - j*nc + i if (k = length(cols)) { x - c(x, i) y - c(y, j) ind - c(ind, HueOrder[k] ) rect(i-0.5,j-0.5, i+0.5,j+0.5, border=black, col=cols[ HueOrder[k] ]) text(i,j, paste(HueOrder[k]), cex=0.7, col=TextContrastColor[ HueOrder[k] ]) } } } } ## use identify to select n colors result - identify(x, y, ind, n=n, offset=-1, pos=FALSE) result - if (value==index) result else cols[result] result } Greg Snow wrote: I don't know of any existing palettes that meet your conditions, but here are a couple of options for interactive exploration of colorsets (this is quick and dirty, there are probably some better orderings, base colors, etc.): colpicker - function( cols=colors() ) { n - length(cols) nr - ceiling(sqrt(n)) nc - ceiling( n/nr ) imat - matrix(c(seq_along(cols), rep(NA, nr*nc-n) ), ncol=nc, nrow=nr) image( seq.int(nr),seq.int(nc), imat, col=cols, xlab='', ylab='' ) xy - locator() cols[ imat[ cbind( round(xy$x), round(xy$y) ) ] ] } colpicker() ## another approach library(TeachingDemos) cols - colors() n - length(cols) par(xpd=TRUE) # next line only works on windows HWidentify( (1:n) %% 26, (1:n) %/% 26, label=cols, col=cols, pch=15, cex=2 ) # next line works on all platforms with tcltk HTKidentify( (1:n) %% 26, (1:n) %/% 26, label=cols, col=cols, pch=15, cex=2 ) # reorder cols.rgb - col2rgb( cols ) d - dist(t(cols.rgb)) clst - hclust(d) colpicker(cols[clst$order]) HWidentify( (1:n) %% 26, (1:n) %/% 26, label=cols[clst$order], col=cols[clst$order], pch=15, cex=2 ) ## or HTKidentify cols.hsv - rgb2hsv( cols.rgb ) d2 - dist(t(cols.hsv)) clst2 - hclust(d2) HWidentify( (1:n) %% 26, (1:n) %/% 26, label=cols[clst2$order], col=cols[clst2$order], pch=15, cex=2 ) ## or HTKidentify Hope this helps, -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street
Re: [R] Lyapunov Discrete Time Equation
¿Did you do your homework before posting? ¿Did you read the posting guide? I do not know of anything in R, but searching the web gives a lot of info, there is a good article in wikipedia, and there are a lot of papers accessible. Code, which probably can be used with R, can be found on the following page (705): http://www.netlib.org/toms/ Kjetil B Halvorsen On Fri, Jan 29, 2010 at 9:47 AM, Giuseppe neo...@gmail.com wrote: Dear all, I need to solve the following Lyapunov Matrix equation: C=ACA' + B, with A and B given square symmetric matrices. Does anyone knows of a package that can solve the lyapunov matrix equation in R? Or even a C/Fortran implementation? I did not find one on netlib. Thank you. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] two sample chi-squared test
Hello, Can you tell me what R function to use to do a two-sample chi-squared test? I want to see if two distributions are significantly different from each other, and I don't specify the theoretical distribution of either. For example, I have the following fake count data: x - sample(1:10,50,replace=TRUE) y - sample(1:10,100,replace=TRUE) I saw chisq.test in the stats package, but that looks like a one-sample test. I'm running version 2.7.2 on windows xp. Thanks. eric __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] color palette for points, lines, text / interactive Rcolorpicker?
Hi Michael, have a look at colors.plot(T) from the epitools-package (and perhaps at colorbrewer.display() as well). Maybe this suits you? hth Michael Friendly schrieb: I'm looking for a scheme to generate a default color palette for plotting points, lines and text (on a white or transparent background) with from 2 to say 9 colors with the following constraints: - red is reserved for another purpose - colors should be highly distinct - avoid light colors (like yellows) In RColorBrewer, most of the schemes are designed for area fill rather than points and lines. The closest I can find for these needs is the Dark2 palette, e.g., library(RColorBrewer) display.brewer.pal(7,Dark2) I'm wondering if there is something else I can use. On a related note, I wonder if there is something like an interactive color picker for R. For example, http://research.stowers-institute.org/efg/R/Color/Chart/ displays several charts of all R colors. I'd like to find something that displays such a chart and uses identify() to select a set of tiles, whose colors() indices are returned by the function. -Michael __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Applying a function on each columns of a matrix
Hello everyone, I have the following matrix [,1] [,2] [,3] [,4] [1,] 0.002809706 0.0063856960 0.0063856960 0.011749681 [2,] 0.004893124 0.0023118418 -0.0005122951 -0.014646465 [3,] 0.003547897 0.0063355297 0.0030410542 0.011403953 [4,] 0.004838299 -0.0040383645 -0.0090406831 -0.011027569 [5,] 0.035648755 0.0334815590 0.0380977404 0.059817597 I want to apply a function on each column varying the first parameter of the function. If I do it on one column only with apply it works perfectly as follow: apply(column1, 1, myfunction, parameter1= ..., parameter2=...) But when I try to do it on each column without even varying the parameter it doesn't work: apply(matrix, 2, apply, MARGIN = 1, Fun = myfunction, parameter1 =..., parameter2=...) I get the following error: Error in FUN(newX[, i], ...) : unused argument(s) (2, function (X, MARGIN, FUN, ...) Does someone know how to solve this? and is there a way to send a vector of parameter1 instead of a scalar? thank you - Anna Lippel -- View this message in context: http://n4.nabble.com/Applying-a-function-on-each-columns-of-a-matrix-tp1415660p1415660.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] create an R object in a loop
Hi everybody, To run some statistical tests from the package WRS (from Rand R Wilcox), I need to store my data in a list, which fac2list() from this package does very well. But I would like to do it in a loop for each numerical variable. It would be easier! For now, I have the loop with the extraction and storage into a list. The code is below. - # Defines variables file - ssfamed #data file object to be used spec - cotau #species selection bone - tx #tooth row selection cat - 3#column indexe to be used as categorical variable seq.num - c(seq(7,21,1))#column indexes to be used as numerical variables # Select data for species and tooth row select - file[file$SPECSHOR==spec file$BONE==bone, ] #Separate the data from each numeric variable in seq.num (select[,k]) into groups from levels in select[cat] and store into list mode. for(i in 1:length(seq.num)) { k - seq.num[i] name.num - names(file)[k] TO_POS_Asfc.median_cotautx - fac2list(select[,k], select[cat]) names(TO_POS_Asfc.median_cotautx) - levels(factor(select[[cat]])) } - What I want to do is, instead of giving manually the name of the list (here TO_POS_Asfc.median_cotautx), I would like the name of the list to be created in the loop too, so that it looks like: select[[cat]]_name.num_specbone. In the code it would look like: - select[[cat]]_name.num_specbone - fac2list(select[,k], select[cat]) #create the list from the values of these variables at each iteration of the loop names(select[[cat]]_name.num_specbone) - levels(factor(select[[cat]])) - I thought about using paste(), but I cannot create an object like this. In my small R life, I've always stored data into pre-defined objects, I have no idea how to create an object automatically within a loop. Is my question clear? I hope so. I thought there might be a function that would create an object where the name would come from a string stored in an other object. Why do I want that? Simply because I want to run several statistical tests on each list and I would therefore like to have standardized names for the data objects. There might be easier ways to do what I want to, I'm open to all suggestions but I would prefer to stay close from my idea (I would understand better!) Thanks in advance for your help. Have a nice weekend Ivan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] two sample chi-squared test
On Jan 29, 2010, at 11:11 AM, eric lee wrote: Hello, Can you tell me what R function to use to do a two-sample chi-squared test? I want to see if two distributions are significantly different from each other, and I don't specify the theoretical distribution of either. For example, I have the following fake count data: x - sample(1:10,50,replace=TRUE) y - sample(1:10,100,replace=TRUE) I saw chisq.test in the stats package, but that looks like a one-sample test. Nope. You do need to supply it with the right organization of data, though. In your case that would be a 2 x 10 or a 10 x 2 matrix (so (2-1)x(10-1)=9 d.f) ?table ?matrix I'm running version 2.7.2 on windows xp. Probably has very little bearing on this problem, but that is considered to be badly outdated in 2010. Thanks. -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] detect brightness of hex color value in R / convert from hex to hsl/hsv space how?
There is a col2grey (and col2gray) function in the TeachingDemos package that use a common algorithm to convert colors to grey based on perceived lightness, that may work for you on deciding the color. For placing text on colored backgrounds, look at the shadowtext function (also in TeachingDemos) for another way. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Mark Heckmann Sent: Friday, January 29, 2010 3:09 AM To: r-help@r-project.org Subject: [R] detect brightness of hex color value in R / convert from hex to hsl/hsv space how? To the R color experts: I need to detect if a chosen background color (as hex e.g. #910322) is light or dark. If it is dark I need to ovelay it with light text and vice versa. Thus I would like to implement the following pseudo code: if (brightness(color) somevalue) textcolor= dark else textcolor=red I am not too familiar with color systems. My idea was to convert the hex value to hsv / hsl space and extract the v or l value. 1) I am not sure if this is the way to go. 2) I do not succeed in it. convertColor {grDevices} or make.rgb {grDevices} did not help me with that. How can I convert hex to hsv/ hsl space How would you detect the (perceived) color brightness? Thanks Mark --- Mark Heckmann Dipl. Wirt.-Ing. cand. Psych. Vorstraße 93 B01 28359 Bremen Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] evaluating expressions with sub expressions
Hallo I'm having trouble figuring out how to evaluate an expression when one of the variables in the expression is defined separately as a sub expression. Here's a simplified example mat - expression(0, f1*s1*g1) # vector of formulae g1 - expression(1/Tm) # expansion of the definition of g1 vals - data.frame(f1=1, s1=.5, Tm=2) # one set of possible values for variables before adding this sub expression I was using the following to evaluate mat sapply(mat, eval, vals) Obviously I could manually substitute in 1/Tm for each g1 in the definition of mat, but the actual expression vector is much longer, and the sub expression more complicated. Also, the subexpression is often adjusted for different scenarios. Is there a simple way of changing this or redefining mat so that I can define g1 like a macro to be used in the expression vector. Thanks! Jennifer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] evaluating expressions with sub expressions
Hi, Would this do as an alternative syntax? g1 - quote(1/Tm) mat - list(0, bquote(f1*s1*.(g1))) vals - data.frame(f1=1, s1=.5, Tm=2) sapply(mat, eval, vals) HTH, baptiste On 29 January 2010 17:51, Jennifer Young jennifer.yo...@math.mcmaster.ca wrote: Hallo I'm having trouble figuring out how to evaluate an expression when one of the variables in the expression is defined separately as a sub expression. Here's a simplified example mat - expression(0, f1*s1*g1) # vector of formulae g1 - expression(1/Tm) # expansion of the definition of g1 vals - data.frame(f1=1, s1=.5, Tm=2) # one set of possible values for variables before adding this sub expression I was using the following to evaluate mat sapply(mat, eval, vals) Obviously I could manually substitute in 1/Tm for each g1 in the definition of mat, but the actual expression vector is much longer, and the sub expression more complicated. Also, the subexpression is often adjusted for different scenarios. Is there a simple way of changing this or redefining mat so that I can define g1 like a macro to be used in the expression vector. Thanks! Jennifer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Applying a function on each columns of a matrix
Hello, You could do something along the following lines: sapply( 1:ncol( my.matrix ), function( i ) my.foo( my.matrix[,i], my.parm[i] ) Best regards, Carlos J. Gil Bellosta http://www.datanalytics.com anna wrote: Hello everyone, I have the following matrix [,1] [,2] [,3] [,4] [1,] 0.002809706 0.0063856960 0.0063856960 0.011749681 [2,] 0.004893124 0.0023118418 -0.0005122951 -0.014646465 [3,] 0.003547897 0.0063355297 0.0030410542 0.011403953 [4,] 0.004838299 -0.0040383645 -0.0090406831 -0.011027569 [5,] 0.035648755 0.0334815590 0.0380977404 0.059817597 I want to apply a function on each column varying the first parameter of the function. If I do it on one column only with apply it works perfectly as follow: apply(column1, 1, myfunction, parameter1= ..., parameter2=...) But when I try to do it on each column without even varying the parameter it doesn't work: apply(matrix, 2, apply, MARGIN = 1, Fun = myfunction, parameter1 =..., parameter2=...) I get the following error: Error in FUN(newX[, i], ...) : unused argument(s) (2, function (X, MARGIN, FUN, ...) Does someone know how to solve this? and is there a way to send a vector of parameter1 instead of a scalar? thank you - Anna Lippel __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] evaluating expressions with sub expressions
Hmm I *think* this will work, but may break in a further sub routine. It certainly works in this example, but my expression vector is used in many scenarios and it will take a while to check them all. For instance, I take the derivative of each element with respect to each variable using sapply(mat, deriv, names(vals)) This bit seems to still work, but I'd welcome a solution that doesn't change the structure of the expression vector to a list, just in case. Thanks for this solution. Hi, Would this do as an alternative syntax? g1 - quote(1/Tm) mat - list(0, bquote(f1*s1*.(g1))) vals - data.frame(f1=1, s1=.5, Tm=2) sapply(mat, eval, vals) HTH, baptiste On 29 January 2010 17:51, Jennifer Young jennifer.yo...@math.mcmaster.ca wrote: Hallo I'm having trouble figuring out how to evaluate an expression when one of the variables in the expression is defined separately as a sub expression. Here's a simplified example mat - expression(0, f1*s1*g1) # vector of formulae g1 - expression(1/Tm) # expansion of the definition of g1 vals - data.frame(f1=1, s1=.5, Tm=2) # one set of possible values for variables before adding this sub expression I was using the following to evaluate mat sapply(mat, eval, vals) Obviously I could manually substitute in 1/Tm for each g1 in the definition of mat, but the actual expression vector is much longer, and the sub expression more complicated. Also, the subexpression is often adjusted for different scenarios. Is there a simple way of changing this or redefining mat so that I can define g1 like a macro to be used in the expression vector. Thanks! Jennifer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 to express time series linear model Q(t) ~ Q(t-1)+.. Q(t-n) as a formula
Hello, You may problably need to create the lagged vars yourself and use them as input for the NN. Best regards, Carlos J. Gil Bellosta http://www.datanalytics.com http://datanalytics.wordpress.com CJ Rubio wrote: For example I have a time series Q(t) ~ Q(t-1) + Q(t-2) + Q(t-3) meaning that my current value is dependent to the 3 previous values. Can anybody help me express this in a formula that I can use for my neural network model (I am planning to use packages nnet and MASS) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Step function
On Fri, 29 Jan 2010, Ashta wrote: Hi All, Does the step function work in this model? I tried to run the following model but no result obtained. The computer is hanging and I killed the job several times. Below is the code. library(survival) m.fit=clogit(y~x1+x2+x3+x4, data=ftest) summary(m.fit) final- step(m.fit) You need to provide commented, minimal, self-contained, reproducible code such as: fit - clogit(I(state=='treated')~.,Puromycin) step(fit) which runs just fine. You have no strata() in your formula. Are you sure you want clogit?? If so, use an idiom like step(fit, scope=list(lower=~strata(stratvar)) ) HTH, Chuck Thanks in advance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Applying a function on each columns of a matrix
But then I would have to make a loop right? - Anna Lippel -- View this message in context: http://n4.nabble.com/Applying-a-function-on-each-columns-of-a-matrix-tp1415660p1415743.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] Create matrix with subset from unlist
Thanks David Dennis, I may have found something. Given that the object xx is the product of unlist(x), to create a 2x2 matrix with subsets, I could do, y - matrix(xx[c(1:4)], 2, 2). This returns, [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 If I do, y2 - matrix(xx[c(5:8)],2,2) it returns, [,1] [,2] [1,] 14.4 29.0 [2,] -38.1 -3.4 The results are exactly what I want to achieve. The question is, how can I incorporate the increment in a for loop so that it becomes c(1:4) c(5:8) c(9:12) and so on How should I modify this code? y - # typeof ? for (i in 1:32){ y[[i]] - matrix(xx[c(1:4)],2,2) } Muhammad David Winsemius wrote: On Jan 29, 2010, at 9:45 AM, Dennis Murphy wrote: Hi: The problem, I'm guessing, is that you need to assign each of the matrices to an object. There's undoubtedly a slick apply family solution for this (which I want to see, BTW!), I don't have a method that would assign names but you could populate an array of sufficient size and dimension. I populated a three-element list with his data: dput(x) list(structure(list(V1 = c(-27.3, 29), V2 = c(14.4, -38.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(14.4, -38.1), V2 = c(29, -3.4)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(29, -3.4), V2 = c(-38.1, 55.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2))) xx - array( , dim=c(2,2,3)) xx[,,1:3] - sapply(x, data.matrix) xx , , 1 [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 , , 2 [,1] [,2] [1,] 14.4 29.0 [2,] -38.1 -3.4 , , 3 [,1] [,2] [1,] 29.0 -38.1 [2,] -3.4 55.1 Without the more complex structure ready to accept the 2x2 arrays I got this: sapply(x, data.matrix) [,1] [,2] [,3] [1,] -27.3 14.4 29.0 [2,] 29.0 -38.1 -3.4 [3,] 14.4 29.0 -38.1 [4,] -38.1 -3.4 55.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.
Re: [R] Create matrix with subset from unlist
On Jan 29, 2010, at 12:43 PM, Muhammad Rahiz wrote: Thanks David Dennis, I may have found something. Given that the object xx is the product of unlist(x), to create a 2x2 matrix with subsets, I could do, y - matrix(xx[c(1:4)], 2, 2). This returns, [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 Much simpler to do: xx[ , , 1] [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 If I do, y2 - matrix(xx[c(5:8)],2,2) it returns, [,1] [,2] [1,] 14.4 29.0 [2,] -38.1 -3.4 The results are exactly what I want to achieve. The question is, how can I incorporate the increment in a for loop so that it becomes c(1:4) c(5:8) c(9:12) and so on How should I modify this code? y - # typeof ? for (i in 1:32){ y[[i]] - matrix(xx[c(1:4)],2,2) } I don't get it. You had the data in a list. You wanted it out of that list, and now you're going to put it back in another list??? ( y2 would not be the same as y[[2]] ) What's wrong with xx[ , , 2]? Muhammad David Winsemius wrote: On Jan 29, 2010, at 9:45 AM, Dennis Murphy wrote: Hi: The problem, I'm guessing, is that you need to assign each of the matrices to an object. There's undoubtedly a slick apply family solution for this (which I want to see, BTW!), I don't have a method that would assign names but you could populate an array of sufficient size and dimension. I populated a three-element list with his data: dput(x) list(structure(list(V1 = c(-27.3, 29), V2 = c(14.4, -38.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(14.4, -38.1), V2 = c(29, -3.4)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(29, -3.4), V2 = c(-38.1, 55.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2))) xx - array( , dim=c(2,2,3)) xx[,,1:3] - sapply(x, data.matrix) xx , , 1 [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 , , 2 [,1] [,2] [1,] 14.4 29.0 [2,] -38.1 -3.4 , , 3 [,1] [,2] [1,] 29.0 -38.1 [2,] -3.4 55.1 Without the more complex structure ready to accept the 2x2 arrays I got this: sapply(x, data.matrix) [,1] [,2] [,3] [1,] -27.3 14.4 29.0 [2,] 29.0 -38.1 -3.4 [3,] 14.4 29.0 -38.1 [4,] -38.1 -3.4 55.1 David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Create matrix with subset from unlist
OK, I've got this. The output prints what I want, but I'm not sure if there will be problems in further analysis because the main idea is to convert the data from list to matrix. I'm quite concerned with how I define xx2. xx - unlist(x) # Unlist from lapply + read.table a - seq(1,128,by=4) # creates sequence for increment in loop xx2 - list() # Is this the correct definition? for (z in 1:32){ xx2[[z]] - matrix(xx[c(a[z]:(a[z]+4))],2,2) } When I do, mode(xx2) [1] list When I do, xx3 - xx2[[1]] + 5 # simple test mode(xx3) numeric Am I doing this right? Muhammad -- Muhammad Rahiz wrote: Thanks David Dennis, I may have found something. Given that the object xx is the product of unlist(x), to create a 2x2 matrix with subsets, I could do, y - matrix(xx[c(1:4)], 2, 2). This returns, [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 If I do, y2 - matrix(xx[c(5:8)],2,2) it returns, [,1] [,2] [1,] 14.4 29.0 [2,] -38.1 -3.4 The results are exactly what I want to achieve. The question is, how can I incorporate the increment in a for loop so that it becomes c(1:4) c(5:8) c(9:12) and so on How should I modify this code? y - # typeof ? for (i in 1:32){ y[[i]] - matrix(xx[c(1:4)],2,2) } Muhammad David Winsemius wrote: On Jan 29, 2010, at 9:45 AM, Dennis Murphy wrote: Hi: The problem, I'm guessing, is that you need to assign each of the matrices to an object. There's undoubtedly a slick apply family solution for this (which I want to see, BTW!), I don't have a method that would assign names but you could populate an array of sufficient size and dimension. I populated a three-element list with his data: dput(x) list(structure(list(V1 = c(-27.3, 29), V2 = c(14.4, -38.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(14.4, -38.1), V2 = c(29, -3.4)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(29, -3.4), V2 = c(-38.1, 55.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2))) xx - array( , dim=c(2,2,3)) xx[,,1:3] - sapply(x, data.matrix) xx , , 1 [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 , , 2 [,1] [,2] [1,] 14.4 29.0 [2,] -38.1 -3.4 , , 3 [,1] [,2] [1,] 29.0 -38.1 [2,] -3.4 55.1 Without the more complex structure ready to accept the 2x2 arrays I got this: sapply(x, data.matrix) [,1] [,2] [,3] [1,] -27.3 14.4 29.0 [2,] 29.0 -38.1 -3.4 [3,] 14.4 29.0 -38.1 [4,] -38.1 -3.4 55.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] Create matrix with subset from unlist
On Jan 29, 2010, at 1:07 PM, Muhammad Rahiz wrote: OK, I've got this. The output prints what I want, but I'm not sure if there will be problems in further analysis because the main idea is to convert the data from list to matrix. I'm quite concerned with how I define xx2. xx - unlist(x) # Unlist from lapply + read.table a - seq(1,128,by=4) # creates sequence for increment in loop xx2 - list() # Is this the correct definition? It will work. for (z in 1:32){ xx2[[z]] - matrix(xx[c(a[z]:(a[z]+4))],2,2) # which would be a list of matrices } If you go back to your original posting, you could shortcut the whole process since you already had a list of 32 dataframes (lists) . That was the starting point. If a list is acceptable, then skip the intermediate array. class(x[[1]]) [1] data.frame class(lapply(x, data.matrix)[[1]]) [1] matrix So just do this: xx2 - lapply(x, data.matrix) # a list of matrices -- David. When I do, mode(xx2) [1] list When I do, xx3 - xx2[[1]] + 5 # simple test mode(xx3) numeric Am I doing this right? Muhammad -- Muhammad Rahiz wrote: Thanks David Dennis, I may have found something. Given that the object xx is the product of unlist(x), to create a 2x2 matrix with subsets, I could do, y - matrix(xx[c(1:4)], 2, 2). This returns, [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 If I do, y2 - matrix(xx[c(5:8)],2,2) it returns, [,1] [,2] [1,] 14.4 29.0 [2,] -38.1 -3.4 The results are exactly what I want to achieve. The question is, how can I incorporate the increment in a for loop so that it becomes c(1:4) c(5:8) c(9:12) and so on How should I modify this code? y - # typeof ? for (i in 1:32){ y[[i]] - matrix(xx[c(1:4)],2,2) } Muhammad David Winsemius wrote: On Jan 29, 2010, at 9:45 AM, Dennis Murphy wrote: Hi: The problem, I'm guessing, is that you need to assign each of the matrices to an object. There's undoubtedly a slick apply family solution for this (which I want to see, BTW!), I don't have a method that would assign names but you could populate an array of sufficient size and dimension. I populated a three-element list with his data: dput(x) list(structure(list(V1 = c(-27.3, 29), V2 = c(14.4, -38.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(14.4, -38.1), V2 = c(29, -3.4)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2)), structure(list( V1 = c(29, -3.4), V2 = c(-38.1, 55.1)), .Names = c(V1, V2), class = data.frame, row.names = c(1, 2))) xx - array( , dim=c(2,2,3)) xx[,,1:3] - sapply(x, data.matrix) xx , , 1 [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 , , 2 [,1] [,2] [1,] 14.4 29.0 [2,] -38.1 -3.4 , , 3 [,1] [,2] [1,] 29.0 -38.1 [2,] -3.4 55.1 Without the more complex structure ready to accept the 2x2 arrays I got this: sapply(x, data.matrix) [,1] [,2] [,3] [1,] -27.3 14.4 29.0 [2,] 29.0 -38.1 -3.4 [3,] 14.4 29.0 -38.1 [4,] -38.1 -3.4 55.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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Applying a function on each columns of a matrix
See sweep function On Fri, Jan 29, 2010 at 2:32 PM, anna lippelann...@hotmail.com wrote: Hello everyone, I have the following matrix [,1] [,2] [,3] [,4] [1,] 0.002809706 0.0063856960 0.0063856960 0.011749681 [2,] 0.004893124 0.0023118418 -0.0005122951 -0.014646465 [3,] 0.003547897 0.0063355297 0.0030410542 0.011403953 [4,] 0.004838299 -0.0040383645 -0.0090406831 -0.011027569 [5,] 0.035648755 0.0334815590 0.0380977404 0.059817597 I want to apply a function on each column varying the first parameter of the function. If I do it on one column only with apply it works perfectly as follow: apply(column1, 1, myfunction, parameter1= ..., parameter2=...) But when I try to do it on each column without even varying the parameter it doesn't work: apply(matrix, 2, apply, MARGIN = 1, Fun = myfunction, parameter1 =..., parameter2=...) I get the following error: Error in FUN(newX[, i], ...) : unused argument(s) (2, function (X, MARGIN, FUN, ...) Does someone know how to solve this? and is there a way to send a vector of parameter1 instead of a scalar? thank you - Anna Lippel -- View this message in context: http://n4.nabble.com/Applying-a-function-on-each-columns-of-a-matrix-tp1415660p1415660.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. -- 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] evaluating expressions with sub expressions
The following recursively walks the expression tree. The esub function is from this page (you may wish to read that entire thread): http://tolstoy.newcastle.edu.au/R/help/04/03/1245.html esub - function(expr, sublist) do.call(substitute, list(expr, sublist)) proc - function(e, env = parent.frame()) { for(nm in all.vars(e)) { if (exists(nm, env) is.language(g - get(nm, env))) { if (is.expression(g)) g - g[[1]] g - Recall(g, env) L - list(g) names(L) - nm e - esub(e, L) } } e } mat - expression(0, f1*s1*g1) g1 - expression(1/Tm) vals - data.frame(f1=1, s1=.5, Tm=2) e - sapply(mat, proc) sapply(e, eval, vals) The last line should give: sapply(e, eval, vals) [1] 0.00 0.25 On Fri, Jan 29, 2010 at 11:51 AM, Jennifer Young jennifer.yo...@math.mcmaster.ca wrote: Hallo I'm having trouble figuring out how to evaluate an expression when one of the variables in the expression is defined separately as a sub expression. Here's a simplified example mat - expression(0, f1*s1*g1) # vector of formulae g1 - expression(1/Tm) # expansion of the definition of g1 vals - data.frame(f1=1, s1=.5, Tm=2) # one set of possible values for variables before adding this sub expression I was using the following to evaluate mat sapply(mat, eval, vals) Obviously I could manually substitute in 1/Tm for each g1 in the definition of mat, but the actual expression vector is much longer, and the sub expression more complicated. Also, the subexpression is often adjusted for different scenarios. Is there a simple way of changing this or redefining mat so that I can define g1 like a macro to be used in the expression vector. Thanks! Jennifer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Question on codetools and parse trees
Dear R Users, Using codetools I obtained the text representation of the parse tree for this snippet z=quote({x[1]-2}) showTree(z) ({ (- ([ x 1) 2)) (A) If I understand correctly, x[1]-2 ought to be [-(x,1,2), so shouldn't i see ({ ( [- x 1 2 ) ) If indeed the parse tree in (A) is correct, the operation ([ x 1) returns the value of x[1], how then does the - operator know to change the 1st element of x ? Does the - implementation inspect the its 1st argument (e.g if it sees [ call, it instead changes itself to implementation of [-? Thank you Saptarshi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] code for FD
Dear list members, I'm tryng to write the code in order to calculate the index (expression 2) published in Ricotta Burrascano 2008 (Preslia 80, pp 61-71). Specifically, I'm having some problems in extending the index for more than two observations. Does anyone already write a function for such an index? Thank you in advance. Giovanni [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question on codetools and parse trees
On 29/01/2010 2:03 PM, Saptarshi Guha wrote: Dear R Users, Using codetools I obtained the text representation of the parse tree for this snippet z=quote({x[1]-2}) showTree(z) ({ (- ([ x 1) 2)) (A) If I understand correctly, x[1]-2 ought to be [-(x,1,2), so shouldn't i see ({ ( [- x 1 2 ) ) If indeed the parse tree in (A) is correct, the operation ([ x 1) returns the value of x[1], how then does the - operator know to change the 1st element of x ? Does the - implementation inspect the its 1st argument (e.g if it sees [ call, it instead changes itself to implementation of [-? The displayed parse tree is correct. You could confirm it by looking at z[[1]], z[[2]], z[[2]][[1]], etc. The [ call is the first argument to -, which is the destination of the assignment. The conversion to [- happens at evaluation time. 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] How do people use Sweave / R / Databases
I'm currently using r scripts in sweave to grab some data via ODBC, process it then generate some tables. I'd like to be able to give someone the files and let them reproduce what I've done. Is there some way to store the data that is gathered by ODBC so that the second person can recreate the work without the database (apart from just writing it to a file or into the document) Thanks Paul. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] SemiPar/spm question
Hello -- I posted this question yesterday and for some reason the post seems to be attached to the wrong thread. Also, I extended my test a little and it seems to indicate the problem is with spm. I would appreciate any help. Thanks. == library(plyr) library(SemiPar) data - data.frame(id=c(rep(111,100),rep(222,200)), value=c(rnorm(100,2,1),rnorm(200,10,5)), lhs=c(rnorm(100,2,1),rnorm(200,10,5))) #this works d_ply(data, c(id), function(x) { print(lm(lhs~value, data=x)) }) #this works data111 - data[data$id==111,] print(spm(data111$value ~ f(1:nrow(data111 #this does not work d_ply(data, c(id), function(x) { print(spmx - spm(x$value ~ f(1:nrow(x }) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 in R 2.9.x for R 2.10.x packages
[Env: Win Xp] Is there any options() setting or call to help() or help.start() that will allow me to view a help file for a package built under R 2.10.x under R 2.9.2? I'm using both R 2.9.2 and R 2.10.1, but prefer the former because the CHM help is so much easier to use. Yet, if I install a package built for R 2.10.x, I can't find *any* way to display a help file in this package. For example, after library(TeachinDemos), ?HWidentify Error in print.help_files_with_topic(x) : No text help for 'HWidentify' is available: corresponding file is missing In addition: Warning message: In print.help_files_with_topic(C:/R/R-2.9.2/library/TeachingDemos/chm/HWidentify) : No CHM help for 'HWidentify' in package 'TeachingDemos' is available: the CHM file for the package is missing So, I try help.start() updating HTML package listing updating HTML search index If nothing happens, you should open 'C:\R\R-2.9.2\doc\html\index.html' yourself I can then get to file:///C:/R/R-2.9.2/library/TeachingDemos/html/00Index.html but then all the links there give Not Found, e.g., file:///C:/R/R-2.9.2/library/TeachingDemos/html/HWidentify.html and, indeed, C:\R\R-2.9.2\library\TeachingDemos\html contains only 00Index.html. All the links therein are to .html files in the same directory, so of course are wrong. -Michael -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do people use Sweave / R / Databases
On 29/01/2010 2:28 PM, Paul wrote: I'm currently using r scripts in sweave to grab some data via ODBC, process it then generate some tables. I'd like to be able to give someone the files and let them reproduce what I've done. Is there some way to store the data that is gathered by ODBC so that the second person can recreate the work without the database (apart from just writing it to a file or into the document) What I've done in a case like that is to store the data in a .Rdata file using save(), then have the Sweave code call load() to load it at the beginning of the script. There's also the cacheSweave package (and I think another one whose name I can't remember) to cache the value of some code blocks; you might be able to bundle up the document with the cache to send to someone who doesn't want to re-run the retrieval code. 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.
Re: [R] help in R 2.9.x for R 2.10.x packages
On 29/01/2010 2:34 PM, Michael Friendly wrote: [Env: Win Xp] Is there any options() setting or call to help() or help.start() that will allow me to view a help file for a package built under R 2.10.x under R 2.9.2? I'm using both R 2.9.2 and R 2.10.1, but prefer the former because the CHM help is so much easier to use. Yet, if I install a package built for R 2.10.x, I can't find *any* way to display a help file in this package. For example, after library(TeachinDemos), ?HWidentify Error in print.help_files_with_topic(x) : No text help for 'HWidentify' is available: corresponding file is missing In addition: Warning message: In print.help_files_with_topic(C:/R/R-2.9.2/library/TeachingDemos/chm/HWidentify) : No CHM help for 'HWidentify' in package 'TeachingDemos' is available: the CHM file for the package is missing So, I try help.start() updating HTML package listing updating HTML search index If nothing happens, you should open 'C:\R\R-2.9.2\doc\html\index.html' yourself I can then get to file:///C:/R/R-2.9.2/library/TeachingDemos/html/00Index.html but then all the links there give Not Found, e.g., file:///C:/R/R-2.9.2/library/TeachingDemos/html/HWidentify.html and, indeed, C:\R\R-2.9.2\library\TeachingDemos\html contains only 00Index.html. All the links therein are to .html files in the same directory, so of course are wrong. The CHM help files were built at package install time. Binary packages are images of already-installed packages, so they won't have CHM files unless installed in 2.9.x or earlier. So you just need to get the package source, and install it into the earlier R. Sometimes this is easy, sometimes not. 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.
Re: [R] help in R 2.9.x for R 2.10.x packages
Dear Michael, the help system has been rearranged considerably. It is not possible to use binary packages prepared under R-2.10.x with earlier versions of R. The other way round is also not a really good idea. Note also that the most recent version of TeachingDemos (2.5) uses help markup that does not work with R versions prior to R-2.10.0. You can use TeachingDemos 2.4 with R-2.9.x, tough (and that version is still available in the Windows binary repository for the R-2.9.x series. Hence just say install.packages(TeachingDemos) if you wanto to stay with that ancient version of R. Best wishes, Uwe On 29.01.2010 20:34, Michael Friendly wrote: [Env: Win Xp] Is there any options() setting or call to help() or help.start() that will allow me to view a help file for a package built under R 2.10.x under R 2.9.2? I'm using both R 2.9.2 and R 2.10.1, but prefer the former because the CHM help is so much easier to use. Yet, if I install a package built for R 2.10.x, I can't find *any* way to display a help file in this package. For example, after library(TeachinDemos), ?HWidentify Error in print.help_files_with_topic(x) : No text help for 'HWidentify' is available: corresponding file is missing In addition: Warning message: In print.help_files_with_topic(C:/R/R-2.9.2/library/TeachingDemos/chm/HWidentify) : No CHM help for 'HWidentify' in package 'TeachingDemos' is available: the CHM file for the package is missing So, I try help.start() updating HTML package listing updating HTML search index If nothing happens, you should open 'C:\R\R-2.9.2\doc\html\index.html' yourself I can then get to file:///C:/R/R-2.9.2/library/TeachingDemos/html/00Index.html but then all the links there give Not Found, e.g., file:///C:/R/R-2.9.2/library/TeachingDemos/html/HWidentify.html and, indeed, C:\R\R-2.9.2\library\TeachingDemos\html contains only 00Index.html. All the links therein are to .html files in the same directory, so of course are wrong. -Michael __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do people use Sweave / R / Databases
On 29/01/2010 2:55 PM, Tobias Verbeke wrote: Duncan Murdoch wrote: On 29/01/2010 2:28 PM, Paul wrote: I'm currently using r scripts in sweave to grab some data via ODBC, process it then generate some tables. I'd like to be able to give someone the files and let them reproduce what I've done. Is there some way to store the data that is gathered by ODBC so that the second person can recreate the work without the database (apart from just writing it to a file or into the document) What I've done in a case like that is to store the data in a .Rdata file using save(), then have the Sweave code call load() to load it at the beginning of the script. There's also the cacheSweave package (and I think another one whose name I can't remember) The weaver package on Bioconductor? http://bioconductor.org/packages/release/bioc/html/weaver.html Yes, that's it. Thanks! Duncan Murdoch Best, Tobias to cache the value of some code blocks; you might be able to bundle up the document with the cache to send to someone who doesn't want to re-run the retrieval code. 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do people use Sweave / R / Databases
On Jan 29, 2010, at 1:28 PM, Paul wrote: I'm currently using r scripts in sweave to grab some data via ODBC, process it then generate some tables. I'd like to be able to give someone the files and let them reproduce what I've done. Is there some way to store the data that is gathered by ODBC so that the second person can recreate the work without the database (apart from just writing it to a file or into the document) Thanks Paul. There are likely to be several approaches, as there always is with R, but here is mine. I have a function that I wrote to (via RODBC) obtain the entire content of a series of Oracle views from our server. Basically a loop of select * from VIEWNAME queries, where the changing parts of the query are paste()d together. The function takes a viewname prefix to define a common set of views, gets the names of the views that match the prefix pattern from a table that stores all viewnames and then creates a series of data frames in the R global environment via assign(), with one data frame per Oracle view. The function is called from within a code chunk in a .Rnw file, which by default is set to results=hide,eval=FALSE=. I do this so that I can run the code chunk once manually to secure the data. Note that I use ESS for all of this, so I just highlight that code and send it to the R buffer (session). I then save the data frames (Oracle views) to a .RData file using save() to preserve the clean source data. I can then run the rest of the .Rnw file as much as I want, changing code as I need to, but always using the same set of data, since the code chunk containing the function that gets the Oracle data is not evaluated on subsequent runs. I also use subversion to version control changes made to the .Rnw file as required and to store the original data set. Since I will perform updated retrievals over time, I have the flexibility of running the .Rnw file (or a revised version) on old versions of the data retrieval as I need. So, using this approach, you can pass the .RData file off to your colleague, along with the .Rnw file and they should be good to go. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Using win-builder with static libraries
Dear All, I am intending to build a package (pksmooth) on Linux to work on Windows. Some c++ functions need c++ libraries (numerical recipes) from a static library libNR.a. Building the package on Linux for Linux is allright. However, when sending the 'pksmooth_1.0.tar.gz' to the online Windows builder (win-builder.r-project.org),the compilation doesn't take into account the library libNR.a. Yet, it is included in the tar.gz file in a 'libs' folder and called in a makefile located in the 'src' folder. Any comment will be appreciated, Maxime NB: Here is the compilation error: _(__ * installing *source* package 'pksmooth' ... ** libs making DLL ... g++ -Id:/Rcompile/recent/R-2.10.1/include-O2 -Wall -c ksmoothC.C -o ksmoothC.o ksmoothC.C: In function 'double fxRoot(double (*)(double), double, double)': ksmoothC.C:16: warning: 'root' may be used uninitialized in this function g++ -shared -s -o pksmooth.dll tmp.def ksmoothC.o -Ld:/Rcompile/recent/R-2.10.1/bin -lR ksmoothC.o:ksmoothC.C:(.text+0x1ab): undefined reference to `NR::zbrak(double (*)(double), double, double, int, NRVecdouble, NRVecdouble, int)' ksmoothC.o:ksmoothC.C:(.text+0x1fc): undefined reference to `NR::rtbis(double (*)(double), double, double, double)' collect2: ld returned 1 exit status ... done ** R ** preparing package for lazy loading ** help *** installing help indices ** building package indices ... ** MD5 sums packaged installation of 'pksmooth' as pksmooth_1.0.zip * DONE (pksmooth) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] combine 3 affybatches
Hello, Im trying to combine 3 affybatches (1x hgu133+2 array and 2x hgu133a array) Im useing this script: library(matchprobes) library(affy) library(AnnotationDbi) library(hgu133plus2probe) library(hgu133aprobe) library(hgu133a.db) u133p2 = ReadAffy() # reading hgu133 +2 cel file into affybatch u133a1 = ReadAffy() # reading hgu133a cel file into affybatch u133a2 = ReadAffy() # reading hgu133a cel file into affybatch data-combineAffyBatch(list(u133p2,u133a1,u133a2),c(hgu133plus2probe,hgu133aprobe,hgu133aprobe),newcdf=mycdf) This wil give the following error: package:hgu133plus2probehgu133plus2probe package:hgu133aprobehgu133aprobe 241837 unique probes in common Error in as.vector(x, character) : cannot coerce type 'closure' to vector of type 'character' Can somebody help me with the combining of 3 affybatches? Joeri Meijsen TU Delft the Netherlands -- View this message in context: http://n4.nabble.com/combine-3-affybatches-tp1415313p1415313.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] Saving Xpose.VPC as wmf and Turning off Recording
Dear All, I have been attempting to save the output from xpose.VPC as a windows metafile. When I ran vpc on PSN I had 6 groups and would like to output a single wmf for each graph. When I set max.plots.per.page=1, xpose turns on recording (page# in top right corner of output) and prints one graph per page. I have written to pdf, but the page number remains in the top right corner. The goal is to get each graph in a single windows metafile. Since xpose.VPC is a wrap-around xyplot, I attempted to use (without success): page=function(x){SavePlot(paste(dir,x,.wmf),type=wmf)} Any suggestions would be greatly appreciated. xpose.VPC(vpc.file,vpctab=vpctab, PI=both, PI.real=T, xlb=Time (Min), ylb=Ln(Concentration), max.plots.per.page=1, main=Visual Predictive Check, ) Ryan Notice: This e-mail message, together with any attachme...{{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] Setting breaks for histogram of dates
Loris Bennett loris.benn...@fu-berlin.de writes: Hi, I have a list of dates like this: date 2009-12-03 2009-12-11 2009-10-07 2010-01-25 2010-01-05 2009-09-09 2010-01-19 2010-01-25 2009-02-05 2010-01-25 2010-01-27 2010-01-27 ... and am creating a histogram like this t - read.table(test.dat,header=TRUE) hist(as.Date(t$date), years, format = %d/%m/%y, freq=TRUE) However, I would rather not label the breaks themselves, but instead print the date with the format %Y, between the breaks. Is there a simple way of doing this? Regards Loris -- Dr. Loris Bennett ZEDAT Computer Centre Freie Universität Berlin Berlin, Germany __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. With a little help from a chap called Jim who doesn't seem to have replied to the list, I looked discovered 'axis' and came up with this: hist(as.Date(t$date),years,format=%Y,freq=TRUE,xaxt=n) In hist.default(unclass(x), unclass(breaks), plot = FALSE, ...) : argument '...' is not made use of axis(1,at=as.Date(c(2009-07-01,2010-07-01)), labels=c(2009,2010),lwd=0,lwd.ticks=0) I don't know what to make of the warning but the labels are placed as I want. Loris -- Dr. Loris Bennett ZEDAT Computer Centre Freie Universität Berlin Berlin, Germany __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Vectors with equal sd but different slope
Hi, what I would need are 2 vector pairs (x,y) and (x1,y1). x and x1 must have the same sd. y and y1 should also exhibit the same sd's but different ones as x and x1. Plotting x,y and x1,y1 should produce a plot with 2 vectors having a different slope. Plotting both vector pairs in one plot with fixed axes should reveal the different slope. many thanks syrvn -- View this message in context: http://n4.nabble.com/Vectors-with-equal-sd-but-different-slope-tp1415562p1415562.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] Merge and join data
Thank you, that worked great! Sean Peter Alspach wrote: Tena koe Sean I suspect the apply() and merge() functions are working, but they may not be doing what you expect :-) You could try rbind() and aggregate(): data.frame1$HAD - as.numeric(NA) data.both - rbind(data.frame1, data.frame2) aggregate(data.both[,-(1:3)], data.both[,1:3], sum, na.rm=T) Season Gear Area COD POLL HAD 1 winter dredge 515 113 174 18 This assumes COD, POLL and HAD are numeric. HTH Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sean M. Lucey Sent: Thursday, 21 January 2010 9:20 a.m. To: r-help@r-project.org Subject: [R] Merge and join data Hi, I'm looking to combine two data frames. Several of the columns are in common while the others need to be summed up. The apply functions and the merge functions don't seem to be working. I've included a basic example of what I'm trying to do below. Thanks! Sean data.frame1-as.data.frame(matrix(c('winter','dredge','515',10 0,150),1,5)) names(data.frame1)-c('Season','Gear','Area','COD','POLL') data.frame2-as.data.frame(matrix(c('winter','dredge','515',13 ,24,18),1,6)) names(data.frame2)-c('Season','Gear','Area','COD','POLL','HAD') I'd like to end up with something that looks like this: Season Gear Area COD POLL HAD winter dredge 515113 174 18 Thanks, Sean __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 with readVECT6 in spgrass6 package: A possible solution.
Hi I am working with spgrass6 package and GRASS v.6.2. Everything was fine until I tryed to read a vector file with readVECT6 (and other related vector commands, like vInfo). When I ran these commands, the problem immediately appeared ( Sorry, is not a valid flag ). Ok, the solution is easy: - You have to download the spgrass package within a folder, in order to install the package from this directory. You should type (being in R) download.packages( spgrass6 , destdir=/thef/folder/that/you/want/ ) in my computer, the/folder/that/you/want/ = /home/jdgiraldo/R/downloaded_packages (I had created /downloaded_packages earlier ). - Ok. Unzip the spgrass6_0.6-14.tar.gz file (this is my downloaded version). - Open the vect_link.R file. It must be located in the/folder/that/you/want/spgrass6/R folder. - Now, go to the line 218. You'll find the next line vinfo0 - execGRASS(v.info, flags=t , parameters=list(map=vname), intern=TRUE, ignore.stderr=ignore.stderr) and it should be changed into vinfo0 - execGRASS(v.info, flags=g , parameters=list(map=vname), intern=TRUE, ignore.stderr=ignore.stderr) Did you see??? A little t is hateful. I think it was a typing mistake. - Save and close the vect_link.R file. - Install the modified spgrass6 package. Use install.package( /home/jdgiraldo/R/downloaded_packages/spgrass6 , repos=NULL ) - It's ready to use. I hope this information will be useful. Juan Diego __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Vector from Matrix
Dear Mailing List Members, the problem I've been grappling with für quite some time now is the following: I have a 100 rows x 200 columns matrix. data.set - matrix(rnorm(2, 100, 200)) Now I would like to get a vector of length 100 which collects the values from the following procedure: Take the sum of the minima of the two values from each row of columns 1 and 101, and divide it by the sum of column 101. Do the same for column 2 and 102, 3 and 103 and so on. Thanks a lot for your help. Alrik *** Alrik Thiem Research Assistant WEC E17 Weinbergstrasse 11 Center for Comparative and International Studies (CIS) and Center for Security Studies (CSS) Swiss Federal Institute of Technology Zurich CH-8092 Zurich Tel.: 0041 44 63 20937 th...@sipo.gess.ethz.ch http://www.cis.ethz.ch/ http://www.css.ethz.ch/ *** [[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] [BioC] Suppress output from getGEO
On Fri, Jan 29, 2010 at 10:04 AM, Craig P. Pyrame crap...@gmail.com wrote: Dear R-ers, I am using getGEO to download expression data from the Gene Expression Omnibus. With default settings, when a file is downloaded and parsed, lots of dotted lines are printed in the terminal, like this: .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. downloaded 50.2 Mb but many more! I tried to suppress this rather unhelpful behavior with capture.output and sink, as below, but to no effect: capture.output(getGEO(GEO=GEO)) # GEO is some GEO id sink('/dev/null'); getGEO(GEO=GEO); sink() Is this an issue with getGEO, or some underlying function? How can I avoid having the terminal spammed? Could the function responsible for this annoying output be modified to put an end to this? Hi, Craig. These dots are from the output from download.file(). GEOquery was modified to use quiet=TRUE on December 8, 2009. If you would like to take advantage of this change, you can use the development version of GEOquery. Sean __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Data.frame manipulation
Thanks again, Dennis and Petr! The solution using the plyr package was perfect: ddply(data, .(id, mod1), summarize, es = mean(es), mod2 = head(mod2, 1)) Take care, AC On Thu, Jan 28, 2010 at 11:26 PM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi r-help-boun...@r-project.org napsal dne 28.01.2010 17:40:01: Thank you, Dennis and Petr. One more question: when aggregating to one es per id, how would I go about keeping the other variables in the data.frame (e.g., keeping the value for the first row of the other variables, such as mod2) e.g.: # Dennis provided this example (notice how mod2 is removed from the output): with(x, aggregate(list(es = es), by = list(id = id, mod1 = mod1), mean)) id mod1 es 1 31 0.20 2 12 0.30 3 24 0.15 # How can I get this output (taking the first row of the other variable in the data.frame): If I remember it correctly in my suggestion I used something like aggregate(x[,-columns.mod1 and mod2], by = x[, columns.mod1 and mod2, mean) Which shall use mod2 as aggregating variable. Does it result in output you wanted? Regards Petr id es mod1 mod2 1 .30 2wai 2 .15 4other 3 .20 1 itas Thank you, AC On Thu, Jan 28, 2010 at 1:29 AM, Petr PIKAL petr.pi...@precheza.cz wrote: HI r-help-boun...@r-project.org napsal dne 28.01.2010 04:35:29: Hi All, I'm conducting a meta-analysis and have taken a data.frame with multiple rows per study (for each effect size) and performed a weighted average of effect size for each study. This results in a reduced # of rows. I am particularly interested in simply reducing the additional variables in the data.frame to the first row of the corresponding id variable. For example: id-c(1,2,2,3,3,3) es-c(.3,.1,.3,.1,.2,.3) mod1-c(2,4,4,1,1,1) mod2-c(wai,other,calpas,wai,itas,other) data-as.data.frame(cbind(id,es,mod1,mod2)) Do not use cbind. Its output is a matrix and in this case character matrix. Resulting data frame will consist from factors as you can check by str(data) data-data.frame(id=id,es=es,mod1=mod1,mod2=mod2) data id esmod1 mod2 1 1 0.32 wai 2 2 0.14 other 3 2 0.24 calpas 4 3 0.11 itas 5 3 0.21 wai 6 3 0.31 wai # I would like to reduce the entire data.frame like this: E.g. aggregate aggregate(data[, -(3:4)], data[,3:4], mean) mod1 mod2 id es 14 calpas 2 0.3 21 itas 3 0.2 31 other 3 0.3 44 other 2 0.1 51wai 3 0.1 62wai 1 0.3 doBy or tapply or ddply from plyr library or Regards Petr id es mod1 mod2 1 .30 2wai 2 .15 4other 3 .20 1 itas # If possible, I would also like the option of this (collapsing on id and mod2): id es mod1 mod2 1 .30 2wai 2 0.1 4 other 2 0.2 4calpas 3 0.1 1 itas 3 0.251 wai Any help is much appreciated! AC Del Re [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.