[R] Zero Index Origin?
I'm very new to R and utterly blown away by not only the language but the unbelievable set of packages and the documentation and the documentation standards and... I was an early APL user and never lost my love for it and in R I find most of the essential things I loved about APL except for one thing. At this early stage of my learning I can't yet determine if there is a way to effect what in APL was zero index origin, the ordinality of indexes starts with 0 instead of 1. Is it possible to effect that in R without a lot of difficulty? I come here today from the world of DSP research and development where Matlab has a near hegemony. I see no reason whatsoever that R couldn't replace it with a _far_ better and _far_ less idiosyncratic framework. I'd be interested in working on a Matlab equivalent DSP package for R (if that isn't being done by someone) and one of the things most criticized about Matlab from the standpoint of the DSP programmer is its insistence on 1 origin indexing. Any feedback greatly appreciated. Thanks, Bob -- Things should be described as simply as possible, but no simpler. A. Einstein __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Failure to compile source packages in Debian
F. Tusell [EMAIL PROTECTED] wrote on 31/03/2004 10:06:32: [...] and yet libgc2-pic is not resolved. *HOWEVER* following your lead that whatever is needed must by in a library of name libg2c*, I did the following in /usr/lib: ln -s libg2c0.so.0 libg2c-pic.so and everything works like a charm. Seems it si just a library that changed its name. Hmm.. Doing a search on http://www.debian.org/distrib/packages#search_contents using options Keyword g2c-pic packages that contain files or directories, whose names contain the keyword testing Intel x86 points to g77 packages. Probably installing this one is a better solution ? HTH, Tobias __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Much of R is itself written in R, so you cannot possibly change something as fundamental as this. Further, index 0 has a special meaning that you would lose if R have 0-based indexing. However, the R thinking is to work with whole objects (vectors, arrays, lists ...) and you rather rarely need to know what numbers are in an index vector. There are usages such as 1:n, and those are quite often wrong: they should be seq(length=n) or seq(along=x) or some such, since n might be zero. If you are writing code that works with single elements, you are probably a lot better off writing C code to link into R (and C is 0-based ...). On Wed, 31 Mar 2004, Bob Cain wrote: I'm very new to R and utterly blown away by not only the language but the unbelievable set of packages and the documentation and the documentation standards and... I was an early APL user and never lost my love for it and in R I find most of the essential things I loved about APL except for one thing. At this early stage of my learning I can't yet determine if there is a way to effect what in APL was zero index origin, the ordinality of indexes starts with 0 instead of 1. Is it possible to effect that in R without a lot of difficulty? I come here today from the world of DSP research and development where Matlab has a near hegemony. I see no reason whatsoever that R couldn't replace it with a _far_ better and _far_ less idiosyncratic framework. I'd be interested in working on a Matlab equivalent DSP package for R (if that isn't being done by someone) and one of the things most criticized about Matlab from the standpoint of the DSP programmer is its insistence on 1 origin indexing. Any feedback greatly appreciated. Thanks, Bob -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Bob Cain wrote: I'm very new to R and utterly blown away by not only the language but the unbelievable set of packages and the documentation and the documentation standards and... I was an early APL user and never lost my love for it and in R I find most of the essential things I loved about APL except for one thing. At this early stage of my learning I can't yet determine if there is a way to effect what in APL was zero index origin, the ordinality of indexes starts with 0 instead of 1. Is it possible to effect that in R without a lot of difficulty? I come here today from the world of DSP research and development where Matlab has a near hegemony. I see no reason whatsoever that R couldn't replace it with a _far_ better and _far_ less idiosyncratic framework. I'd be interested in working on a Matlab equivalent DSP package for R (if that isn't being done by someone) and one of the things most criticized about Matlab from the standpoint of the DSP programmer is its insistence on 1 origin indexing. Any feedback greatly appreciated. Thanks, Bob Hallo Bob, in APL we control index origin by QUAD.IO and QUAD.IO \in {0,1}. Suppose within a function index origin is unknown: a) If we want to work with origin 0 we write x[ i + QUAD.IO ] b) ... with origin 1 ... x[ i - !QUAD.IO ] . So set: QUAD.IO - 1 and use a) --- apl-like. Or define an index shift function: io.0-function(ind) ind+1 to be able to type x[io.0(0:5)] I am shure that your first experiments have been to implement APL functions like take, drop, rotate, ... and now you are looking for a more elegant way to manage origin 0 than +QUAD.IO. Peter Wolf __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Can R be useful to me?
hi My name is Luiz Tozzi and I have an aplication of R in mind but I dont know if it works. I've got a UNIX DEC machine here in my work and I have to generate statistical graphics and tables in GIF. We use to generate them in Excel sheets, importing our data to a Windows computer. My question is: can I generate graphics and tables in gif ou any graphical format through shell script?? can I call R, run a package in my ascii data e then export the results to a gif, png or whatever? Depending on your answers I'll learn R to do this kind ok task. thanks in advaced, Luiz Rodrigo L. Tozzi METOP -- CPTEC/INPE [EMAIL PROTECTED] ICQ: 3276578 TEL: (12)31868419 Deus nunca fica em roaming Ele esta sempre a uma oracao de distancia __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Bob Cain wrote: At this early stage of my learning I can't yet determine if there is a way to effect what in APL was zero index origin, the ordinality of indexes starts with 0 instead of 1. Is it possible to effect that in R without a lot of difficulty? Clearly R wasn't written by Dijkstra: http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF This text was pointed out to me when I started using Python, which has zero-based indexing. Python can look so much like R, but there are subtle differences. R: x=c(5,4,3,2,1) x[3] [1] 3 x[2:4] [1] 4 3 2 compare: Python: x=[5,4,3,2,1] x[3] 2 x [5, 4, 3, 2, 1] x[2:4] [3, 2] A single element from a sequence in python is indexed from zero, hence x[3] == 2, but a range indexes from the commas between the limits of the range. Hence x[2:4] is the elements between comma 2 and comma 4 - hence its only 2 elements. Did my head in when I first started pythoning. Flipping between R and python is not recommended, kudos to all those involved in such R-python links... Baz __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Can R be useful to me?
On Wed, Mar 31, 2004 at 08:32:49AM -0300, Luiz Rodrigo Tozzi wrote: My question is: can I generate graphics and tables in gif ou any graphical format through shell script?? can I call R, run a package in my ascii data e then export the results to a gif, png or whatever? Yes - R is well suited for such a task. Actually there even is a package called sweave which allows you to use LaTeX to format your results and create a perfectly fine report on the fly. If you need to generate such reports on a regular basis R is definitely a good way to appraoch the task. cu Philipp -- Dr. Philipp PagelTel. +49-89-3187-3675 Institute for Bioinformatics / MIPS Fax. +49-89-3187-3585 GSF - National Research Center for Environment and Health Ingolstaedter Landstrasse 1 85764 Neuherberg, Germany http://mips.gsf.de/~pagel __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Can R be useful to me?
On Wed, 31 Mar 2004 08:32:49 -0300, you wrote: My question is: can I generate graphics and tables in gif ou any graphical format through shell script?? can I call R, run a package in my ascii data e then export the results to a gif, png or whatever? Depending on your answers I'll learn R to do this kind ok task. Base R doesn't have support for the GIF format, but it can produce PNG, EPS or JPEG graphics files. It's possible there's a user-contributed package that does GIF, but the license restrictions make that somewhat unlikely. So yes, you could run R in batch mode to do what you want, as long as GIF isn't a requirement. Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Hi Bob, Jonathan Rougier's Oarray package might be what you want. Jim __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Can R be useful to me?
wow! this R is real awesome! thanks all of you. i'll start the tutorial and manual reading right now tks! Luiz Rodrigo L. Tozzi METOP -- CPTEC/INPE [EMAIL PROTECTED] ICQ: 3276578 TEL: (12)31868419 Deus nunca fica em roaming Ele esta sempre a uma oracao de distancia __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] as.environment() does not work for package:base?
OK. Thank you. I have not seen that particularity in the documentation... is it written somewhere? However, I found: .BaseNamespaceEnv environment: namespace:base which is, according to the documentation, still experimental. Should I better use envir = NULL or .BaseNamespaceEnv to get a full control on objects in the base environment (this is for an object browser, so, I need full control on EVERY object in any environment), given that I will be careful of course with experimental stuff? Best, Philippe Grosjean -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Tuesday, 30 March, 2004 22:28 To: Philippe Grosjean Cc: r-help Subject: Re: [R] as.environment() does not work for package:base? NULL is the correct answer: as an environment base is denoted by NULL. Did you think to try ls(envir=NULL) ? If not, do so now. On Tue, 30 Mar 2004, Philippe Grosjean wrote: Hello, I want to retrieve one environment from the search path. I have: search() [1] .GlobalEnv package:R2HTML package:tcltk package:methods package:ctest [6] package:mva package:modreg package:nls package:ts Autoloads [11] package:base as.environment(1) environment: R_GlobalEnv as.environment(2) environment: package:R2HTML attr(,name) [1] package:R2HTML attr(,path) [1] C:/PROGRA~1/R/rw1081/library/R2HTML as.environment(10) environment: 01749504 attr(,name) [1] Autoloads as.environment(11) NULL as.environment(package:base) NULL So, everything works fine, except for package:base, the 11th entry. Is it by purpose that as.environment() returns NULL? Is it because package:base is sealed? Then, how do I get the environment corresponding to package:base? Thanks, Philippe Grosjean ...°})) ) ) ) ) ) ( ( ( ( ( Prof. Philippe Grosjean \ ___ ) \/ECO\ ( Numerical Ecology of Aquatic Systems /\___/ ) Mons-Hainaut University, Pentagone / ___ /( 8, Av. du Champ de Mars, 7000 Mons, Belgium /NUM\/ ) \___/\ ( phone: + 32.65.37.34.97, fax: + 32.65.37.33.12 \ ) email: [EMAIL PROTECTED] ) ) ) ) ) SciViews project coordinator (http://www.sciviews.org) ( ( ( ( ( ... __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] as.environment() does not work for package:base?
On Wed, 31 Mar 2004, Philippe Grosjean wrote: OK. Thank you. I have not seen that particularity in the documentation... is it written somewhere? Yes, the source code if nowhere else. However, I found: .BaseNamespaceEnv environment: namespace:base which is, according to the documentation, still experimental. Should I better use envir = NULL or .BaseNamespaceEnv to get a full control on objects in the base environment (this is for an object browser, so, I need full control on EVERY object in any environment), given that I will be careful of course with experimental stuff? There is a difference between the package:foo and namespace:foo. I don't know what you mean by `full control': you should regard namespaces as read-only and private. Base is exceptional in many ways and it is the relationship of its namespace to everything else which is subject to change. Best, Philippe Grosjean -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Tuesday, 30 March, 2004 22:28 To: Philippe Grosjean Cc: r-help Subject: Re: [R] as.environment() does not work for package:base? NULL is the correct answer: as an environment base is denoted by NULL. Did you think to try ls(envir=NULL) ? If not, do so now. On Tue, 30 Mar 2004, Philippe Grosjean wrote: Hello, I want to retrieve one environment from the search path. I have: search() [1] .GlobalEnv package:R2HTML package:tcltk package:methods package:ctest [6] package:mva package:modreg package:nls package:ts Autoloads [11] package:base as.environment(1) environment: R_GlobalEnv as.environment(2) environment: package:R2HTML attr(,name) [1] package:R2HTML attr(,path) [1] C:/PROGRA~1/R/rw1081/library/R2HTML as.environment(10) environment: 01749504 attr(,name) [1] Autoloads as.environment(11) NULL as.environment(package:base) NULL So, everything works fine, except for package:base, the 11th entry. Is it by purpose that as.environment() returns NULL? Is it because package:base is sealed? Then, how do I get the environment corresponding to package:base? Thanks, Philippe Grosjean ...°})) ) ) ) ) ) ( ( ( ( ( Prof. Philippe Grosjean \ ___ ) \/ECO\ ( Numerical Ecology of Aquatic Systems /\___/ ) Mons-Hainaut University, Pentagone / ___ /( 8, Av. du Champ de Mars, 7000 Mons, Belgium /NUM\/ ) \___/\ ( phone: + 32.65.37.34.97, fax: + 32.65.37.33.12 \ ) email: [EMAIL PROTECTED] ) ) ) ) ) SciViews project coordinator (http://www.sciviews.org) ( ( ( ( ( ... __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] choice-based conjoint
Hello everyone, I am new to this list and the R-Project, so I hope my question is not trivial or has been answered before. I searched the FAQs and the mailing list archives and I could not find anything about Conjoint Analysis. I am especially interested in Choice-based Conjoint, resp. discrete choice models. Is there a function / module that handles this issue? Or can the multinomial logit model be used? I would doubt the latter, for in a Choice-based Conjoint analysis the choice has to be conditioned to the alternatives in the choice set which are not equal for the respondents. Any help will be much appreciated! Thank you! Felix [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Zero Index Origin?
Dear Bob, One approach would be to introduce a class of objects for which zero-based indexing is implemented. Here's a simple example: [.io0 - function(x, i) as.vector(x)[i + 1] v - 0:10 class(v) - io0 v[0] [1] 0 v[0:5] [1] 0 1 2 3 4 5 Of course, a serious implementation would handle arrays and perhaps other kinds of objects, and would be more careful about the subscript. I hope that this helps, John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bob Cain Sent: Wednesday, March 31, 2004 3:16 AM To: R-help Subject: [R] Zero Index Origin? I'm very new to R and utterly blown away by not only the language but the unbelievable set of packages and the documentation and the documentation standards and... I was an early APL user and never lost my love for it and in R I find most of the essential things I loved about APL except for one thing. At this early stage of my learning I can't yet determine if there is a way to effect what in APL was zero index origin, the ordinality of indexes starts with 0 instead of 1. Is it possible to effect that in R without a lot of difficulty? I come here today from the world of DSP research and development where Matlab has a near hegemony. I see no reason whatsoever that R couldn't replace it with a _far_ better and _far_ less idiosyncratic framework. I'd be interested in working on a Matlab equivalent DSP package for R (if that isn't being done by someone) and one of the things most criticized about Matlab from the standpoint of the DSP programmer is its insistence on 1 origin indexing. Any feedback greatly appreciated. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
If you are willing to do it yourself you can define a class for which indexing behaves that way. For example, here is a start for a limited implementation for vectors. The first statement defines the constructor, the second defines [, the third converts an index 0 based vector back to a regular vector, the next implements lvalues and the last provides print method. as.vector0 - function(x) structure(x, class=vector0) [.vector0 - function(x,i) as.vector0(as.vector.vector0(x)[i+1]) as.vector.vector0 - function(x) unclass(x) [-.vector0 - function(x,i,value) { x - as.vector.vector0(x) x[i+1] - value as.vector0(x) } print.vector0 - function(x) print(as.vector.vector0(x)) # Test: x - as.vector0(1:10) x[0:4] - 100 * x[0:4] x Bob Cain arcane at arcanemethods.com writes: : : I'm very new to R and utterly blown away by not only the : language but the unbelievable set of packages and the : documentation and the documentation standards and... : : I was an early APL user and never lost my love for it and in : R I find most of the essential things I loved about APL : except for one thing. At this early stage of my learning I : can't yet determine if there is a way to effect what in APL : was zero index origin, the ordinality of indexes starts with : 0 instead of 1. Is it possible to effect that in R without : a lot of difficulty? : : I come here today from the world of DSP research and : development where Matlab has a near hegemony. I see no : reason whatsoever that R couldn't replace it with a _far_ : better and _far_ less idiosyncratic framework. I'd be : interested in working on a Matlab equivalent DSP package for : R (if that isn't being done by someone) and one of the : things most criticized about Matlab from the standpoint of : the DSP programmer is its insistence on 1 origin indexing. : Any feedback greatly appreciated. : : Thanks, : : Bob __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] choice-based conjoint
Not quite an answer. I've been using ace() in the acepack library to do _ordinary_ conjoint analysis with rating responses. I never do (nor have any reason to do) choice-based conjoint, so I haven't thought about how to analyze such data, but I'd be interested in the answer if anyone has it. (What would happen if you just use ace() with a binary dependent variable? What if the stimuli are two alternative options rather than one option vs. a constant default?) For examples of scripts that I used with an undergrad class, see http://www.sas.upenn.edu/~baron/353/ particularly http://www.sas.upenn.edu/~baron/353/ca1.R Jon -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page:http://www.sas.upenn.edu/~baron R page: http://finzi.psych.upenn.edu/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] choice-based conjoint
The multinomial model can be used- it's the standard method used, although there are now more sophisticated ones - see Kenneth Train's website at Berkley for the Mixed Logit. I too am new to R so can't really comment on how to implement it in this package. If you want to run more sophisticated models (e.g. Mixed Logit) and you are an academic (non-commercial) you could download a free version of Ox (a matrix programming language very similar to GAUSS) and do a search for Mixed Logit - some one wrote a free routine that converts Ken Train's GAUSS code to Ox. Afraid I don't have time to look up the website addresses. Hope this helps, Stephen Stephen Kay Head of Statistics Adelphi Group Products www.adelphigroup.com -Original Message- From: Felix Eggers [mailto:[EMAIL PROTECTED] Sent: 31 March 2004 13:50 To: [EMAIL PROTECTED] Subject: [R] choice-based conjoint Hello everyone, I am new to this list and the R-Project, so I hope my question is not trivial or has been answered before. I searched the FAQs and the mailing list archives and I could not find anything about Conjoint Analysis. I am especially interested in Choice-based Conjoint, resp. discrete choice models. Is there a function / module that handles this issue? Or can the multinomial logit model be used? I would doubt the latter, for in a Choice-based Conjoint analysis the choice has to be conditioned to the alternatives in the choice set which are not equal for the respondents. Any help will be much appreciated! Thank you! Felix [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html DISCLAIMER: The information in this message is confidential ...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Aggregating frequency of irregular time series
You are quite right. One can see from the original function I wrote that I am not very familiar with the apply family. Thanks for pointing out this improvement. Below is the new version of the function; any other comments are welcome. Regards, Whit Timebase - function(x,monthly=T,first.day=T) { if(length(dim(x))!=2) stop(can only take 2 dimensional data.) seriesDates - as.integer(Dates(x)) # year and Month seriesYM - as.integer(seriesDates/100) # for each seriesYM grab the max day of month ans.dates - as.numeric(tapply( seriesDates, seriesYM, max )) ans - matrix(NA,nrow=length(ans.dates),ncol=ncol(x)) colnames(ans) - colnames(x) ans[] - x[as.character(ans.dates),] if(first.day==T) { rownames(ans) - paste(substring(as.character(ans.dates),1,6),01,sep=) } else { rownames(ans) - ans.dates } as.tseries(ans) } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gabor Grothendieck Sent: Tuesday, March 30, 2004 8:59 PM To: [EMAIL PROTECTED] Subject: Re: [R] Aggregating frequency of irregular time series I am not 100% sure I understand what you are trying to accomplish but if its to calculate the highest date in seriesDates for each value of seriesYM then you can do it without a loop like this (untested): tapply( seriesDates, seriesYM, max ) Whit Armstrong Whit.Armstrong at tudor.com writes: : : This function will probably work for you if your dates are in the format : mmdd. Use it to convert the series from daily to monthly, then use a 1 : period difference to calc the returns of the series. : : Feel free to contact me off list with any questions. : : Dates - function(x) rownames(x) : : Timebase - function(x,monthly=T,first.day=T) { : if(length(dim(x))!=2) stop(can only take 2 dimensional data.) : : seriesDates - as.integer(Dates(x)) : : # year and Month : seriesYM - as.integer(seriesDates/100) : seriesYM.unique - sort(unique(seriesYM)) : ans.nrow - length(seriesYM.unique) : : # loop through all the unique months and grab the max day of month : ans - matrix(NA,nrow=ans.nrow,ncol=ncol(x)) : ans.dates - vector(numeric,ans.nrow) : : for (i in 1:ans.nrow) { : : this.month - seriesYM == seriesYM.unique[i] : max.day - max(seriesDates[this.month]) : ans.dates[i] - max.day : } : : : colnames(ans) - colnames(x) : ans[] - x[as.character(ans.dates),] : : if(first.day==T) { : rownames(ans) - : paste(substring(as.character(ans.dates),1,6),01,sep=) : } else { : rownames(ans) - ans.dates : } : : as.tseries(ans) : } : : -Original Message- : From: r-help-bounces at stat.math.ethz.ch : [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Patrick Burns : Sent: Tuesday, March 30, 2004 2:37 PM : To: Ajay Shah : Cc: r-help at stat.math.ethz.ch; Ivan Alves : Subject: Re: [R] Aggregating frequency of irregular time series : : : Assuming that you are using log returns, one approach (probably not the : best) is to convert the dates to julian days, find all of the Sundays : spanning the dates in the series, then do something along the lines of: : : tapply(the.log.returns, cut(julian.days, sundays), sum) : : Patrick Burns : : Burns Statistics : patrick at burns-stat.com : +44 (0)20 8525 0696 : http://www.burns-stat.com : (home of S Poetry and A Guide for the Unwilling S User) : : Ajay Shah wrote: : : S-Plus has the function AggregateSeries() whose name is self : explanatory. For instance one can derive monthly series from daily : ones by specifying end-of-period, averages, sums, etc. I looked for a : similar function in the packages its and tseries, but found : nothing. I also help.searched() for aggregate to no avail. Would : anybody be so kind to point me in the right direction? : : : : I once needed a function which would convert daily stock prices into : weekly returns. I know, the code is pretty bad (it is all loops and : it's very slow), but my knowledge of R is weak and I really needed it, : so I just used brute force. See EOF for the function. Gabor and Dirk : and Brian Ripley and others on the list were very helpful to me in : getting to the point where I could write this, though obviously they : should not be blamed for my bad code! : : I would be very happy if listers could give me ideas on how to do this : better. : : Daily to monthly is innately easier since months are 'more normal' than : weeks. I have perl code which does this, which supports 2 cases: : Reporting the last traded price (LTP) of the month versus reporting the : average of the month. If this is useful to you, ask me. : : What are the specialised
[R] help with the usage of randomForest
Dear all, Can anybody give me some hint on the following error msg I got with using randomForest? I have two-class classification problem. The data file sample is: -- udomain.edu udomain.hcs hpclass 1 1. 1 not 2 NA 2 not 3 NA 0.8 not 4 NA 0.2 hp 5 NA 0.9 hp The steps I called the function are: (1) Read data hp - read.table(sample) (2) Call randomForest hp.rf - randomForest(hpclass ~., yy, data=hp, importance=TRUE, proximity=TRUE) But the error msg I got is: Error in randomForest.default(m, y, ...) : Need at least two classes to do classification. I learned the usage of randomForest from: http://www.maths.lth.se/help/R/.R/library/randomForest/html/randomForest.html Thanks a lot for any of your comments in advance! Hui Han Department of Computer Science and Engineering, The Pennsylvania State University University Park, PA,16802 email: [EMAIL PROTECTED] homepage: http://www.cse.psu.edu/~hhan __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Gabor Grothendieck wrote: If you are willing to do it yourself you can define a class for which indexing behaves that way. I'd like to prefix all these solutions with Here's how to do it, but don't actually do it you crazy fool. It's on a par with redefining pi, or redefining '+'. And then redefining '-'. These techniques have their proper place, and that would be in the currently non-existent obfuscated R contest. No, the R-ish (iRish?) way is to index vectors from 1. That's what the R gods intended! Baz __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Failure to compile source packages in Debian
On Wed, Mar 31, 2004 at 09:15:24AM +0200, F. Tusell wrote: As of quite recently I experience failures to compile source packages. Messages like * Installing *source* package 'dse1' ... ** libs g77 -mieee-fp -fPIC -g -O2 -c dsefor.f -o dsefor.o gcc -shared -o dse1.so dsefor.o -L/usr/lib/gcc-lib/i486-linux/3.3.3 -L/usr/lib/gcc-lib/i486-linux/3.3.3/../../.. -lfrtbegin -lg2c-pic -lm -lgcc_s -L/usr/lib/R/bin -lR /usr/bin/ld: no se puede encontrar -lg2c-pic clearly point to the non-existence of library g2c-pic. Problem is I cannot locate the .deb package containing such library. Could some Debian user point me to the right location? (I am using Debian testing on a Pentium box and R ver. 1.8.1 installed from the .deb package.) The g77 packages used to provide a g2c-pic library. E.g. when 1.8.1 was built, they did and thusly the Depends ended up in /etc/R/Makeconf. However, on your current system, g77 no longer provides the library -- so this fails. You need to bring R and g77 back in sync. There are several possibilities: a) install the current r-base-core and r-base-dev packages from unstable b) recompile the 1.8.1 package locally to reflect to reflect your current compiler setup c) edit /etc/R/Makeconf I'm sorry for the bug, but these things are hard to control for. Dirk -- The relationship between the computed price and reality is as yet unknown. -- From the pac(8) manual page __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Removing leading and trailing spaces (string manipulation)
Hi all, I'm running the following code to generate 40 different jpegs based on the resulting data. I'd like the file names to be 'Cluster1.jpeg', however the code write filenames like 'Cluster 1 .jpeg'. How can I get rid of the unwanted spaces? I've looked at ?format and it doesn't seem to work - at least in this context. ### ClusCount - 40 datain - as.data.frame( read.csv(c:\\daclus.csv)) for(i in 1:ClusCount){ mapit - subset(datain, cluster == i) jpeg(file=paste(c:\\temp\\cluster,format(i),.jpeg), width = 640, height = 480, pointsize = 12,quality = 300, bg = white) plot( as.matrix(mapit[,2]), as.matrix(mapit[,3]),xlim=c(-141.6,-52.1),ylim=c(41.5,83.7), type = p, main = paste(Cluster,i) ) dev.off() } ### Thanks, Danny __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] identify() and controlling label size
I thought this was going to be easy ... Can the label size of identify() be controlled by setting par(cex.*) because I'm having no luck? My only recourse is to save the index and position of the labels from identify() and use text() to replot them. Regards Alex Alex Hanke Department of Fisheries and Oceans St. Andrews Biological Station 531 Brandy Cove Road St. Andrews, NB Canada E5B 2L9 [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Removing leading and trailing spaces (string manipulation)
Danny, Paste uses sep= between arguments as a default. Just include sep= in the paste call. file=paste(c:\\temp\\cluster,format(i),.jpeg,sep=) Sean On 3/31/04 9:44 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi all, I'm running the following code to generate 40 different jpegs based on the resulting data. I'd like the file names to be 'Cluster1.jpeg', however the code write filenames like 'Cluster 1 .jpeg'. How can I get rid of the unwanted spaces? I've looked at ?format and it doesn't seem to work - at least in this context. ### ClusCount - 40 datain - as.data.frame( read.csv(c:\\daclus.csv)) for(i in 1:ClusCount){ mapit - subset(datain, cluster == i) jpeg(file=paste(c:\\temp\\cluster,format(i),.jpeg), width = 640, height = 480, pointsize = 12,quality = 300, bg = white) plot( as.matrix(mapit[,2]), as.matrix(mapit[,3]),xlim=c(-141.6,-52.1),ylim=c(41.5,83.7), type = p, main = paste(Cluster,i) ) dev.off() } ### Thanks, Danny __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] extracting values from a 3d array using a matrix from indices
Suppose I have A, an n x m matrix, each element is an integer (an index). I also have B, an n x l x m array. I need C, where C[n,m] = B[n, A[n, m], m] I am currently using loops, what would be the R way to do this? Another question: let A[n, m] - argmax_l B[n, l, m] what would be the nicest way of doing this? Currently I am using max.col and a single loop, going though the n's. Background: I solving a discrete-space dynamic programming problem, A is the optimal policy, C is the value function. The structure of the problem allows me to use matrices like above, instead of (n * m) x (n x m) square matrices. Thanks Tamas -- Tamás K. Papp E-mail: [EMAIL PROTECTED] (preferred, especially for large messages) [EMAIL PROTECTED] Please try to send only (latin-2) plain text, not HTML or other garbage. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] identify() and controlling label size
Hanke, Alex wrote: I thought this was going to be easy ... Can the label size of identify() be controlled by setting par(cex.*) because I'm having no luck? My only recourse is to save the index and position of the labels from identify() and use text() to replot them. Funny, it seems to ignore that, but allows 'col=' and 'font=' to set the font colour and type. But! It accepts 'ps=' to set the point size! You may be saved... Try: plot(1:10) identify(1:10,ps=24) identify(1:10,ps=12) Baz __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Removing leading and trailing spaces (string manipulation)
I believe all you need to do here is use plain i instead of format(i) in the jpeg call. Someone is bound to come up with a better generic answer but this should get you up and running for now. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 31 March 2004 15:44 To: [EMAIL PROTECTED] Subject: [R] Removing leading and trailing spaces (string manipulation) Security Warning: If you are not sure an attachment is safe to open contact Andy on x234. There are 0 attachments with this message. Hi all, I'm running the following code to generate 40 different jpegs based on the resulting data. I'd like the file names to be 'Cluster1.jpeg', however the code write filenames like 'Cluster 1 .jpeg'. How can I get rid of the unwanted spaces? I've looked at ?format and it doesn't seem to work - at least in this context. ### ClusCount - 40 datain - as.data.frame( read.csv(c:\\daclus.csv)) for(i in 1:ClusCount){ mapit - subset(datain, cluster == i) jpeg(file=paste(c:\\temp\\cluster,format(i),.jpeg), width = 640, height = 480, pointsize = 12,quality = 300, bg = white) plot( as.matrix(mapit[,2]), as.matrix(mapit[,3]),xlim=c(-141.6,-52.1),ylim=c(41.5,83.7), type = p, main = paste(Cluster,i) ) dev.off() } ### Thanks, Danny __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 69 Fax: +44 (0) 1379 65 email: [EMAIL PROTECTED] web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Removing leading and trailing spaces (string manipulation)
On Wed, 2004-03-31 at 08:44, [EMAIL PROTECTED] wrote: Hi all, I'm running the following code to generate 40 different jpegs based on the resulting data. I'd like the file names to be 'Cluster1.jpeg', however the code write filenames like 'Cluster 1 .jpeg'. How can I get rid of the unwanted spaces? I've looked at ?format and it doesn't seem to work - at least in this context. ### ClusCount - 40 datain - as.data.frame( read.csv(c:\\daclus.csv)) for(i in 1:ClusCount){ mapit - subset(datain, cluster == i) jpeg(file=paste(c:\\temp\\cluster,format(i),.jpeg), width = 640, height = 480, pointsize = 12,quality = 300, bg = white) plot( as.matrix(mapit[,2]), as.matrix(mapit[,3]),xlim=c(-141.6,-52.1),ylim=c(41.5,83.7), type = p, main = paste(Cluster,i) ) dev.off() } ### Thanks, Danny Change the code in your 'jpeg' statement to read: jpeg(file=paste(c:\\temp\\cluster,format(i),.jpeg, sep = ), ... You can use the 'sep' argument (which defaults to ) to eliminate the spaces between the pasted components. See ?paste for more information. HTH, Marc Schwartz __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Removing leading and trailing spaces (string manipulation)
Thanks to Marc, J.R. and Sean for your help. I didn't realize that the paste command was where I should be looking. Danny __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] array addition doesn't recycle!
Hi, I have noticed the following: a - array(1:4, c(2, 2)) A - array(1:4, c(2,2,2)) A + a Error in A + a : non-conformable arrays It works with a matrix + a vector, why doesn't it work with arrays? Am I missing something? How would you do the above operation efficiently (ie I need to add a matrix to each plane of 3-dim array)? At the moment I am using something like A + array(a, c(2,2,2)) but it doesn't seem that efficient. Thanks Tamas -- Tamás K. Papp E-mail: [EMAIL PROTECTED] (preferred, especially for large messages) [EMAIL PROTECTED] Please try to send only (latin-2) plain text, not HTML or other garbage. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Please confirm your subscription.
Hi , It's 'I DESIRE' Success writing you to confirm your subscription to our mailing list. You can confirm your subscription by simply clicking the link below: https://www.mcssl.com/app/optin.asp?j=0c=18836264pg=dasnc=1 If you received this message in error, or do not wish to be included in future mailings, you do not have to do anything Simply, delete the message and your information will be removed by our system automatically. You can contact us at [EMAIL PROTECTED], for more information on our service. Regards, 'I DESIRE' Success __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] help with the usage of randomForest
Thanks for Matt and Torsten for very helpful suggestions! As Matt pointed out, the problem is that na.action has the default value of na.fail, that deleted one class samples. I changed all NAs to real values, and the error msg. dissappeared. However my real dataset contains many NAs. I wonder if anybody can point me any documentations on how to define na.action not be na.fail? Best regards, Hui On Wed, Mar 31, 2004 at 06:26:36PM +0200, Torsten Hothorn wrote: On Wed, 31 Mar 2004, Hui Han wrote: Dear all, Can anybody give me some hint on the following error msg I got with using randomForest? I have two-class classification problem. The data file sample is: -- udomain.edu udomain.hcs hpclass 1 1. 1 not 2 NA 2 not 3 NA 0.8 not 4 NA 0.2 hp 5 NA 0.9 hp The steps I called the function are: (1) Read data hp - read.table(sample) most probably a problem here. say R summary(hp) and check if the factor `hpclass' has two levels. Torsten (2) Call randomForest hp.rf - randomForest(hpclass ~., yy, data=hp, importance=TRUE, proximity=TRUE) But the error msg I got is: Error in randomForest.default(m, y, ...) : Need at least two classes to do classification. I learned the usage of randomForest from: http://www.maths.lth.se/help/R/.R/library/randomForest/html/randomForest.html Thanks a lot for any of your comments in advance! Hui Han Department of Computer Science and Engineering, The Pennsylvania State University University Park, PA,16802 email: [EMAIL PROTECTED] homepage: http://www.cse.psu.edu/~hhan __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Hui Han Department of Computer Science and Engineering, The Pennsylvania State University University Park, PA,16802 email: [EMAIL PROTECTED] homepage: http://www.cse.psu.edu/~hhan __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] (no subject)
Hi, I wonder if you can help me: I cannot seem to be able to import my data anymore. When I try to import the attached file with the string FunctRes-read.table(C:/Documents and Settings/FunctRes.txt, header=FALSE) I obtain: FunctRes V1 1 ÿþC 2 \n 3C 40 50 6B 7 \n 8C 90 10 1 11 B 12 \n 13 C 14 0 15 0 16 B 17 \n 18 C 19 0 20 1 21 B 22 \n 23 C 24 0 25 1 26 B 27 \n 28 C 29 0 30 1 31 B Can you help me? Thanks Nicole Dr Nicole Soranzo Centre for Population Genetics and Human Health University College London Darwin Building Gower Street London WC1E 6BT Tel: +44 (0)20 7679 4397 Fax: +44 (0)20 7679 2887 E-mail: [EMAIL PROTECTED] http://popgen.biol.ucl.ac.uk/ ÿþC E P H 0 . 0 0 7 8 1 2 5 1 B C E P H 0 . 0 0 7 8 1 2 5 1 B C E P H 0 . 0 0 7 8 1 2 5 0 . 0 2 0 5 1 7 B C E P H 0 . 0 0 7 8 1 2 5 0 . 0 3 1 4 7 9 B C E P H 0 . 0 0 7 8 1 2 5 1 B C E P H 0 . 0 0 7 8 1 2 5 0 . 1 4 6 3 1 B C E P H 0 . 0 0 7 8 1 2 5 1 B C E P H 0 . 0 0 7 8 1 2 5 1 B C E P H 0 . 0 0 7 8 1 2 5 1 B __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] help with the usage of randomForest
Thinking that the following suggestions by Matt may be helpful to others, I am fowarding his notes to R-list. Regards, Hui On Wed, Mar 31, 2004 at 08:57:13AM -0800, Austin, Matt wrote: Use na.action=na.omit in your function call to delete those rows, but this can give you problems if you want to use follow-up methods such as the partial.plot(). This is what I usually do: naRows - apply(data2, 1, function(x) any(is.na(x))) sum(!(naRows)) data2.noNAs - data2[!naRows,] chg.rf - randomForest(ch13 ~ .,data=data2.noNAs, importance=TRUE, keep.forest=TRUE) That way when I call partial.plot() like in the following example I don't run into trouble with NAs in the original dataset not matching with what was used in the random forest fit. postscript(temp.ps, horizontal=TRUE) par(mfrow=c(4,4)) for(i in 1:length(varNames)){ partial.plot(chg.f, data2.noNAs, varNames[i], ylim=c(.95, 1.7)) } dev.off() -Original Message- From: Hui Han [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 31, 2004 8:12 AM To: Austin, Matt Subject: Re: [R] help with the usage of randomForest Matt, I appreciate your help so much!! Yes, I changed all NAs to real values, and the error msg. disappeared. However my real dataset contains many NAs. Can you give me more suggestions on how to define na.action not be na.fail? Thank you so much again, Hui On Wed, Mar 31, 2004 at 08:02:47AM -0800, Austin, Matt wrote: What is yy? Is this your subset index? If so make sure that you are not removing all of one class. Note that the default na.action in randomForest is na.fail, so even if your subsetting isn't removing all of the rows with an NA the method should still fail. --Matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Hui Han Sent: Wednesday, March 31, 2004 6:11 AM To: [EMAIL PROTECTED] Subject: [R] help with the usage of randomForest Dear all, Can anybody give me some hint on the following error msg I got with using randomForest? I have two-class classification problem. The data file sample is: -- udomain.edu udomain.hcs hpclass 1 1. 1 not 2 NA 2 not 3 NA 0.8 not 4 NA 0.2 hp 5 NA 0.9 hp The steps I called the function are: (1) Read data hp - read.table(sample) (2) Call randomForest hp.rf - randomForest(hpclass ~., yy, data=hp, importance=TRUE, proximity=TRUE) But the error msg I got is: Error in randomForest.default(m, y, ...) : Need at least two classes to do classification. I learned the usage of randomForest from: http://www.maths.lth.se/help/R/.R/library/randomForest/html/randomForest.htm l Thanks a lot for any of your comments in advance! Hui Han Department of Computer Science and Engineering, The Pennsylvania State University University Park, PA,16802 email: [EMAIL PROTECTED] homepage: http://www.cse.psu.edu/~hhan __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Hui Han Department of Computer Science and Engineering, The Pennsylvania State University University Park, PA,16802 email: [EMAIL PROTECTED] homepage: http://www.cse.psu.edu/~hhan Hui Han Department of Computer Science and Engineering, The Pennsylvania State University University Park, PA,16802 email: [EMAIL PROTECTED] homepage: http://www.cse.psu.edu/~hhan __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (no subject)
Nicole Soranzo [EMAIL PROTECTED] writes: I cannot seem to be able to import my data anymore. When I try to import the attached file with the string FunctRes-read.table(C:/Documents and Settings/FunctRes.txt, header=FALSE) I obtain: FunctRes V1 1 ÿþC ... Can you help me? Something is wrong with your file (16-bit encoding?) I see almost every 2nd character coded as ^@ (ASCII NUL). This is the string terminator and so has antisocial consequences if it finds its way into the middle of a character string. You need to get rid of those somehow. ÿþC -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] scan seems to modify the data
Hello list, I have used scan function to import data into R. I have done some analysis and find strange results. I have found my problem : when importing data with scan, this can slightly modify the data : write(c(0.251,3.399,-0.481,0.266),essai.txt) scan(essai.txt) Read 4 items [1] 0.251 3.399 -0.481 0.266 print(scan(essai.txt),17) Read 4 items [1] 0.25100 3.39900 -0.48098 0.26601 Is it normal ? Is it a bug ? thanks in advance, Sincerely. version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major1 minor8.1 year 2003 month11 day 21 language R Stéphane DRAY -- Département des Sciences Biologiques Université de Montréal, C.P. 6128, succursale centre-ville Montréal, Québec H3C 3J7, Canada Tel : 514 343 6111 poste 1233 E-mail : [EMAIL PROTECTED] -- Web http://www.steph280.freesurf.fr/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (no subject)
On 31 Mar 2004 19:22:30 +0200, Peter Dalgaard [EMAIL PROTECTED] wrote : Nicole Soranzo [EMAIL PROTECTED] writes: I cannot seem to be able to import my data anymore. When I try to import the attached file with the string FunctRes-read.table(C:/Documents and Settings/FunctRes.txt, header=FALSE) I obtain: FunctRes V1 1 ÿþC ... Can you help me? Something is wrong with your file (16-bit encoding?) I see almost every 2nd character coded as ^@ (ASCII NUL). My text editor identifies it as a Unicode file. R wants plain ascii. Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] help with the usage of randomForest
Hui Han [EMAIL PROTECTED] writes: Thinking that the following suggestions by Matt may be helpful to others, I am fowarding his notes to R-list. Did you ask for permission? You really should. On Wed, Mar 31, 2004 at 08:57:13AM -0800, Austin, Matt wrote: Use na.action=na.omit in your function call to delete those rows, but this can give you problems if you want to use follow-up methods such as the partial.plot(). This is what I usually do: naRows - apply(data2, 1, function(x) any(is.na(x))) sum(!(naRows)) data2.noNAs - data2[!naRows,] chg.rf - randomForest(ch13 ~ .,data=data2.noNAs, importance=TRUE, keep.forest=TRUE) Actually, data2.noNAs - na.omit(data2) will do the trick and !naRows is the same as complete.cases(data2). -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] scan seems to modify the data
On Wed, 31 Mar 2004 12:24:38 -0500, Stephane DRAY [EMAIL PROTECTED] wrote : Hello list, I have used scan function to import data into R. I have done some analysis and find strange results. I have found my problem : when importing data with scan, this can slightly modify the data : write(c(0.251,3.399,-0.481,0.266),essai.txt) scan(essai.txt) Read 4 items [1] 0.251 3.399 -0.481 0.266 print(scan(essai.txt),17) Read 4 items [1] 0.25100 3.39900 -0.48098 0.26601 Is it normal ? Is it a bug ? I think it's normal. Floating point formats aren't exact except for fractions with only powers of 2 in the denominator. There is no way to represent any of your values in the formats that R uses without slight errors. I do notice one oddity in the print routines in R: x-scan() 1: 0.266 2: 0.251 3: Read 2 items print(x,17) [1] 0.26601 0.25100 x-scan() 1: 0.266 2: Read 1 items print(x,17) [1] 0.266 I don't know why the second print() prints 0.266 differently from the first one. (This is in the 1.9.0 beta in Windows). Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] (kein Betreff)
Dear colleagues! How can I calculate the mean of every line of feld without using the command for? Thank You in advance feld-array(,c(100,10)) mittel-array(,c(100,1)) feld[,]-rnorm(1000) for(a in 1:100){mittel[a]-mean(feld[a,])} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] scan seems to modify the data
Duncan Murdoch [EMAIL PROTECTED] writes: print(x,17) [1] 0.26601 0.25100 ... print(x,17) [1] 0.266 I don't know why the second print() prints 0.266 differently from the first one. (This is in the 1.9.0 beta in Windows). To get the same number of decimals as the other guy. The interesting question is why 0.251 gets all those trailing zeros: print(0.251,17) [1] 0.25100 print(0.253,17) [1] 0.25300 print(0.255,17) [1] 0.255 -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] scan seems to modify the data
On Wed, 31 Mar 2004, Duncan Murdoch wrote: On Wed, 31 Mar 2004 12:24:38 -0500, Stephane DRAY [EMAIL PROTECTED] wrote : Hello list, I have used scan function to import data into R. I have done some analysis and find strange results. I have found my problem : when importing data with scan, this can slightly modify the data : write(c(0.251,3.399,-0.481,0.266),essai.txt) scan(essai.txt) Read 4 items [1] 0.251 3.399 -0.481 0.266 print(scan(essai.txt),17) Read 4 items [1] 0.25100 3.39900 -0.48098 0.26601 Is it normal ? Is it a bug ? I think it's normal. Floating point formats aren't exact except for fractions with only powers of 2 in the denominator. There is no way to represent any of your values in the formats that R uses without slight errors. I do notice one oddity in the print routines in R: x-scan() 1: 0.266 2: 0.251 3: Read 2 items print(x,17) [1] 0.26601 0.25100 x-scan() 1: 0.266 2: Read 1 items print(x,17) [1] 0.266 I don't know why the second print() prints 0.266 differently from the first one. (This is in the 1.9.0 beta in Windows). Because the precision applies to the smallest of the numbers. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (kein Betreff)
Mag. Ferri Leberl wrote: Dear colleagues! How can I calculate the mean of every line of feld without using the command for? Thank You in advance feld-array(,c(100,10)) mittel-array(,c(100,1)) feld[,]-rnorm(1000) for(a in 1:100){mittel[a]-mean(feld[a,])} (please use an informative subject) See ?rowMeans mittel - rowMeans(feld) -sd __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (kein Betreff)
On Wed, 2004-03-31 at 19:01, Mag. Ferri Leberl wrote: Dear colleagues! How can I calculate the mean of every line of feld without using the command for? Thank You in advance feld-array(,c(100,10)) mittel-array(,c(100,1)) feld[,]-rnorm(1000) for(a in 1:100){mittel[a]-mean(feld[a,])} You could use: mittel - apply(feld, 1, mean) prodrigues __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] ARCH GARCH
i'm looking for an R library dealing with ARCH and GARCH models __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] scan seems to modify the data
On 31 Mar 2004, Peter Dalgaard wrote: Duncan Murdoch [EMAIL PROTECTED] writes: print(x,17) [1] 0.26601 0.25100 ... print(x,17) [1] 0.266 I don't know why the second print() prints 0.266 differently from the first one. (This is in the 1.9.0 beta in Windows). To get the same number of decimals as the other guy. The interesting question is why 0.251 gets all those trailing zeros: print(0.251,17) [1] 0.25100 print(0.253,17) [1] 0.25300 print(0.255,17) [1] 0.255 Take a look at formatReal. scientific thinks 0.251 has 17 digits and 0.255 has 3. It really doesn't make any sense to ask for more precision than you have (.Machine$double.eps) and you do often get spurious errors if you attempt to do so. So 15 digits is normally safe, but no more. Note that there are decimal - binary - decimal conversions and you can't say which one introduced the small changes. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] array addition doesn't recycle!
Another alternative is to use the underappreciated function 'sweep()': sweep(A, 1:2, a, +) Internally this is about the same as your 'A + array(a, c(2,2,2))'. But it has the advantage that it makes explicit what the relationship between the dimensions of 'A' and 'a' is. I find that relying on implicit recycling tends to produce errors that are hard to trace, and code that is hard to understand six months later. Rich Raubertas Merck Co. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian Ripley Sent: Wednesday, March 31, 2004 10:00 AM To: Tamas Papp Cc: R-help mailing list Subject: Re: [R] array addition doesn't recycle! The recycling rules are documented and this is not amongst them. Computer packages do have a tendency to follow their rules rather than read your mind. I suspect A + as.vector(a) is what you intended. On Wed, 31 Mar 2004, Tamas Papp wrote: Hi, I have noticed the following: a - array(1:4, c(2, 2)) A - array(1:4, c(2,2,2)) A + a Error in A + a : non-conformable arrays It works with a matrix + a vector, why doesn't it work with arrays? Am I missing something? How would you do the above operation efficiently (ie I need to add a matrix to each plane of 3-dim array)? At the moment I am using something like A + array(a, c(2,2,2)) but it doesn't seem that efficient. Why do you think is `not that efficient'? Does you have a need to save microseconds? -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] scan seems to modify the data
At 13:34 31/03/2004, Prof Brian Ripley wrote: Take a look at formatReal. scientific thinks 0.251 has 17 digits and 0.255 has 3. It really doesn't make any sense to ask for more precision than you have (.Machine$double.eps) and you do often get spurious errors if you attempt to do so. So 15 digits is normally safe, but no more. Note that there are decimal - binary - decimal conversions and you can't say which one introduced the small changes. I completely agree with you. My problem arise when I try to compute a correlation. One of the variable seems to have equal values but it does not. Hence, it has a very low variance and so when I try to compute the correlation with another variable, this correlation is very high. I wonder if it would not be good to introduce a tolerance threshold. Is it meaningful to produce correlation when a variance is very low ? See the example below : essai=matrix(c(0.266,.234,.005,.481,.1,.009,.4,.155,.255,.2,.34,.43),4,3) essai2=sweep(essai,2,apply(essai,2,sum),/) x=coef(lm(essai2~scale(runif(4 x [,1] [,2] [,3] (Intercept) 0.2500 0.250 0.2500 scale(runif(4)) 0.05307906 0.1330111 0.06936634 cor(x[1,],runif(3)) [1] 0.932772 var(x) [,1][,2] [,3] [1,] 0.01938893 0.011518783 0.01778528 [2,] 0.01151878 0.006843202 0.01056607 [3,] 0.01778528 0.010566067 0.01631426 var(x[1,]) [1] 1.92593e-33 Obviously, I can introduce this threshold, but I wonder if 15 digits is always a good limit to avoid this kind of problems cor(round(x[1,],15),runif(3)) [1] NA Warning message: The standard deviation is zero in: cor(x, y, na.method, method == kendall) Thanks a lot to all, Stéphane DRAY -- Département des Sciences Biologiques Université de Montréal, C.P. 6128, succursale centre-ville Montréal, Québec H3C 3J7, Canada Tel : 514 343 6111 poste 1233 E-mail : [EMAIL PROTECTED] -- Web http://www.steph280.freesurf.fr/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] scan seems to modify the data
Note, digits in print() corresponds to signif and not to round. You need to input some knowledge about your problem to call such issues. On Wed, 31 Mar 2004, Stephane DRAY wrote: At 13:34 31/03/2004, Prof Brian Ripley wrote: Take a look at formatReal. scientific thinks 0.251 has 17 digits and 0.255 has 3. It really doesn't make any sense to ask for more precision than you have (.Machine$double.eps) and you do often get spurious errors if you attempt to do so. So 15 digits is normally safe, but no more. Note that there are decimal - binary - decimal conversions and you can't say which one introduced the small changes. I completely agree with you. My problem arise when I try to compute a correlation. One of the variable seems to have equal values but it does not. Hence, it has a very low variance and so when I try to compute the correlation with another variable, this correlation is very high. I wonder if it would not be good to introduce a tolerance threshold. Is it meaningful to produce correlation when a variance is very low ? See the example below : essai=matrix(c(0.266,.234,.005,.481,.1,.009,.4,.155,.255,.2,.34,.43),4,3) essai2=sweep(essai,2,apply(essai,2,sum),/) x=coef(lm(essai2~scale(runif(4 x [,1] [,2] [,3] (Intercept) 0.2500 0.250 0.2500 scale(runif(4)) 0.05307906 0.1330111 0.06936634 cor(x[1,],runif(3)) [1] 0.932772 var(x) [,1][,2] [,3] [1,] 0.01938893 0.011518783 0.01778528 [2,] 0.01151878 0.006843202 0.01056607 [3,] 0.01778528 0.010566067 0.01631426 var(x[1,]) [1] 1.92593e-33 Obviously, I can introduce this threshold, but I wonder if 15 digits is always a good limit to avoid this kind of problems cor(round(x[1,],15),runif(3)) [1] NA Warning message: The standard deviation is zero in: cor(x, y, na.method, method == kendall) Thanks a lot to all, Stéphane DRAY -- Département des Sciences Biologiques Université de Montréal, C.P. 6128, succursale centre-ville Montréal, Québec H3C 3J7, Canada Tel : 514 343 6111 poste 1233 E-mail : [EMAIL PROTECTED] -- Web http://www.steph280.freesurf.fr/ -- -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] classification with nnet: handling unequal class sizes
Dear Prof. Ripley Since you are the creator of the MASS library I dare to ask you a short question, for which I didn't get an answer from the R mailing-list. If you feel disturbed by my question, please forgive me and just ignore my mail. I use the nnet code from your book, VR p. 348: The very nice and general function CVnn2() to choose the number of hidden units and the amount of weight decay by an inner cross-validation- with a slight modification to use it for classification (see below). My data has 2 classes with unequal size: 45 observations for classI and 116 obs. for classII (number of variables: 39) With CVnn2 I get the following confusion matrix (%) (average of 10 runs): predicted true53 47 16 84 I had a similar biased confusion matrix with randomForest until I used the sampsize argument (the same holds for svm until I used the class.weights argument). How can I handle this problem of unequal class sizes with nnet, in order to get a less biased confusion matrix? (with randomForest I finally got 78 22 16 84 ) many thanks for a hint. By the way, I just want to say 'thank you' for your great MASS book. Since your first recommendation, I consult it quite frequently. Christoph #--- neural networks #classification network is constructed; this has one output and entropy fit if the number of levels is two, and a number of outputs equal to the number of classes and a softmax output stage for more levels. - therefore two lines of Prof. Ripley's wrapper function are changed below (original commented out) and an additional function has been introduced (resmatrix) con - function(...) { print(tab - table(...)) diag(tab) - 0 cat(error rate = , round(100*sum(tab)/length(list(...)[[1]]), 2), %\n) invisible() } CVnn2 - function(formula, data, size = c(0,4,4,10,10), lambda = c(0, rep(c(0.001, 0.01),2)), nreps = 1, nifold = 5, verbose = 99, ...) { resmatrix - function(predict.matrix,learn, data, ri, i) { rae.matrix - predict.matrix rae.matrix[,] - 0 rae.vector - as.numeric(as.factor((predict(learn, data[ri == i,], type = class for (k in 1:dim(rae.matrix)[1]) { if (rae.vector[k] == 1) rae.matrix[k,1] - rae.matrix[k,1] + 1 else rae.matrix[k,2] - rae.matrix[k,2] + 1 } rae.matrix } CVnn1 - function(formula, data, nreps=1, ri, verbose, ...) { totalerror - 0 truth - data[,deparse(formula[[2]])] res - matrix(0, nrow(data), length(levels(truth))) if(verbose 20) cat( inner fold) for (i in sort(unique(ri))) { if(verbose 20) cat( , i, sep=) for(rep in 1:nreps) { learn - nnet(formula, data[ri !=i,], trace = F, ...) #res[ri == i,] - res[ri == i,] + predict(learn, data[ri == i,]) res[ri == i,] - res[ri == i,] + resmatrix(res[ri == i,],learn,data, ri, i) } } if(verbose 20) cat(\n) sum(as.numeric(truth) != max.col(res/nreps)) } truth - data[,deparse(formula[[2]])] res - matrix(0, nrow(data), length(levels(truth))) choice - numeric(length(lambda)) for (i in sort(unique(rand))) { if(verbose 0) cat(fold , i,\n, sep=) ri - sample(nifold, sum(rand!=i), replace=T) for(j in seq(along=lambda)) { if(verbose 10) cat( size =, size[j], decay =, lambda[j], \n) choice[j] - CVnn1(formula, data[rand != i,], nreps=nreps, ri=ri, size=size[j], decay=lambda[j], verbose=verbose, ...) } decay - lambda[which.is.max(-choice)] csize - size[which.is.max(-choice)] if(verbose 5) cat( #errors:, choice, ) # if(verbose 1) cat(chosen size = , csize, decay = , decay, \n, sep=) for(rep in 1:nreps) { learn - nnet(formula, data[rand != i,], trace=F, size=csize, decay=decay, ...) #res[rand == i,] - res[rand == i,] + predict(learn, data[rand == i,]) res[rand == i,] - res[rand == i,] + resmatrix(res[rand == i,],learn,data, rand, i) } } factor(levels(truth)[max.col(res/nreps)], levels = levels(truth)) } -- Christoph Lehmann [EMAIL PROTECTED] -- Christoph LehmannPhone: ++41 31 930 93 83 Department of Psychiatric NeurophysiologyMobile: ++41 76 570 28 00 University Hospital of Clinical Psychiatry Fax:++41 31 930 99 61 Waldau[EMAIL PROTECTED] CH-3000 Bern 60 http://www.puk.unibe.ch/cl/pn_ni_cv_cl_03.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do
RE: [R] help with the usage of randomForest
As you've learned, using the formula interface, the NAs are handled by na.action. (BTW, the R default is na.omit, so the NAs are silently omitted. If it were na.fail, you would have gotten an error message.) There are several options on handling NAs, na.omit being one of them. If you have too many NAs, omitting them would leave you too little data, as you experienced. One possibility is to use na.roughfix (in the randomForest package) as na.action, which replaces the NAs with the median of the variable (or the mode for factor variable). If you want to, you can use rfImpute to use randomForest itself to impute NAs (assuming your training data isn't terribly big). HTH, Andy From: Hui Han Thanks for Matt and Torsten for very helpful suggestions! As Matt pointed out, the problem is that na.action has the default value of na.fail, that deleted one class samples. I changed all NAs to real values, and the error msg. dissappeared. However my real dataset contains many NAs. I wonder if anybody can point me any documentations on how to define na.action not be na.fail? Best regards, Hui On Wed, Mar 31, 2004 at 06:26:36PM +0200, Torsten Hothorn wrote: On Wed, 31 Mar 2004, Hui Han wrote: Dear all, Can anybody give me some hint on the following error msg I got with using randomForest? I have two-class classification problem. The data file sample is: -- udomain.edu udomain.hcs hpclass 1 1. 1 not 2 NA 2 not 3 NA 0.8 not 4 NA 0.2 hp 5 NA 0.9 hp The steps I called the function are: (1) Read data hp - read.table(sample) most probably a problem here. say R summary(hp) and check if the factor `hpclass' has two levels. Torsten (2) Call randomForest hp.rf - randomForest(hpclass ~., yy, data=hp, importance=TRUE, proximity=TRUE) But the error msg I got is: Error in randomForest.default(m, y, ...) : Need at least two classes to do classification. I learned the usage of randomForest from: http://www.maths.lth.se/help/R/.R/library/randomForest/html/ra ndomForest.html Thanks a lot for any of your comments in advance! Hui Han Department of Computer Science and Engineering, The Pennsylvania State University University Park, PA,16802 email: [EMAIL PROTECTED] homepage: http://www.cse.psu.edu/~hhan __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Hui Han Department of Computer Science and Engineering, The Pennsylvania State University University Park, PA,16802 email: [EMAIL PROTECTED] homepage: http://www.cse.psu.edu/~hhan __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] extracting values from a 3d array using a matrix from indices
1. Create a matrix A.list each of whose i,j-th entries is a one element list containing A[i,,j]. Note that A.list and B have the same lengths so we can use mapply. With mapply, we can choose the B[k]-th element from the list represented by A.list[k]. Finally reshape. # test data A - array(1:8,c(2,2,2)) B - matrix(c(1,2,2,1),2) # solution A.list - apply(A,c(1,3),function(x)list(x)) C - mapply(A.list,B,FUN=function(x,y)unlist(x)[y]) C - matrix(C,nrow(A)) # compare to loop solution C.loop - matrix(NA,2,2) for(i in 1:2)for(j in 1:2) C.loop[i,j] - A[i,B[i,j],j] identical(C,C.loop) # TRUE 2. The second problem can also be handled with the same A.list in a similar way: C - sapply(A.list,function(x)which.max(unlist(x))) C - matrix(C,nrow(A)) Tamas Papp tpapp at axelero.hu writes: : Suppose I have A, an n x m matrix, each element is an integer (an : index). : : I also have B, an n x l x m array. I need C, where : : C[n,m] = B[n, A[n, m], m] : : I am currently using loops, what would be the R way to do this? : : Another question: let : : A[n, m] - argmax_l B[n, l, m] : : what would be the nicest way of doing this? Currently I am using : max.col and a single loop, going though the n's. : : Background: I solving a discrete-space dynamic programming problem, A : is the optimal policy, C is the value function. The structure of the : problem allows me to use matrices like above, instead of (n * m) x (n : x m) square matrices. : : Thanks : : Tamas : __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Zero Index Origin?
Dear Baz, I'm inclined to believe that your general advice is correct. As a long-time APLer who came to R through Lisp-Stat, I think that it's generally a good idea not to resist the most natural way of programming in R. On the other hand, introducing a new class and defining methods for it (such as a method for indexing) doesn't disturb standard methods, as your message seems to imply. Indeed, the ability to do these kinds of things is in my view one of the strengths of R (and S more generally). Of course, it is necessary to implement the new class carefully. Whether it is worth the trouble to have a class that accommodates zero-origin indexing seems to me to depend upon the application. I've never myself encountered an application where this was really desirable. Regards, John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Barry Rowlingson Sent: Wednesday, March 31, 2004 8:38 AM Cc: [EMAIL PROTECTED] Subject: Re: [R] Zero Index Origin? Gabor Grothendieck wrote: If you are willing to do it yourself you can define a class for which indexing behaves that way. I'd like to prefix all these solutions with Here's how to do it, but don't actually do it you crazy fool. It's on a par with redefining pi, or redefining '+'. And then redefining '-'. These techniques have their proper place, and that would be in the currently non-existent obfuscated R contest. No, the R-ish (iRish?) way is to index vectors from 1. That's what the R gods intended! Baz __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] ARCH GARCH
On 31 Mar 2004 at 20:07, [EMAIL PROTECTED] wrote: i'm looking for an R library dealing with ARCH and GARCH models help.search(ARCH) on my system gives among others: garch-methods(tseries) Methods for Fitted GARCH Models garch(tseries) Fit GARCH Models to Time Series summary.garch(tseries) Summarizing GARCH Model Fits so you should look into the tseries package. Kjetil Halvorsen __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
On 31 Mar 2004 at 14:38, Barry Rowlingson wrote: Gabor Grothendieck wrote: If you are willing to do it yourself you can define a class for which indexing behaves that way. I'd like to prefix all these solutions with Here's how to do it, but don't actually do it you crazy fool. It's on a par with redefining pi, or redefining '+'. And then redefining '-'. You mean y - 5 - - function(x,value) x+value y [1] 5 y - 5 [1] 10 (but remember not to save the workspace) These techniques have their proper place, and that would be in the currently non-existent obfuscated R contest. No, the R-ish (iRish?) way is to index vectors from 1. That's what the R gods intended! But not everybody listens to the gods! On CRAN there is a blasfemish package called Oarray Kjetil Halvorsen Baz __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] scan seems to modify the data
Stephane DRAY wrote: Hello list, I have used scan function to import data into R. I have done some analysis and find strange results. I have found my problem : when importing data with scan, this can slightly modify the data : write(c(0.251,3.399,-0.481,0.266),essai.txt) scan(essai.txt) Read 4 items [1] 0.251 3.399 -0.481 0.266 print(scan(essai.txt),17) Read 4 items [1] 0.25100 3.39900 -0.48098 0.26601 Is it normal ? Is it a bug ? It is normal, that there are no exact representations for floating point numbers in a computer (you have only a limited number of bits to represent them!). In this case, it is not scan(), but just the representation: Try out and type print(c(0.251,3.399,-0.481,0.266), 17) Uwe Ligges thanks in advance, Sincerely. version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major1 minor8.1 year 2003 month11 day 21 language R Stéphane DRAY -- Département des Sciences Biologiques Université de Montréal, C.P. 6128, succursale centre-ville Montréal, Québec H3C 3J7, Canada Tel : 514 343 6111 poste 1233 E-mail : [EMAIL PROTECTED] -- Web http://www.steph280.freesurf.fr/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] scan seems to modify the data
Stéphane, in the example below which you are concerned about, the large correlation you see is not a result of the small variance, but rather the 3 random numbers you generated just happened to have the same rank ordering as the magnitudes of the three coefficients you were correlating them with. Just try your example again but repeat your correlation command cor(x[1,],runif(3)) several times in succession. You will probably see correlations ranging from large and positive to large (in absolute value) and negative to everywhere in between. Dan Nordlund --Original message-- In a message dated 3/31/2004 10:53:03 AM Pacific Standard Time, [EMAIL PROTECTED] writes: At 13:34 31/03/2004, Prof Brian Ripley wrote: Take a look at formatReal. scientific thinks 0.251 has 17 digits and 0.255 has 3. It really doesn't make any sense to ask for more precision than you have (.Machine$double.eps) and you do often get spurious errors if you attempt to do so. So 15 digits is normally safe, but no more. Note that there are decimal - binary - decimal conversions and you can't say which one introduced the small changes. I completely agree with you. My problem arise when I try to compute a correlation. One of the variable seems to have equal values but it does not. Hence, it has a very low variance and so when I try to compute the correlation with another variable, this correlation is very high. I wonder if it would not be good to introduce a tolerance threshold. Is it meaningful to produce correlation when a variance is very low ? See the example below : essai=matrix(c(0.266,.234,.005,.481,.1,.009,.4,.155,.255,.2,.34,.43),4,3) essai2=sweep(essai,2,apply(essai,2,sum),/) x=coef(lm(essai2~scale(runif(4 x [,1] [,2] [,3] (Intercept) 0.2500 0.250 0.2500 scale(runif(4)) 0.05307906 0.1330111 0.06936634 cor(x[1,],runif(3)) [1] 0.932772 var(x) [,1][,2] [,3] [1,] 0.01938893 0.011518783 0.01778528 [2,] 0.01151878 0.006843202 0.01056607 [3,] 0.01778528 0.010566067 0.01631426 var(x[1,]) [1] 1.92593e-33 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] corrupted ASCII file; was: (no subject)
Nicole Soranzo wrote: Hi, I wonder if you can help me: I cannot seem to be able to import my data anymore. When I try to import the attached file with the string FunctRes-read.table(C:/Documents and Settings/FunctRes.txt, header=FALSE) I obtain: FunctRes V1 1 ÿþC 2 \n 3C 40 50 6B 7 \n 8C 90 10 1 11 B 12 \n 13 C 14 0 15 0 16 B 17 \n 18 C 19 0 20 1 21 B 22 \n 23 C 24 0 25 1 26 B 27 \n 28 C 29 0 30 1 31 B Can you help me? Strange. The file got corrupted in some way. Copy and paste the contents to another (empty) ASCII file solves the problem. [Please use a sensible subject.] Uwe Ligges Thanks Nicole Dr Nicole Soranzo Centre for Population Genetics and Human Health University College London Darwin Building Gower Street London WC1E 6BT Tel: +44 (0)20 7679 4397 Fax: +44 (0)20 7679 2887 E-mail: [EMAIL PROTECTED] http://popgen.biol.ucl.ac.uk/ Name: FunctRes.txt FunctRes.txtType: Plain Text (text/plain) Encoding: base64 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Thanks for the input. I'm new to classes and object orientation as well as to R and was sorta hoping to hear that a solution might exist within that structure. Would existing functions be able to deal with such objects and see them as the 1 origin objects that they expect? A solution to backward compatibility that I proposed to the Matlab group, which was never shot down from a technical standpoint, but which in the end we could not get them to consider, was to make the origin a contextual variable which could be set by the programmer to whatever he wanted, ala APL. To deal with existing functions, it was made local in scope and always initialized to 1 when a function was called. I'm not yet sure that this simple approach is even meaningful much less inclusive in the context of R but I'd like to invite comment. I fully understand the potentially large scope of such a proposed change to the implementation but right now I'm just curious about the theoretical possibility. I don't really wish to go into all of the reasoning why this convenience is important to DSP applications. Let me just say that it has been the subject of considerable discussion WRT Matlab and a rather large number of reasons for its desirability have been put forth from that community. I'd like to promote R in the various usenet and email groups that are involved in DSP type programming, even to the point of recruiting an R-DSP working group, and to be able to point to this capability would be a strong selling point. Bob -- Things should be described as simply as possible, but no simpler. A. Einstein __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
I don't really wish to go into all of the reasoning why this convenience is important to DSP applications. I do some DSP work, in the context of instrumentation signal filtering, identification, tracking, and coherence (finding plant signals that have similar fingerprints). I agree that in languages that require you to work with explicit index values, the zero-offset makes perfect sense. However, I'd like to second Prof. Ripley's remark that if you're actually using indicies explicitly, you probably haven't wrapped your head around how powerful the indexing structure and whole object approach is in S (including R). It's been a long time since I used counter-based indicies. I'd like to promote R in the various usenet and email groups that are involved in DSP type programming, even to the point of recruiting an R-DSP working group Sounds interesting. Could you contact me off-list about this? Cheers Jason __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] functions paths
Hi, I have a couple of quick questions regarding R. 1) I have a .First function that automatically loads the quadprog package into the workspace. The .First function resides in R and is only saved if I save the workspace. The exact function is as follows: .First-function() { library(quadprog) } Is there any way that this function can be saved outside of R? That is, is there any procedure that will run specified R commands whenever R is invoked? 2) Is there anyway to specify additional paths for R to search. For example, I have some R script named, myProg.r that is saved in a directory C:\Programs\RLanguage\Rob\. I run the script in the following way: source(C:/Programs/RLanguage/Rob/myProg.r) This works fine, but I was wondering if there is any command that could be entered into the .First function described above that adds the directory C:\Programs\RLanguage\Rob\ to the R path. This way, C:\Programs\RLanguage\Rob\ will always be checked for the code and I could simply run myProg.r as follows: source(myProg.r) 3) Is there anyway that I could save functions that I have written outside of R. That is, could I write functions and have them saved in some directory, such as, C:\Programs\RLanguage\RobFunctions\? This way I would be able to copy the functions to other pcs. This is very simple in MatLab. Please let me know. Thanks for the help. Rob __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Jason Turner wrote: I do some DSP work, in the context of instrumentation signal filtering, identification, tracking, and coherence (finding plant signals that have similar fingerprints). I agree that in languages that require you to work with explicit index values, the zero-offset makes perfect sense. However, I'd like to second Prof. Ripley's remark that if you're actually using indicies explicitly, you probably haven't wrapped your head around how powerful the indexing structure and whole object approach is in S (including R). It's been a long time since I used counter-based indicies. I absolutely agree that the powerful indexing in R ameliorates it to a large extent but even the less powerful indexing of Matlab should satisfy that condition and yet there is still considerable sturm and drang over this issue. Bob -- Things should be described as simply as possible, but no simpler. A. Einstein __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Is there a package or routine for calculating mimimum spanning trees?
__ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Gauss user question
I have been using Gauss for doing maximum likelihood estimation of somewhat complex models, and I am possibly interested in moving over to R. Does anyone have experience doing both? My main concern is that my models are very slow to estimate in Gauss; wondering if R is likely to be faster or slower. Any feedback would be much appreciated! Thank you, Oleg Urminsky [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Bob Cain wrote: : Jason Turner wrote: : : However, I'd like to second Prof. Ripley's remark that if you're actually : using indicies explicitly, you probably haven't wrapped your head around : how powerful the indexing structure and whole object approach is in S : (including R). It's been a long time since I used counter-based indicies. : : I absolutely agree that the powerful indexing in R : ameliorates it to a large extent but even the less powerful : indexing of Matlab should satisfy that condition and yet : there is still considerable sturm and drang over this issue. I believe the point was not so much that R has powerful indexing (which it does) but that the capabilities of dealing with objects as a whole, i.e. without using indexing at all, makes facilities for indexing less important. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] functions paths
Rob, On Wed, Mar 31, 2004 at 05:28:19PM -0500, Kissell, Robert [EQRE] wrote: 1) I have a .First function that automatically loads the quadprog package into the workspace. The .First function resides in R and is only saved if I save the workspace. The exact function is as follows: [...] Is there any way that this function can be saved outside of R? That is, is there any procedure that will run specified R commands whenever R is invoked? Try help(Startup) You probably want .Rprofile (on a per-directory basis), and/or the site-wide $R_HOME/etc/Rprofile. 2) Is there anyway to specify additional paths for R to search. For example, I have some R script named, myProg.r that is saved in a directory C:\Programs\RLanguage\Rob\. I run the script in the following way: source(C:/Programs/RLanguage/Rob/myProg.r) This works fine, but I was wondering if there is any command that could be entered into the .First function described above that adds the directory C:\Programs\RLanguage\Rob\ to the R path. This way, C:\Programs\RLanguage\Rob\ will always be checked for the code and I could simply run myProg.r as follows: source(myProg.r) For library(), there is an argumemnt lib.loc. You can also set things from Rprofile. Source is simpler and wants pathname, so maybe you want to write a local function that does your desired magic with the directory and appends the filename you supply, before calling source() on the combined string? 3) Is there anyway that I could save functions that I have written outside of R. That is, could I write functions and have them saved in some directory, such as, C:\Programs\RLanguage\RobFunctions\? This way I would be able to copy the functions to other pcs. This is very simple in MatLab. Please let me know. See 2), save() and friends have pathnames too. So save(N:/my/network/share/foo.R) works just fine. Hth, Dirk -- The relationship between the computed price and reality is as yet unknown. -- From the pac(8) manual page __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Is there a package or routine for calculating mimimum spanning trees?
see mst in package ace At 17:54 31/03/2004, Briggs, Meredith M wrote: __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Stéphane DRAY -- Département des Sciences Biologiques Université de Montréal, C.P. 6128, succursale centre-ville Montréal, Québec H3C 3J7, Canada Tel : 514 343 6111 poste 1233 E-mail : [EMAIL PROTECTED] -- Web http://www.steph280.freesurf.fr/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] functions paths
At 5:28 PM -0500 3/31/04, Kissell, Robert [EQRE] wrote: Hi, I have a couple of quick questions regarding R. - snip - 3) Is there anyway that I could save functions that I have written outside of R. That is, could I write functions and have them saved in some directory, such as, C:\Programs\RLanguage\RobFunctions\? This way I would be able to copy the functions to other pcs. This is very simple in MatLab. Please let me know. Yes. Here are two ways. - 1 - In the directory where you have your function definitions, load the functions into R. Quit R, and say yes when asked whether or not to save the workspace image. Find the file in which the image is saved, copy it to the other pcs. On the other pcs, use the attach function to attach that file. The functions are now available. -2- Go get the R Extensions manual, learn how to create a package. Take your functions, make them into a package. Copy the package file to the other pcs. Use R's install package functionality to install the package. Then, whenever the functions are needed, use the library command to load your package. Thanks for the help. Rob -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Bob Cain [EMAIL PROTECTED] writes: Jason Turner wrote: I do some DSP work, in the context of instrumentation signal filtering, identification, tracking, and coherence (finding plant signals that have similar fingerprints). I agree that in languages that require you to work with explicit index values, the zero-offset makes perfect sense. However, I'd like to second Prof. Ripley's remark that if you're actually using indicies explicitly, you probably haven't wrapped your head around how powerful the indexing structure and whole object approach is in S (including R). It's been a long time since I used counter-based indicies. I absolutely agree that the powerful indexing in R ameliorates it to a large extent but even the less powerful indexing of Matlab should satisfy that condition and yet there is still considerable sturm and drang over this issue. I think it was said quite early in the thread, but since noone apparently listened, let me reiterate: One of the powerful indexing features in R is the negative index (all, except) and x[-0] would lead to some complications if 0 was a true index. -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] functions paths
Don MacQueen [EMAIL PROTECTED] writes: At 5:28 PM -0500 3/31/04, Kissell, Robert [EQRE] wrote: Hi, I have a couple of quick questions regarding R. - snip - 3) Is there anyway that I could save functions that I have written outside of R. That is, could I write functions and have them saved in some directory, such as, C:\Programs\RLanguage\RobFunctions\? This way I would be able to copy the functions to other pcs. This is very simple in MatLab. Please let me know. Yes. Here are two ways. - 1 - In the directory where you have your function definitions, load the functions into R. Quit R, and say yes when asked whether or not to save the workspace image. Find the file in which the image is saved, copy it to the other pcs. On the other pcs, use the attach function to attach that file. The functions are now available. -2- Go get the R Extensions manual, learn how to create a package. Take your functions, make them into a package. Copy the package file to the other pcs. Use R's install package functionality to install the package. Then, whenever the functions are needed, use the library command to load your package. - 3 - dump(c(fun1,fun2,fun3),path/to/myfuns.R) and source(path/to/myfuns.R) to get them into another session. (Can you even get started with -2- without knowing this??) -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Is there a package or routine for calculating mimimum spanning trees?
Stephane DRAY [EMAIL PROTECTED] writes: see mst in package ace *** ape, I believe... -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] identify() and controlling label size
Thank-you it works! I have ignored ps and relied on the cex arguments until now. Alex -Original Message- From: Barry Rowlingson [mailto:[EMAIL PROTECTED] Sent: March 31, 2004 10:59 AM To: Hanke, Alex Cc: '[EMAIL PROTECTED]' Subject: Re: [R] identify() and controlling label size Hanke, Alex wrote: I thought this was going to be easy ... Can the label size of identify() be controlled by setting par(cex.*) because I'm having no luck? My only recourse is to save the index and position of the labels from identify() and use text() to replot them. Funny, it seems to ignore that, but allows 'col=' and 'font=' to set the font colour and type. But! It accepts 'ps=' to set the point size! You may be saved... Try: plot(1:10) identify(1:10,ps=24) identify(1:10,ps=12) Baz __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Peter Dalgaard wrote: I think it was said quite early in the thread, but since noone apparently listened, let me reiterate: One of the powerful indexing features in R is the negative index (all, except) and x[-0] would lead to some complications if 0 was a true index. Interesting. The kind of gotcha I hoped wouldn't exist. Others? I've thought of another one. Legacy functions that accept indices as arguments from a 0-origin caller. Bob -- Things should be described as simply as possible, but no simpler. A. Einstein __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
I note that (1) [ is a class-based function in R, so it would be possible to define a class of zero-origin arrays. This would mean that indexing these things would be quite incompatible with all the other indexing in R, so it's not clear that it would be a good thing. (2) R lets you define left-hand functions, so if you define sub - function (a, i) a[i+1] sub- - function (a, i, value) a[i+1] - value then you can use sub(a,i) and sub(a,i) - ... for indexing. This still wouldn't work like R indexing in general, but it wouldn't _look_ as if it should, so that might be better. I used to love APL myself, and am a great fan of index origin 0, but I'm *not* a fan of having two different origins in one language controlled by a variable; it made life quite difficult trying to mix code from different libraries. In R, I find myself wondering whether a[fred] (string indexing) should depend on index origin, and if not, why not. (:-) Despite my love for origin 0, I've decided that the rest of R is worth it. Despite my love for origin 0, I've found that for the things that I do with R, index origin 1 really does seem to work better as a human interface. It would be interesting to see some sample code where origin 0 is supposed to make life easier, and to see what R experts to do make it even easier than that. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] row selection based on median in data frame
Hi. I am having trouble thinking of an easy way to grab rows out of a data frame. I want to select the rows with a median value when the rows are similar. A simple example is this table, which I could read into a data frame. I would like to find a new data frame with only the rows with a median value for the c column given a certain a value. For example, the c values for deadlift rows are 13, 8, and 5, so the row with a c value of 8 should show up in the output. a b c 1 deadlift 7 13 2 squat 7 24 3 clean 7 10 4 deadlift 8 8 5 squat 8 20 6 clean 8 2 7 deadlift 9 5 8 squat 9 32 9 clean 9 19 Result: a b c 4 deadlift 8 8 5 squat 8 20 3 clean 7 10 It's more complicated in my case, because I have not just one a column, but about eight columns that have to be the same. I can do this with clumsy loops, but I wonder whether there's a better way. -- --Ed L Cashin| PGP public key: [EMAIL PROTECTED]| http://noserose.net/e/pgp/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] row selection based on median in data frame
Ed L Cashin [EMAIL PROTECTED] writes: Hi. I am having trouble thinking of an easy way to grab rows out of a data frame. I want to select the rows with a median value when the rows are similar. I'm still catching up on my R list reading, and I notice there is a similar post to mine: Federico Calboli data manipulation: getting mean value every 5 rows I think the responses there answer my question, but I'll have to look into it. The responses say to use aggregate and an auxiliary row. -- --Ed L Cashin| PGP public key: [EMAIL PROTECTED]| http://noserose.net/e/pgp/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Bob Cain arcane at arcanemethods.com writes: ... zero origin ... It occurred to me that perhaps the point about classes could be framed somewhat differently. I think you have an implicit assumption that vectors, matrices and arrays in general should be used to represent the objects that you are interested in for your DSP work. This is an understandable assumption coming from an APL background where everything is an array but in R and other OO languages you can define your own classes that behave the way you want. The objective is not to shoehorn your application into preset structures like you do in APL but rather in R it is possible to create a model through its class and other facilities that closely models your domain. Even within the classes offered to you out-of-the-box I wonder if time series rather than vectors are not the appropriate class? For example, even if we accept indexing as the way to go for the moment, a time series might have an advantage. Furthermore, are you sure you want to loop over 0:length(whatever)-1. Maybe that paradigm is just ingrained through lack of access to anything better. Might it not really be better to iterate over time: t0, t0+deltat, ..., t1 in which 0-origin is inadequate so why stop there when you can have it all? The point is that rather than shoehorn your problem into vectors, you could use the facilities of R (either ones that are already there or ones you create for DSP) to act in precisely the right way and in the process get rid of the baggage that comes with being forced to iterate over 1,2,3,... or over 0,1,2,... Going past that you can go past iteration altogether and start dealing with whole objects at once. Finally, if you really approach this as how to set up one or more DSP clases, the solution you come up with may not be to create a 0-origin vector class but rather it should involve really understanding and modeling your problem domain in a way which was never possible with the limited modelling facilities of APL in which everything is an array. Its been said that you can program FORTRAN in any language. In the context of this discussion perhaps it could be said that you can program in an APL-like style in R but to really get the benefit of R you have to move to the appropriate program design style. (I am not putting down APL which is one of the most brilliant computer science achievements I have ever seen -- just pointing out where to go from there.) Of course the above is motherhood and some specific examples might put a sharper edge to the discussion. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] row selection based on median in data frame
Ed L Cashin [EMAIL PROTECTED] writes: Ed L Cashin [EMAIL PROTECTED] writes: Hi. I am having trouble thinking of an easy way to grab rows out of a data frame. I want to select the rows with a median value when the rows are similar. I'm still catching up on my R list reading, and I notice there is a similar post to mine: Federico Calboli data manipulation: getting mean value every 5 rows I think the responses there answer my question, but I'll have to look into it. The responses say to use aggregate and an auxiliary row. After consulting the docs and Venables and Ripley, I am not sure aggregate can do what I'm looking for. Given rows where certain specified columns have the same values, I'd like to select the row with the median value in another specified column (runtime). That is, after grouping the rows of the data frame based on the columns in the by parameter, I want to select one whole row as is, the row with the median runtime value, without doing median on more than one column. 'aggregate.data.frame' is the data frame method. If 'x' is not a data frame, it is coerced to one. Then, each of the variables (columns) in 'x' is split into subsets of cases (rows) of identical combinations of the components of 'by', and 'FUN' is applied to each such subset with further arguments in '...' passed to it. (I.e., 'tapply(VAR, by, FUN, ..., simplify = FALSE)' is done for each variable 'VAR' in 'x', conveniently wrapped into one call to 'lapply()'.) Is there a way to tell aggregate just do perform median on column runtime to select the whole row? Empty subsets are removed, and the result is reformatted into a data frame containing the variables in 'by' and 'x'. The ones arising from 'by' contain the unique combinations of grouping values used for determining the subsets, and the ones arising from 'x' the corresponding summary statistics for the subset of the respective variables in 'x'. I'd like to select all the columns, not just the ones I'm using to group or the one from which I want to find the median value. I think I can't use aggregate after all. But I must admit I'm very tired and should go to bed. -- --Ed L Cashin| PGP public key: [EMAIL PROTECTED]| http://noserose.net/e/pgp/ __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] New utility: sas2r
Dear R users, Biostatistics Denmark would like to annouce the availability of the new utility: sas2R --- a SAS to R parser. For almost 40 years SAS has been the primary tool for statisticians worldwide and its easy-to-learn syntax, unsurpassed graphical system, powerful macro language and recent graphical user interfaces have made SAS the number one statistical software choice for both beginners and advanced users. We find it unnecessary for users to learn yet another statistical software package and have decided to make SAS available to a larger audience by providing a SAS interface to the free statistical software package R. It is our hope that the sas2R utility eventually will prove as powerful as the true SAS system and we believe that this release marks the beginning of a new era for R. The sas2R utility consists of a parser (written in perl) that rewrites the SAS code as R code and a package (sastor) of utility functions that are needed to run the parsed code. sastor consists mainly of functions for presenting output in the familiar and canonical SAS format. Download the utility at: http://www.biostatistics.dk/sas2r/index.html Example: The following SAS code: DATA test; INPUT x y f$; CARDS; 1 2 m 1 3 m 2 4 m 2 4 f 1 5 m 4 3 f 3 2 f ; PROC PRINT DATA=test; VAR x; PROC REG DATA=test; MODEL y = x; RUN; is converted to library(sastor) test - data.frame(x = c(1, 1, 2, 2, 1, 4, 3), y = c(2, 3, 4, 4, 5, 3, 2), f = c(m, m, m, f, m, f, f)) sas.print.print(test[, c(x), drop=F]) sas.print.reg(lm(y ~ x, data=test)) which produces the following output: The SAS2R System Obs x 1 1 2 1 3 2 4 2 5 1 6 4 7 3 The SAS2R REG Procedure Analysis of Variance Dependent Variable: y Df Sum Sq Mean Sq F value Pr(F) Model1 0.5000 0.5000 0.3608 0.5742 Error5 6.9286 1.3857 Corrected Total 6 7.4286 1.8857 Root MSE 1.17716R-Square 0.0673 Dependent Mean3.28571Adj R-Sq-0.1192 Coeff Var35.82672 Parameter Estimates: DF Estimate Std. Error t value Pr(|t|) (Intercept) 1 3.7857 0.9438 4.011 0.0102 * x1 -0.2500 0.4162 -0.601 0.5742 Here is the DESCRIPTION file for the package: Package: sas2r Version: 1.04 Title: SAS-to-R parser Author: Rolf Poalis [EMAIL PROTECTED] Maintainer: Rolf Poalis [EMAIL PROTECTED] Description: A collection of functions for running SAS code in R. Depends: R (= 1.4.0), perl = 5.8.0 License: GPL URL: www.biostatistics.dk/sas2r/index.html The following SAS procedures are parsed succesfully: PROC CONTENTS PROC CORR PROC FREQ PROC GLM PROC MEANS PROC NPAR1WAY PROC PRINT PROC REG PROC SORT PROC TTEST PROC UNIVARIATE The following SAS procedures work to some degree: PROC GENMOD PROC GPLOT PROC MIXED Please note: o All SAS procedure calls must include a DATA= We look forward to receiving questions, comments and suggestions. Rolf Poalis, Biostatistics Denmark __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] New utility: sas2r
Rolf Poalis wrote: Dear R users, Biostatistics Denmark would like to annouce the availability of the new utility: sas2R --- a SAS to R parser. Has this been done by anyone for Matlab? Bob -- Things should be described as simply as possible, but no simpler. A. Einstein __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Gabor Grothendieck wrote: [snip good stuff] Of course the above is motherhood and some specific examples might put a sharper edge to the discussion. I really appreciate your point of view on this and think you are probably right. A question I have from my very limited understanding yet of OO is whether such objects could be passed to legacy functions with any expectation of correct results. Thanks, Bob -- Things should be described as simply as possible, but no simpler. A. Einstein __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Richard A. O'Keefe wrote: It would be interesting to see some sample code where origin 0 is supposed to make life easier, and to see what R experts to do make it even easier than that. I think I will try and invite Robert Bristow Johnson into this discussion. He's one of the most respected voices in DSP on the net and the most ardent critic of Matlab's 1 origin problem in DSP. Interesting him in a project to create a Matlike DSP package for R is one of the main reasons I am inquiring about 0-origin. Again, the more I get into this language (I just wish I could suspend everything else I'm doing for the nonce) the more I simply love it. Bob -- Things should be described as simply as possible, but no simpler. A. Einstein __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] [R-pkgs] energy 1.0.1
R Users, We would like to announce that Version 1.0.1 of the energy package is now available on CRAN. The energy package introduces a new class of statistical tests based on the concept of Newton's potential energy. Included in the package are * mvnorm.etest (test) and mvnorm.e (statistic) A rotation invariant multivariate goodness-of-fit test, implemented for testing multivariate normality with estimated parameters * eqdist.etest (test) and ksample.e (statistic) A k-sample multivariate nonparametric test of equal distributions (arbitrary number of samples and arbitrary dimension) with optional incomplete statistics to support testing arbitrarily large samples * energy.hclust and edist Hierarchical clustering based on e-distances and cluster distance function * poisson.mtest (test) and poisson.m (statistic) Mean distance test of Poisson distribution, estimated mean Here is a brief summary of the potential energy background of the tests in the energy package: Newton's gravitational force is inversely proportional to squared Euclidean distances between pairs of objects, and the potential energy is inversely proportional to their Euclidean distances. The simplest choice for the absolute value of the force is constant, and then the potential energy is proportional to the Euclidean distances between pairs of objects. In statistics, the objects are the observed random vectors, and thus our energy terms are Euclidean distances between the pairs of sample elements: ||x_i - x_j||. Tests are based on the Theorem that a suitable linear combination of these distances (the potential energy of the 'statistical situation') is always nonnegative, and equals 0 if and only if the null hypothesis holds. Comments and suggestions are welcome. The description file is below. Gabor Szekely and Maria Rizzo -- Description: Package: energy Title: E-statistics (energy statistics) tests of fit, clustering Version: 1.0.1 Date: March 24, 2004 Author: Maria L. Rizzo [EMAIL PROTECTED] and Gabor J. Szekely [EMAIL PROTECTED] Description: E-statistics (energy) tests for comparing distributions: multivariate normality, Poisson test, multivariate k-sample test for equal distributions, hierarchical clustering by e-distances. Energy-statistics concept based on a generalization of Newton's potential energy is due to Gabor J. Szekely. Maintainer: Maria Rizzo [EMAIL PROTECTED] License: GPL 2.0 or later -- Gabor J. Szekely Professor Department of Mathematics and Statistics Math Science Building Bowling Green State University Bowling Green, OH 43403-0221 E-mail: [EMAIL PROTECTED] Tel:419-372-7474 Fax:419-372-6092 http://www-math.bgsu.edu/~gabors/ ___ R-packages mailing list [EMAIL PROTECTED] https://www.stat.math.ethz.ch/mailman/listinfo/r-packages __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] New utility: sas2r
Bob Cain arcane at arcanemethods.com writes: Rolf Poalis wrote: Dear R users, Biostatistics Denmark would like to annouce the availability of the new utility: sas2R --- a SAS to R parser. Has this been done by anyone for Matlab? Bob Don't know about that but at the bottom of: http://cran.r-project.org/other-docs.html there are some links to R/Octave and R/Matlab lexicons. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Zero Index Origin?
Richard A. O'Keefe wrote: It would be interesting to see some sample code where origin 0 is supposed to make life easier, ... An application is the implementation of algorithms which use origin 0 and are written in pseudo code. Write down the statements in R syntax, include some print or browser statements and you are able to demonstrate the working of different approaches. Here is an example for sorting -- I know sort(x) is a better solution ... sort.6-function(a){ n-length(a) adapt-function(i){i+1} # local function to perform the index correction a-c(0,a) for(i in 2:n){ j-i-1 a[adapt(0)]-a[adapt(i)] while(a[adapt(j)]a[adapt(0)]){ a[adapt(j+1)]-a[adapt(j)] j-j-1 } a[adapt(j+1)]-a[adapt(0)] } return(a[-1]) } Peter Wolf __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html