Re: [R] [Q] GET_DIM() crash on Windows only

2004-06-23 Thread Uwe Ligges
Paul Roebuck wrote:
I have the following contrived code in package format.
On Solaris and Mac OS X, code runs just fine. On Windows,
it crashes the R environment with the "Send Bug Report"
dialog. I tried R 1.8.1 (Win2K) and R 1.9 (WinXP) binaries
with the same result. PCs otherwise appear properly
configured for creating R packages. Anything blatantly
wrong? Suggestions?

Works for me (R-1.9.1, WinNT4.0), even with gctorture(TRUE).
Did you use the recommended compiler and tools?
Uwe Ligges

TIA

Relevant files from package (getdim):
R/getdim.R
--
getdim <- function(x)
.Call("getdim",
  as.matrix(x),
  PACKAGE="getdim");
R/zzz.R
---
.First.lib <- function(libname, pkgname) {
if (version$major == 1 && version$minor < 8.1) {
stop("Requires R 1.8.1 or later")
}
library.dynam("getdim", pkgname, libname)
}
src/getdim.c

#include 
#include 
#include 
int GetMatrixDimen(SEXP vntX, int *nrow, int *ncol)
{
SEXP vntXdim;
int nX;
#ifdef DEBUG_GETDIM
REprintf("In GetMatrixDimen()...\n");
#endif
/ Code crashes here on Windoze **/
PROTECT(vntXdim = GET_DIM(vntX));
#ifdef DEBUG_GETDIM
REprintf("\tgot dimension object\n");
#endif
nX = GET_LENGTH(vntXdim);
#ifdef DEBUG_GETDIM
REprintf("\tgot length from dimension object\n");
#endif
if (nX == 2)
{
int *piXdim = INTEGER_POINTER(vntXdim);
*nrow = piXdim[0];
*ncol = piXdim[1];
}
else
{
*nrow = -1;
*ncol = -1;
}
UNPROTECT(1);
return nX;
}
SEXP getdim(SEXP vntX)
{
SEXP vntOut;
int m, n;
#ifdef DEBUG_GETDIM
REprintf("In getdim(x)...\n");
#endif
if (GetMatrixDimen(vntX, &m, &n) != 2)
{
error("'x' is not a two dimensional matrix");
/*NOTREACHED*/
}
#ifdef DEBUG_GETDIM
REprintf("\tm = %d\n", m);
REprintf("\tn = %d\n", n);
#endif
PROTECT(vntOut = NEW_INTEGER(2));
INTEGER(vntOut)[0] = m;
INTEGER(vntOut)[1] = n;
UNPROTECT(1);
return vntOut;
}
tests/getdim.R
--
library(getdim)
test.getdim <- function(input, expected) {
result <- getdim(input);
identical(all.equal(result, expected), TRUE);
}
mat <- matrix(1:6, 3, 2)
mat.expected <- c(3, 2)
test.getdim(mat, mat.expected)
vec <- 1:6
vec.expected <- c(6, 1)
test.getdim(vec, vec.expected)
--
SIGSIG -- signature too long (core dumped)
__
[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] chronological clustering

2004-06-23 Thread Angel Lopez
Does anybody know of any R functions to perform chronological clustering 
as explained in:

Legendre, P., S. Dallot & L. Legendre. 1985. Succession of species 
within a community: chronological clustering, with applications to 
marine and freshwater zooplankton. American Naturalist 125: 257-288.

http://www.fas.umontreal.ca/BIOL/legendre/reprints/succession_of_species.pdf
Thanks,
Angel
__
[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] GARCH and forecasting

2004-06-23 Thread Laura Holt
Dear R People:
Is there a way to forecast with GARCH modeling as found in tseries, please?
When I use the predict command, I get an output of length 100, regardless of 
what I put in the n.ahead steps.

R Version 1.9.0
Thanks in advance.
Sincerely,
Laura
mailto: [EMAIL PROTECTED]
download! http://toolbar.msn.click-url.com/go/onm00200413ave/direct/01/
__
[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 1.9.1 compilation error

2004-06-23 Thread Frankie Cheung
Dear Sir/Madam,

I encounter some problem duuring compilation of R 1.9.1 on AIX 5.1, after
running "./configure" then I type "make" to compile:

# make
.
gcc -I../../src/extra/zlib -I../../src/extra/bzip2 -I../../src/extra/pcre
-I. -I../../src/include -I../../src/include -I/usr/local/include
-DHAVE_CONFIG_H -mno-fp-in-toc  -g -O2 -c registration.c -o registration.o
g77   -g -O2 -c xxxpr.f -o xxxpr.o
gcc -Wl,-bdynamic -Wl,-bE:../../etc/R.exp -Wl,-bM:SRE -L/usr/local/lib -o
R.bin  CConverters.o Rdynload.o RNG.o apply.o arithmetic.o apse.o array.o
attrib.o base.o bind.o builtin.o character.o coerce.o colors.o complex.o
connections.o context.o cov.o cum.o dcf.o datetime.o debug.o devPS.o
devPicTeX.o deparse.o deriv.o devices.o dotcode.o dounzip.o dstruct.o
duplicate.o engine.o envir.o errors.o eval.o format.o fourier.o gram.o
gram-ex.o graphics.o identical.o internet.o iosupport.o lapack.o list.o
logic.o main.o mapply.o match.o memory.o model.o names.o objects.o optim.o
optimize.o options.o par.o paste.o pcre.o platform.o plot.o plot3d.o
plotmath.o print.o printarray.o printvector.o printutils.o qsort.o
random.o regex.o relop.o saveload.o scan.o seq.o serialize.o size.o sort.o
source.o split.o sprintf.o subassign.o subscript.o subset.o summary.o
unique.o util.o version.o vfonts.o registration.o xxxpr.o
../unix/libunix.a ../appl/libappl.a ../nmath/libnmath.a   -L/usr/local/lib
-L/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3
-L/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/../../../../powerpc-ibm-aix5.1.0.0/lib
-L/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/../../.. -lfrtbegin
-lg2c -lm -lgcc_s
/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/libgcc.a -lg
/lib/crt0.o ../extra/zlib/libz.a ../extra/bzip2/libbz2.a
../extra/pcre/libpcre.a -ldl -lm -lc
/usr/local/bin/ld: target dynamic not found
collect2: ld returned 1 exit status
make[3]: *** [R.bin] Error 1
make[3]: Leaving directory `/d1/ftcheung_GoIn/tmp/R-1.9.1/src/main'
make[2]: *** [R] Error 2
make[2]: Leaving directory `/d1/ftcheung_GoIn/tmp/R-1.9.1/src/main'
make[1]: *** [R] Error 1
make[1]: Leaving directory `/d1/ftcheung_GoIn/tmp/R-1.9.1/src'
make: *** [R] Error 1

I've tried to use AIX xlc compiler and GCC compiler (v2.95 and v3.3.3) but
all of them result to the same error message shown above. Can anyone give
me some hint of how to solve it?

with regards,
Frankie Cheung 
The University of Hong Kong

__
[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] GARCH and forecasting

2004-06-23 Thread Adrian Trapletti
Laura Holt wrote:
Dear R People:
Is there a way to forecast with GARCH modeling as found in tseries, 
please?

When I use the predict command, I get an output of length 100, 
regardless of what I put in the n.ahead steps.
n.ahead is no argument to predict.garch. See ?predict.garch. Only 
one-step ahead predictions are possible. For a prediction with no target 
observation available, use genuine = T.

Best
Adrian
R Version 1.9.0
Thanks in advance.
Sincerely,
Laura
mailto: [EMAIL PROTECTED]
_
MSN Toolbar provides one-click access to Hotmail from any Web page – 
FREE download! 
http://toolbar.msn.click-url.com/go/onm00200413ave/direct/01/


__
[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] Automatic routine - help

2004-06-23 Thread Monica Palaseanu-Lovejoy
Hi,

I would like to write a little automatic routine in R, but i am a too 
much of a beginner for that. I will appreciate any help regarding this 
particular problem.

Let’s suppose I have a data.frame with j columns (from 1 to n) and i 
rows (from 1 to p). I would like to write a procedure which reads 
every column j (j from 1 to n) and compare each value with the 
interval [0,1]. If z(i,j) is less than 0, then replace z(i,j) with 0. If z(i,j) 
is greater than 1, then replace z(i,j) with 1. If z(i,j) is inside the 
interval [0,1] then don’t change. In the end I would like to have a 
new data.frame with the new values. 

I am not sure how complicated or long such a procedure might be, 
so I will be very grateful for any help.

Thank you in advance,

Monica

__
[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] R 1.9.1 compilation error (on AIX 5.1)

2004-06-23 Thread Prof Brian Ripley
We do have alpha/beta test periods for new releases of R, so would anyone 
who did test AIX please confirm that they did succeed.  (No one reported 
an error, including yourself: are any AIX users interested in helping 
having R available for AIX?)   It is much better to have such reports 
during alpha test, or at least beta test.

On Wed, 23 Jun 2004, Frankie Cheung wrote:

> Dear Sir/Madam,
> 
> I encounter some problem duuring compilation of R 1.9.1 on AIX 5.1, after
> running "./configure" then I type "make" to compile:
> 
> # make
> .
> gcc -I../../src/extra/zlib -I../../src/extra/bzip2 -I../../src/extra/pcre
> -I. -I../../src/include -I../../src/include -I/usr/local/include
> -DHAVE_CONFIG_H -mno-fp-in-toc  -g -O2 -c registration.c -o registration.o
> g77   -g -O2 -c xxxpr.f -o xxxpr.o
> gcc -Wl,-bdynamic -Wl,-bE:../../etc/R.exp -Wl,-bM:SRE -L/usr/local/lib -o
> R.bin  CConverters.o Rdynload.o RNG.o apply.o arithmetic.o apse.o array.o
> attrib.o base.o bind.o builtin.o character.o coerce.o colors.o complex.o
> connections.o context.o cov.o cum.o dcf.o datetime.o debug.o devPS.o
> devPicTeX.o deparse.o deriv.o devices.o dotcode.o dounzip.o dstruct.o
> duplicate.o engine.o envir.o errors.o eval.o format.o fourier.o gram.o
> gram-ex.o graphics.o identical.o internet.o iosupport.o lapack.o list.o
> logic.o main.o mapply.o match.o memory.o model.o names.o objects.o optim.o
> optimize.o options.o par.o paste.o pcre.o platform.o plot.o plot3d.o
> plotmath.o print.o printarray.o printvector.o printutils.o qsort.o
> random.o regex.o relop.o saveload.o scan.o seq.o serialize.o size.o sort.o
> source.o split.o sprintf.o subassign.o subscript.o subset.o summary.o
> unique.o util.o version.o vfonts.o registration.o xxxpr.o
> ../unix/libunix.a ../appl/libappl.a ../nmath/libnmath.a   -L/usr/local/lib
> -L/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3
> -L/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/../../../../powerpc-ibm-aix5.1.0.0/lib
> -L/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/../../.. -lfrtbegin
> -lg2c -lm -lgcc_s
> /usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/libgcc.a -lg
> /lib/crt0.o ../extra/zlib/libz.a ../extra/bzip2/libbz2.a
> ../extra/pcre/libpcre.a -ldl -lm -lc
> /usr/local/bin/ld: target dynamic not found
> collect2: ld returned 1 exit status
> make[3]: *** [R.bin] Error 1
> make[3]: Leaving directory `/d1/ftcheung_GoIn/tmp/R-1.9.1/src/main'
> make[2]: *** [R] Error 2
> make[2]: Leaving directory `/d1/ftcheung_GoIn/tmp/R-1.9.1/src/main'
> make[1]: *** [R] Error 1
> make[1]: Leaving directory `/d1/ftcheung_GoIn/tmp/R-1.9.1/src'
> make: *** [R] Error 1
> 
> I've tried to use AIX xlc compiler and GCC compiler (v2.95 and v3.3.3) but
> all of them result to the same error message shown above. Can anyone give
> me some hint of how to solve it?

You appear not to be using the standard loader (`/usr/local/bin/ld').  
Please set MAIN_LDFLAGS (ideally in config.site before configure, but you
can edit Makeconf now) to whatever your loader needs.  If this is GNU ld
then I guess you need -Wl,--export-dynamic.

-- 
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] Automatic routine - help

2004-06-23 Thread Uwe Ligges
Monica Palaseanu-Lovejoy wrote:
Hi,
I would like to write a little automatic routine in R, but i am a too 
much of a beginner for that. I will appreciate any help regarding this 
particular problem.

Let’s suppose I have a data.frame with j columns (from 1 to n) and i 
rows (from 1 to p). I would like to write a procedure which reads 
every column j (j from 1 to n) and compare each value with the 
interval [0,1]. If z(i,j) is less than 0, then replace z(i,j) with 0. If z(i,j) 
is greater than 1, then replace z(i,j) with 1. If z(i,j) is inside the 
interval [0,1] then don’t change. In the end I would like to have a 
new data.frame with the new values. 

I am not sure how complicated or long such a procedure might be, 
so I will be very grateful for any help.

Thank you in advance,
Monica

If all columns of your data.frame are numeric:
z[z<0] <- 0
z[z>1] <- 1
Uwe Ligges
__
[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] Automatic routine - help

2004-06-23 Thread Prof Brian Ripley
How about

newDF <- DF
newDF[] <- lapply(DF, function(x) pmax(0, pmin(x, 1)))

as in

> DF <- data.frame(x=rnorm(5), y=rnorm(5))
> newDF <- DF
> newDF[] <- lapply(DF, function(x) pmax(0, pmin(x, 1)))
> newDF
   x y
1 0.31872426 1.000
2 1. 0.000
3 1. 0.4510969
4 0.04753697 1.000
5 0.89016978 0.000


On Wed, 23 Jun 2004, Monica Palaseanu-Lovejoy wrote:

> Hi,
> 
> I would like to write a little automatic routine in R, but i am a too 
> much of a beginner for that. I will appreciate any help regarding this 
> particular problem.
> 
> Let’s suppose I have a data.frame with j columns (from 1 to n) and i 
> rows (from 1 to p). I would like to write a procedure which reads 
> every column j (j from 1 to n) and compare each value with the 
> interval [0,1]. If z(i,j) is less than 0, then replace z(i,j) with 0. If z(i,j) 
> is greater than 1, then replace z(i,j) with 1. If z(i,j) is inside the 
> interval [0,1] then don’t change. In the end I would like to have a 
> new data.frame with the new values. 
> 
> I am not sure how complicated or long such a procedure might be, 
> so I will be very grateful for any help.
> 
> Thank you in advance,
> 
> Monica
> 
> __
> [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


[R] legend

2004-06-23 Thread Perez Martin, Agustin
DeaR UseRs:

I want to put a legend in my plot. In the first line of the legend I want to
put a box filled but in the second one I would like to put a lty=2

Of course it must appear with different colors.

Thanks.

__
[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] Colored label on dendrogram

2004-06-23 Thread Philippe Hupé
Hi,
Can someone tell me how to put labels of differente colors on a tree 
dendrogram.

Thanks
--
Philippe Hupé
UMR 144 - Service Bioinformatique
Institut Curie
Laboratoire de Transfert (4ème étage)
26 rue d'Ulm
75005 Paris - France

Email :  [EMAIL PROTECTED]
Tél :+33 (0)1 44 32 42 75
Fax :+33 (0)1 42 34 65 28
__
[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] legend

2004-06-23 Thread Ko-Kang Kevin Wang
Hi,

- Original Message - 
From: "Perez Martin, Agustin" <[EMAIL PROTECTED]>
To: "lista R help (E-mail)" <[EMAIL PROTECTED]>
Sent: Wednesday, June 23, 2004 9:19 PM
Subject: [R] legend


> DeaR UseRs:
>
> I want to put a legend in my plot. In the first line of the legend I want
to
> put a box filled but in the second one I would like to put a lty=2

Have you looked at ?lengend

It's got some good examples.

Kevin

__
[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] Automatic routine - help. THANKS!

2004-06-23 Thread Monica Palaseanu-Lovejoy
Hi,

Thank you so much for the little example - this was exactly what i 
was looking for. Just i didn't know what to search after in R. I will 
change it for my data needs.

Thanks again,

Monica

__
[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] Automatic routine - help

2004-06-23 Thread BXC (Bendix Carstensen)
for (j in 1:n) df[,j] <- pmin( pmax( df[,j], 0 ), 1 )

should do the job.

Bendix Carstensen

--
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
[EMAIL PROTECTED]
www.biostat.ku.dk/~bxc
--



> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Monica 
> Palaseanu-Lovejoy
> Sent: Wednesday, June 23, 2004 11:07 AM
> To: [EMAIL PROTECTED]
> Subject: [R] Automatic routine - help
> 
> 
> Hi,
> 
> I would like to write a little automatic routine in R, but i am a too 
> much of a beginner for that. I will appreciate any help 
> regarding this 
> particular problem.
> 
> Let's suppose I have a data.frame with j columns (from 1 to n) and i 
> rows (from 1 to p). I would like to write a procedure which reads 
> every column j (j from 1 to n) and compare each value with the 
> interval [0,1]. If z(i,j) is less than 0, then replace z(i,j) 
> with 0. If z(i,j) 
> is greater than 1, then replace z(i,j) with 1. If z(i,j) is 
> inside the 
> interval [0,1] then don't change. In the end I would like to have a 
> new data.frame with the new values. 
> 
> I am not sure how complicated or long such a procedure might be, 
> so I will be very grateful for any help.
> 
> Thank you in advance,
> 
> Monica
> 
> __
> [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] Automatic routine - help

2004-06-23 Thread Monica Palaseanu-Lovejoy
Hi,

This works beautifully as well.

Thanks,

Monica

__
[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] How to define stopping criterium for Optim with L-BFGS-B

2004-06-23 Thread ZABALZA-MEZGHANI Isabelle
Hi,

I am using optim with a L-BFGS-B method to minimize a function. As I've
understood, the way to specify a tolerance for stopping optimization is
through "factr" argument.
My function, is by construction, minimal when equal to 1. I wonder if there
is any way to pass this info to "optim". If not, how "factr" argument works
(I am quite confused about the relationship between this argument and the
Machine eps). Please, could someone give me an example ?

Thanks in advance

Isabelle.

I Zabalza-Mezghani
IFP - France

__

Ce message (et toutes ses pièces jointes éventuelles) est confidentiel et établi à 
l'intention exclusive de ses destinataires. Toute utilisation de ce message non 
conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, 
est interdite, sauf autorisation expresse. L'IFP décline toute responsabilité au titre 
de ce message.

This message and any attachments (the message) are confident...{{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] Automatic routine - help

2004-06-23 Thread Barry Rowlingson
Uwe Ligges wrote:
Monica Palaseanu-Lovejoy wrote:
Hi,
I would like to write a little automatic routine in R, but i am a too 
much of a beginner for that. I will appreciate any help regarding this 
particular problem.

If all columns of your data.frame are numeric:
z[z<0] <- 0
z[z>1] <- 1
 For added fun, you can wrap any of the methods given on the list into 
a function. For example:

 hardLimit <- function(z, min=0, max=1){
   z[z < min] <- min
   z[z > max] <- max
   return(z)
}
 Then you can do:
 z <- hardLimit(z)
 if you want to overwrite z, or:
 y <- hardLimit(z)
 to create a new data frame.
 Note how the default min and max arguments are 0 and 1, and make the 
function more flexible. You can also do:

 x <- hardLimit(z, min=-1)
 and that sets everything below -1 to the value -1.
Welcome to the world of R development!
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] Automatic routine - help

2004-06-23 Thread Prof Brian Ripley
On Wed, 23 Jun 2004, Barry Rowlingson wrote:

> Uwe Ligges wrote:
> > Monica Palaseanu-Lovejoy wrote:
> > 
> >> Hi,
> >>
> >> I would like to write a little automatic routine in R, but i am a too 
> >> much of a beginner for that. I will appreciate any help regarding this 
> >> particular problem.
> 
> > If all columns of your data.frame are numeric:
> > 
> > z[z<0] <- 0
> > z[z>1] <- 1
> > 
> 
>   For added fun, you can wrap any of the methods given on the list into 
> a function. For example:
> 
>   hardLimit <- function(z, min=0, max=1){
> z[z < min] <- min
> z[z > max] <- max
> return(z)
> }
> 
>   Then you can do:
> 
>   z <- hardLimit(z)
> 
>   if you want to overwrite z, or:
> 
>   y <- hardLimit(z)
> 
>   to create a new data frame.
> 
>   Note how the default min and max arguments are 0 and 1, and make the 
> function more flexible. You can also do:
> 
>   x <- hardLimit(z, min=-1)
> 
>   and that sets everything below -1 to the value -1.
> 
> Welcome to the world of R development!

First off, if you do start programming, you need to program up the 
comments too.  So as Uwe said

> > If all columns of your data.frame are numeric:

you need (untested)

hardLimit <- function(z, min=0, max=1)
{
if(!(is.numeric(z) || all(sapply(z, is.numeric)) )) 
stop("z is not a numeric vector, array or data frame")
z[z < min] <- min
z[z > max] <- max
z
}

since the code will also work for numeric vectors and arrays.  Then you 
need to check if min < max or the order matters 


However, if you want to do this at all efficiently for a data frame, start
with my solution not Uwe's, which creates several arrays the size of the
one you started with (two for the logical values, and one of the
intermediate answer) and does a for loop over columns internally at least
four times.

When operating on data frames it is usually best to work column by column, 
hence the

newDF[] <- lapply(DF, some_function_for_one_column)

paradigm.  (Changing just the values keeps all the attributes such as row 
names and col names.)


-- 
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] How to define stopping criterium for Optim with L-BFGS-B

2004-06-23 Thread Prof Brian Ripley
On Wed, 23 Jun 2004, ZABALZA-MEZGHANI Isabelle wrote:

> I am using optim with a L-BFGS-B method to minimize a function. As I've
> understood, the way to specify a tolerance for stopping optimization is
> through "factr" argument.
> My function, is by construction, minimal when equal to 1. I wonder if there
> is any way to pass this info to "optim". 

No, as the problem is assumed to be scaled so this is approximately true.

> If not, how "factr" argument works
> (I am quite confused about the relationship between this argument and the
> Machine eps). Please, could someone give me an example ?

The (absolute) convergence tolerance is factr times the Machine eps, and
the help page does already give you an example.  You can read the
references for further details.

-- 
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] converting apply output

2004-06-23 Thread Andrew Beckerman
Hi -
platform powerpc-apple-darwin6.8
status
major1
minor9.0
year 2004
I am trying to deal with the output of apply().  As indicated, when 
each call to 'FUN' returns a vector of length 'n', then 'apply'  
returns an array of dimension 'c(n, dim(X)[MARGIN])'.  However, I would 
like this to be a list in the same format as is produced when 'FUN' 
return vectors of different lengths ('apply'   returns a list of length 
'dim(X)[MARGIN]').

e.g.
tt1<-c(0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 
0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, ,0 ,0 ,0 ,0 ,0 ,0 
,1 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 
,1 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 1, 0, 1, 0)
m1<-matrix(tt1,10,10)
out<-apply(m1,2,function(x) which(x==1))

produces an array,
> out
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]897867666 7
[2,]9   108988   10   107 9
but I would like out as a list of 10 elements with two elements in 
each, e.g.

[[1]]
[1]  8 9
[[2]]
[1] 9 10
etc.
I have tried apply(out,2,function(x) list(x))), but the subsrcripting 
is not equal to the pattern when FUN returns a vectors of different 
length.  Any help would be appreciated.

Cheers
andrew
__
[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] ts & daily timeseries

2004-06-23 Thread Vittorio
On Tuesday 22 June 2004 17:41, Prof Brian Ripley wrote:
> data.frame(time=mytime, ts=myts)
>
> would appear to be what you are looking for.
>
> On Tue, 22 Jun 2004 [EMAIL PROTECTED] wrote:
> > I have defined a daily timeseries for the 365 days of 2003 issuing:
> >
> > myts = ts(dati[,2:10],frequency=365,)
> >
> > > myts
> >
> > Time Series:
> > Start = c(1, 1)
> > End = c(1, 365)
> > Frequency = 365
> >
> > and
> >
> > mytime =  as.POSIXct(strptime(as.character(dati[,1]),format="%Y-%m-%d"))
> >
> > contains the dates from "2003-01-01" to "2003-12-31"
>
> Why not use the Date class?  However, if all you want is the character
> representation of the dates you appear to have those in dati[1].
>
> > How can I combine mytime and myts in order to list the timeseries
> > according to the more natural
> >
> > 2003-01-01x  x   x ..
> > 2003-01-02x  x   x ..
> > ...
> > 2003-12-31x  x   x ..
>
> What do you want the first column to be?  Character strings? Dates?  What
> do you want to do with this?

As a newbye becoming more and more confident with R, I'm having a go at neural 
networks by means of your nnet package trying to model daily electricity 
demand with respect to time, weather extreme temperatures,air humidity, sky 
coverage (don't know if is correct in English, I mean: a measurement of the 
intensity of daylight going to very cloudy to completely clear), and type of 
day (working days, Mon, Sat, Sun).

Therefore, among many other things, I need to:

1) Window different spells of the year to study them separatedly;
2) Print in a human readable way the list of data of the spell  under 
observation;
3) Plot the same spells as timeseries, that is with a time referenced x-axis.

That's all.

Thanks 

Vittorio

__
[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] Tick marks in xyplot

2004-06-23 Thread Ingolfsson, Olafur
Dear R group

I am making multiple xyplot, and would like to have tick marks on bottom and left in 
EACH panel, but only tick labels at the bottom and left of the whole graph.
I have browsed the internet, as well as the help page without success.
If anyone could help me find the path to the solution I would appreciate.
Here is an example, this is the best I could do:

lset(col.whitebg())
x.data <- rnorm(16,20,7);y.data <- rnorm(16,.55,.25); z.data <- 
sample(1:4,16,replace=T)
xyplot(y.data~x.data|z.data, layout=c(2,2),
   scales=list(x=list(alternating=F),y=list(alternating=F),tck=c(-1,0)))

Cheers

Ólafur A. Ingólfsson
Institute of Marine Research
PO Box 1870 Nordnes
5817 Bergen, Norway

__
[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] converting apply output

2004-06-23 Thread Eric Lecoutre
Hi,
Why not try with the data.frame structure, wich internally yet consists in 
a list:

> lapply(as.data.frame(m1),function(x) which(x==1))
$V1
[1] 8 9
$V2
[1]  9 10
[...]
Eric
At 12:53 23/06/2004, Andrew Beckerman wrote:
Hi -
platform powerpc-apple-darwin6.8
status
major1
minor9.0
year 2004
I am trying to deal with the output of apply().  As indicated, when each 
call to 'FUN' returns a vector of length 'n', then 'apply'
returns an array of dimension 'c(n, dim(X)[MARGIN])'.  However, I would 
like this to be a list in the same format as is produced when 'FUN' return 
vectors of different lengths ('apply'   returns a list of length 
'dim(X)[MARGIN]').

e.g.
tt1<-c(0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 
0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 
,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,1 ,0 ,0 
,0 ,0 ,0 ,1 ,0 ,0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
1, 0, 1, 0)
m1<-matrix(tt1,10,10)
out<-apply(m1,2,function(x) which(x==1))

produces an array,
> out
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]897867666 7
[2,]9   108988   10   107 9
but I would like out as a list of 10 elements with two elements in each, e.g.
[[1]]
[1]  8 9
[[2]]
[1] 9 10
etc.
I have tried apply(out,2,function(x) list(x))), but the subsrcripting is 
not equal to the pattern when FUN returns a vectors of different 
length.  Any help would be appreciated.

Cheers
andrew
__
[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
Eric Lecoutre
UCL /  Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve
Belgium
tel: (+32)(0)10473050
[EMAIL PROTECTED]
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre
If the statistics are boring, then you've got the wrong numbers. -Edward 
Tufte

__
[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] gui for MacOS X / Aqua

2004-06-23 Thread Ronaldo Reis Jr.
Hi,

anybody know if Rcmdr or any other GUI like this work with R/Aqua?

Thanks
Ronaldo
-- 
Let's organize this thing and take all the fun out of it.
--
|>   // | \\   [***]
|   ( õ   õ )  [Ronaldo Reis Júnior]
|>  V  [UFV/DBA-Entomologia]
|/ \   [36571-000 Viçosa - MG  ]
|>  /(.''`.)\  [Fone: 31-3899-2532 ]
|  /(: :'  :)\ [EMAIL PROTECTED]]
|>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ]
|( `-  )   [***]
|>>  _/   \_Powered by GNU/Debian Woody/Sarge

__
[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] Grouped AND stacked bar charts possible in R?

2004-06-23 Thread Ivailo Partchev
This may have been answered before, but a nice possibility to plot the 
Titanic data is offered by "mosaic plots", as introduced (I think) by 
John Hartigan and implemented in the VCD package

Ivailo Partchev
Jena
Marc Schwartz wrote:
On Tue, 2004-06-22 at 10:54, Patrick Lenon wrote:
 

Good day all,
My statisticians want an R procedure that will produce grouped stacked 
barplots.  Barplot will
stack or group, but not both.  The ftable function can produce a table
of the exact form they want, but the barplot doesn't show all the
divisions we want.

For an example, here's the sample from the help file for "ftable:"
data(Titanic)
ftable(Titanic, row.vars = 1:3)
ftable(Titanic, row.vars = 1:2, col.vars = "Survived")
ftable(Titanic, row.vars = 2:1, col.vars = "Survived")
Now take it a step further to try to add another dimension:
b <- ftable(Titanic, row.vars=1:3)
  Survived  No Yes
Class SexAge  
1st   Male   Child0   5
Adult  118  57
 Female Child0   1
Adult4 140
2nd   Male   Child0  11
Adult  154  14
 Female Child0  13
Adult   13  80
3rd   Male   Child   35  13
Adult  387  75
 Female Child   17  14
Adult   89  76
Crew  Male   Child0   0
Adult  670 192
 Female Child0   0
Adult3  20

barplot(b)
barplot(b, beside=T))
Neither resulting barplot is satisfactory.  The first stacks all the
subdivisions of "Survived = Yes" and "Survived = No" together.  The
second is closer because it creates two groups, but it lists
combinations side-by-side that we'd like stacked. In the above example
"No" and "Yes" would be stacked on bars labeled "Male" or "Female"
in groups by Class.
I've taken a look through the R-Help archives and looked through the
contributed packages, but haven't found anything yet.
If you have any thoughts how we might produce groups of stacked bars
from an ftable, we would appreciate it.
   


I think that you are trying to plot too much information in a single
graphic. The result of a multi-dimensional barplot is likely to be very
difficult to interpret visually.
You would likely be better served to determine, within the multiple
dimensions, what your conditioning and grouping dimensions need to be
and then consider a lattice based plot.
I would urge you to consider using either barchart() or perhaps
dotplot() in lattice, which are designed to handle multivariable charts
of this nature.
Use:
library(lattice)
Then for general information
?Lattice
and then
?barchart
for more function specific information and examples of graphics with
each function.
For the Titanic data that you have above, you could do something like:
# Convert the multi-dimensional table to a 
# data frame. Assumes you have already done
# data(Titanic)
MyData <- as.data.frame(Titanic)

# Take a look at the structure
MyData
  ClassSex   Age Survived Freq
11st   Male Child   No0
22nd   Male Child   No0
33rd   Male Child   No   35
4   Crew   Male Child   No0
51st Female Child   No0
62nd Female Child   No0
73rd Female Child   No   17
8   Crew Female Child   No0
91st   Male Adult   No  118
10   2nd   Male Adult   No  154
11   3rd   Male Adult   No  387
12  Crew   Male Adult   No  670
13   1st Female Adult   No4
14   2nd Female Adult   No   13
15   3rd Female Adult   No   89
16  Crew Female Adult   No3
17   1st   Male Child  Yes5
18   2nd   Male Child  Yes   11
19   3rd   Male Child  Yes   13
20  Crew   Male Child  Yes0
21   1st Female Child  Yes1
22   2nd Female Child  Yes   13
23   3rd Female Child  Yes   14
24  Crew Female Child  Yes0
25   1st   Male Adult  Yes   57
26   2nd   Male Adult  Yes   14
27   3rd   Male Adult  Yes   75
28  Crew   Male Adult  Yes  192
29   1st Female Adult  Yes  140
30   2nd Female Adult  Yes   80
31   3rd Female Adult  Yes   76
32  Crew Female Adult  Yes   20
# Now do a plot. Use 'library(lattice)' here first
# if you had not already done so above for help.
barchart(Freq ~ Survived | Age * Sex, groups = Class, data = MyData,
auto.key = list(points = FALSE, rectangles = TRUE, space
= "right", title = "Class", border = TRUE), xlab = "Survived",
ylim = c(0, 800))
The above barchart will create a four panel plot, where the four main
panels will contain the combinations of Sex and Age. Within each panel
will be two groups of bars, one each for the Survived Yes/No status.
Within each group will be one bar for each Class. 

That is one quick way of grouping things, but you can alter that and
other plot attributes easily.
HTH,
Marc Schwartz
__
[EMAI

[R] Sciviews

2004-06-23 Thread Ronaldo Reis Jr.
Anybody use Sciviews with Linux or MacOS X? It work with these systems?

Thanks
Ronaldo
-- 
A hacker does for love what others would not do for money.
--
|>   // | \\   [***]
|   ( õ   õ )  [Ronaldo Reis Júnior]
|>  V  [UFV/DBA-Entomologia]
|/ \   [36571-000 Viçosa - MG  ]
|>  /(.''`.)\  [Fone: 31-3899-2532 ]
|  /(: :'  :)\ [EMAIL PROTECTED]]
|>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ]
|( `-  )   [***]
|>>  _/   \_Powered by GNU/Debian Woody/Sarge

__
[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] Tick marks in xyplot

2004-06-23 Thread Deepayan Sarkar
On Wednesday 23 June 2004 06:36, Ingolfsson, Olafur wrote:
> Dear R group
>
> I am making multiple xyplot, and would like to have tick marks on
> bottom and left in EACH panel, but only tick labels at the bottom and
> left of the whole graph. I have browsed the internet, as well as the
> help page without success. If anyone could help me find the path to
> the solution I would appreciate. Here is an example, this is the best
> I could do:

I don't think there is good way to do this in the way you expect (I'm 
assuming you want the same axis limits for each panel). If you really 
want this, look at the following options:

1. You can specify the limits, tick positions, and axis labels 
individually for each panel (see documentation for 'scales' in ?xyplot; 
all the relevant components - at, lab, etc - can be lists). Use this in 
conjunction with relation = "free". You need to supply empty strings as 
labels for all the 'inside' panels.

2. The big problem this would have is that the same amount of space 
would be allocated for the axis labels in each of the panels, even if 
that space is not used for the inside ones. One (undocumented and 
unreliable) way to get around that would be to use negative values of 
'between'.

Hope that helps,

Deepayan

__
[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] Automatic routine - NEW

2004-06-23 Thread Monica Palaseanu-Lovejoy
Hi Again,

First of all thank you for all the responses to my previous query. 
Your answers were very helpful and I did the job ;-). Now I hope you 
can answer as quick the following (sorry I am invading you with 
trivial questions):

Let’s use again the following data.frame example:
DF <- data.frame(x=rnorm(5), y=rnorm(5))

I want to obtain a new data.frame (or matrix) that contains only n 
rows (from the i rows DF has), and all the columns. If I have to do it 
step by step I would do something like that, for example:

a3 <- DF[3,]
a4 <- DF[4,]
a5 <- DF[5,]
b <- data.frame(a3, a4, a5)
c <- matrix(b, nrow=3, ncol=2, byrow=TRUE)

Now I want to do the same in one go, so I wrote:

for (i in 3:5)
{
d[i] <- DF[i,]
e <- data.frame(d[i])
f <- matrix(e, ncol=2, nrow=3, byrow=TRUE)
}

Which of course gives me errors and the matrix f has all elements 
equal with DF[5,5]. If I don’t use [i] after d, the resulting f matrix is 
made up from the DF[5,] elements (which is quite normal since i 
replaces itself ...). So …. How is this done correctly?

I am really appreciating your time and effort to answer me,

Monica

__
[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] Sciviews

2004-06-23 Thread Philippe Grosjean
Ronaldo Reis Jr wrote:
>Anybody use Sciviews with Linux or MacOS X? It work with these systems?

Not yet... but we are rewritting a part of the code so that some features
become platform-independent. Please, leave us a little time to archive this.
There are tens of thousands of lines of code in SciViews... so, this is a
very long process!
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


Re: [R] [Q] GET_DIM() crash on Windows only

2004-06-23 Thread Sundar Dorai-Raj
Uwe Ligges wrote:
Paul Roebuck wrote:
I have the following contrived code in package format.
On Solaris and Mac OS X, code runs just fine. On Windows,
it crashes the R environment with the "Send Bug Report"
dialog. I tried R 1.8.1 (Win2K) and R 1.9 (WinXP) binaries
with the same result. PCs otherwise appear properly
configured for creating R packages. Anything blatantly
wrong? Suggestions?

Works for me (R-1.9.1, WinNT4.0), even with gctorture(TRUE).
Did you use the recommended compiler and tools?
Uwe Ligges

And for me on R-1.9.0, Win2000.
--sundar
__
[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] [Q] GET_DIM() crash on Windows only

2004-06-23 Thread Sundar Dorai-Raj
Uwe Ligges wrote:
Paul Roebuck wrote:
I have the following contrived code in package format.
On Solaris and Mac OS X, code runs just fine. On Windows,
it crashes the R environment with the "Send Bug Report"
dialog. I tried R 1.8.1 (Win2K) and R 1.9 (WinXP) binaries
with the same result. PCs otherwise appear properly
configured for creating R packages. Anything blatantly
wrong? Suggestions?

Works for me (R-1.9.1, WinNT4.0), even with gctorture(TRUE).
Did you use the recommended compiler and tools?
Uwe Ligges

And for me on R-1.9.0, Win2000.
--sundar

__
[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] Automatic routine - NEW

2004-06-23 Thread Liaw, Andy
Sounds to me that you are looking for something like:

subDF <- DF[3:5,]

Andy

> From: Monica Palaseanu-Lovejoy
> 
> Hi Again,
> 
> First of all thank you for all the responses to my previous query. 
> Your answers were very helpful and I did the job ;-). Now I hope you 
> can answer as quick the following (sorry I am invading you with 
> trivial questions):
> 
> Let's use again the following data.frame example:
> DF <- data.frame(x=rnorm(5), y=rnorm(5))
> 
> I want to obtain a new data.frame (or matrix) that contains only n 
> rows (from the i rows DF has), and all the columns. If I have 
> to do it 
> step by step I would do something like that, for example:
> 
> a3 <- DF[3,]
> a4 <- DF[4,]
> a5 <- DF[5,]
> b <- data.frame(a3, a4, a5)
> c <- matrix(b, nrow=3, ncol=2, byrow=TRUE)
> 
> Now I want to do the same in one go, so I wrote:
> 
> for (i in 3:5)
> {
>   d[i] <- DF[i,]
>   e <- data.frame(d[i])
>   f <- matrix(e, ncol=2, nrow=3, byrow=TRUE)
> }
> 
> Which of course gives me errors and the matrix f has all elements 
> equal with DF[5,5]. If I don't use [i] after d, the resulting 
> f matrix is 
> made up from the DF[5,] elements (which is quite normal since i 
> replaces itself ...). So  How is this done correctly?
> 
> I am really appreciating your time and effort to answer me,
> 
> Monica
> 
> __
> [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] legend

2004-06-23 Thread Jim Lemon
Perez Martin, Agustin wrote:
> DeaR UseRs:
>
> I want to put a legend in my plot. In the first line of the legend I want
> to put a box filled but in the second one I would like to put a lty=2
>
> Of course it must appear with different colors.
>
I think I wrote this function about a year ago for someone, but I couldn't 
find it anywhere. Here it is again.

Jim
add.legend.bars<-function(legend.info,whichbars,col,border="black") {
 nelements<-length(legend.info$text$y)
 left<-rep(legend.info$rect$left+
  0.1*(legend.info$text$x[1]-legend.info$rect$left),nelements)
 right<-rep(legend.info$rect$left+
  0.8*(legend.info$text$x[1]-legend.info$rect$left),nelements)
 top<-legend.info$text$y+(legend.info$text$y[1]-legend.info$text$y[2])/3
 bottom<-top-(legend.info$text$y[1]-legend.info$text$y[2])/1.5
 rect(left[whichbars],bottom[whichbars],
  right[whichbars],top[whichbars],
  col=col,border=border)
}
__
[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] Automatic routine - NEW

2004-06-23 Thread Spencer Graves
 The documentation is good for things like this. In most (all recent?) 
versions of R, "help.start()" brings up a help page. Select "An 
Introduction to R", and go to "Vector Indices". Also look at "Arrays and 
Matrices: Array Indexing". There, you will find that "DF[3:5,]" might be 
what you want.

Actually, I'm not certain that your "c" below is what you want, because 
class(c[1,1]) is "list", and I could not do arithmetic on it. I 
discovered that when I tried all.equal(c, DF[3:5,]). {Also, "c" is the 
name of a very useful function; try "?c". It is usually wise to avoid 
using names of functions for matrices of data.frames. R will select the 
one you want from the context in most but not all cases.}

hope this helps.
spencer graves
Monica Palaseanu-Lovejoy wrote:
Hi Again,
First of all thank you for all the responses to my previous query. 
Your answers were very helpful and I did the job ;-). Now I hope you 
can answer as quick the following (sorry I am invading you with 
trivial questions):

Let’s use again the following data.frame example:
DF <- data.frame(x=rnorm(5), y=rnorm(5))
I want to obtain a new data.frame (or matrix) that contains only n 
rows (from the i rows DF has), and all the columns. If I have to do it 
step by step I would do something like that, for example:

a3 <- DF[3,]
a4 <- DF[4,]
a5 <- DF[5,]
b <- data.frame(a3, a4, a5)
c <- matrix(b, nrow=3, ncol=2, byrow=TRUE)
Now I want to do the same in one go, so I wrote:
for (i in 3:5)
{
d[i] <- DF[i,]
e <- data.frame(d[i])
f <- matrix(e, ncol=2, nrow=3, byrow=TRUE)
}
Which of course gives me errors and the matrix f has all elements 
equal with DF[5,5]. If I don’t use [i] after d, the resulting f matrix is 
made up from the DF[5,] elements (which is quite normal since i 
replaces itself ...). So …. How is this done correctly?

I am really appreciating your time and effort to answer me,
Monica
__
[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] Automatic routine - NEW

2004-06-23 Thread Monica Palaseanu-Lovejoy
Hi Spencer,

Your answer is very helpful. I was wondering if i should write again 
to the list to ask where i suppose to read about indices and things 
liek that since it seems they are very useful in lots of things. But 
you already gave me the answer. 

Thanks again,

Monica

__
[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] Automatic routine - NEW

2004-06-23 Thread Adaikalavan Ramasamy
On Wed, 2004-06-23 at 13:53, Monica Palaseanu-Lovejoy wrote:
> Hi Again,
> 
> First of all thank you for all the responses to my previous query. 
> Your answers were very helpful and I did the job ;-). Now I hope you 
> can answer as quick the following (sorry I am invading you with 
> trivial questions):
> 
> Lets use again the following data.frame example:
> DF <- data.frame(x=rnorm(5), y=rnorm(5))
> 
> I want to obtain a new data.frame (or matrix) that contains only n 
> rows (from the i rows DF has), and all the columns. If I have to do it 
> step by step I would do something like that, for example:
> 
> a3 <- DF[3,]
> a4 <- DF[4,]
> a5 <- DF[5,]
> b <- data.frame(a3, a4, a5)
> c <- matrix(b, nrow=3, ncol=2, byrow=TRUE)

1. You need to read the section on subsetting a matrix or dataframe and
sequence generation. e.g. help("[") and help(":")

2. b <- DF[3:5, ] should do the trick. Also please learn the difference
between a matrix and dataframe.

3. 'c' is a built in function. Do not create objects with 'c' or any
other built in function if possible.

> Now I want to do the same in one go, so I wrote:
> 
> for (i in 3:5)
> {
>   d[i] <- DF[i,]
>   e <- data.frame(d[i])
>   f <- matrix(e, ncol=2, nrow=3, byrow=TRUE)
> }
> 
> Which of course gives me errors and the matrix f has all elements 
> equal with DF[5,5]. If I dont use [i] after d, the resulting f matrix is 
> made up from the DF[5,] elements (which is quite normal since i 
> replaces itself ...). So . How is this done correctly?

You have not define 'd' before the loop. So you cannot subset or assign
to 'd'. Read the errors and it should say something like 'Error: Object
"d" not found'.

> I am really appreciating your time and effort to answer me,

I think you better the read the R manuals or Peter Daalgard's book on
Introduction to R. It might take you a couple of hours/days but the time
spent is well worth it.

> Monica
> 
> __
> [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] Covered Labels

2004-06-23 Thread Martina Renninger
Dear All!

 

How can I cope with overlapping or covered labels (covered by labels
from other data points) in plots?

 

 

 

Martina Renninger

 

 


[[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] Covered Labels

2004-06-23 Thread Marc Schwartz
On Wed, 2004-06-23 at 09:06, Martina Renninger wrote:
> Dear All!

> How can I cope with overlapping or covered labels (covered by labels
> from other data points) in plots?


Presuming that you are using text() to identify points in a plot, you
can use the 'cex' argument (which defaults to 1) to reduce the size of
the font. So in this case, try values <1, for example:

text(x, y, labels = YourText, cex = 0.8)

Possibly depending upon how many points you have, you can also adjust
the position of the label with respect to the data points by using
'adj', 'pos' and 'offset'.

See ?text 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


[R] grid lines when plotting its object

2004-06-23 Thread M. Sutter
Dear R community
When plotting an its object (with 'plot(..)), grid lines are 
automatically added which I cannot control with parameter 'tck/tcl'.
Furthermore the vertical grid lines (time axis) do not comply with the 
automatically generated tickmark locations.

Can somebody tell me how to handle these grid lines ?
How can I switch off the grid lines ?
Thanks a lot for any advice and I'd like to thank all the R 
developpers/experts for spending their precious time answering questions 
on the r-help mailing list and making it very valuable for R users like me.

Package: its
Version: 0.2.2
Date: 2004/01/06
> version
_   
platform i686-pc-linux-gnu
arch i686
os   linux-gnu   
system   i686, linux-gnu 
status   
major1   
minor8.1  --> I know, 9.1 is released ... I 
suppose/hope, thats not the problem
year 2003
month11  
day  21  
language R   
>

__
[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] R 1.9.1 compilation error (on AIX 5.1)

2004-06-23 Thread Liaw, Andy
> From: Prof Brian Ripley
> 
> We do have alpha/beta test periods for new releases of R, so 
> would anyone 
> who did test AIX please confirm that they did succeed.  (No 
> one reported 
> an error, including yourself: are any AIX users interested in helping 
> having R available for AIX?)   It is much better to have such reports 
> during alpha test, or at least beta test.

I just tried compiling R-1.9.1 as 64-bit on powerpc-ibm-aix5.1.0.0 using
xlc/xlf.  The compile went fine, and the only part of make check that failed
was internet.R (since there's no 'Net access from that box).  The GCC on
that box is probably too outdated to try, unfortunately.

Best,
Andy

 
> On Wed, 23 Jun 2004, Frankie Cheung wrote:
> 
> > Dear Sir/Madam,
> > 
> > I encounter some problem duuring compilation of R 1.9.1 on 
> AIX 5.1, after
> > running "./configure" then I type "make" to compile:
> > 
> > # make
> > .
> > gcc -I../../src/extra/zlib -I../../src/extra/bzip2 
> -I../../src/extra/pcre
> > -I. -I../../src/include -I../../src/include -I/usr/local/include
> > -DHAVE_CONFIG_H -mno-fp-in-toc  -g -O2 -c registration.c -o 
> registration.o
> > g77   -g -O2 -c xxxpr.f -o xxxpr.o
> > gcc -Wl,-bdynamic -Wl,-bE:../../etc/R.exp -Wl,-bM:SRE 
> -L/usr/local/lib -o
> > R.bin  CConverters.o Rdynload.o RNG.o apply.o arithmetic.o 
> apse.o array.o
> > attrib.o base.o bind.o builtin.o character.o coerce.o 
> colors.o complex.o
> > connections.o context.o cov.o cum.o dcf.o datetime.o debug.o devPS.o
> > devPicTeX.o deparse.o deriv.o devices.o dotcode.o dounzip.o 
> dstruct.o
> > duplicate.o engine.o envir.o errors.o eval.o format.o 
> fourier.o gram.o
> > gram-ex.o graphics.o identical.o internet.o iosupport.o 
> lapack.o list.o
> > logic.o main.o mapply.o match.o memory.o model.o names.o 
> objects.o optim.o
> > optimize.o options.o par.o paste.o pcre.o platform.o plot.o plot3d.o
> > plotmath.o print.o printarray.o printvector.o printutils.o qsort.o
> > random.o regex.o relop.o saveload.o scan.o seq.o 
> serialize.o size.o sort.o
> > source.o split.o sprintf.o subassign.o subscript.o subset.o 
> summary.o
> > unique.o util.o version.o vfonts.o registration.o xxxpr.o
> > ../unix/libunix.a ../appl/libappl.a ../nmath/libnmath.a   
> -L/usr/local/lib
> > -L/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3
> > 
> -L/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/../../..
> /../powerpc-ibm-aix5.1.0.0/lib
> > 
> -L/usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/../../..
>  -lfrtbegin
> > -lg2c -lm -lgcc_s
> > /usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/libgcc.a -lg
> > /lib/crt0.o ../extra/zlib/libz.a ../extra/bzip2/libbz2.a
> > ../extra/pcre/libpcre.a -ldl -lm -lc
> > /usr/local/bin/ld: target dynamic not found
> > collect2: ld returned 1 exit status
> > make[3]: *** [R.bin] Error 1
> > make[3]: Leaving directory `/d1/ftcheung_GoIn/tmp/R-1.9.1/src/main'
> > make[2]: *** [R] Error 2
> > make[2]: Leaving directory `/d1/ftcheung_GoIn/tmp/R-1.9.1/src/main'
> > make[1]: *** [R] Error 1
> > make[1]: Leaving directory `/d1/ftcheung_GoIn/tmp/R-1.9.1/src'
> > make: *** [R] Error 1
> > 
> > I've tried to use AIX xlc compiler and GCC compiler (v2.95 
> and v3.3.3) but
> > all of them result to the same error message shown above. 
> Can anyone give
> > me some hint of how to solve it?
> 
> You appear not to be using the standard loader 
> (`/usr/local/bin/ld').  
> Please set MAIN_LDFLAGS (ideally in config.site before 
> configure, but you
> can edit Makeconf now) to whatever your loader needs.  If 
> this is GNU ld
> then I guess you need -Wl,--export-dynamic.
> 
> -- 
> 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] gui for MacOS X / Aqua

2004-06-23 Thread Ulises Mora Alvarez
Hello,

Yes, indeed. All you have to do it's: launch your X server (take a look 
at your /Applications/Utilities folder), and then launch R from an xterm.

If you don't have your X server installed, take a look at the RAqua-FAQ 
and the R-FAQ on CRAN.

If you need more help, please don't hesitate in letting me know.

Good look.

On Wed, 23 Jun 2004, Ronaldo Reis Jr. wrote:

> Hi,
> 
> anybody know if Rcmdr or any other GUI like this work with R/Aqua?
> 
> Thanks
> Ronaldo
> 

-- 
Ulises M. Alvarez
LAB. DE ONDAS DE CHOQUE
FISICA APLICADA Y TECNOLOGIA AVANZADA
UNAM
[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


[R] Perl--R interface

2004-06-23 Thread XIAO LIU
R users:

My R is 1.8.1 in Linux.  How can I call R in Perl process? And call Perl from R?

Thanks

Xiao

__
[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] Problem with XML package compilation on AIX

2004-06-23 Thread Marea Bissonnette
Hi,

I hope someone has seen this problem before.  I am
trying to install the XML package from
http://cran.r-project.org/src/contrib/XML_0.95-6.tar.gz.

Using 

> R CMD INSTALL XML_0.95-6.tar.gz 

I get the following error message:

/usr/vac/bin/xlc_r -I/usr/local/lib/R/include -DLIBXML
-I/opt/freeware/include/libxml2
-DUSE_EXTERNAL_SUBSET=1 -DROOT_HAS_DTD_NODE=1
-DDUMP_WITH_ENCODING=1 -DUSE_XML_VERSION_H=1
-DXML_ELEMENT_ETYPE=1 -DXML_ATTRIBUTE_ATYPE=1
-DNO_XML_HASH_SCANNER_RETURN=1 -DUSE_R=1 -D_R_=1 
-DHAVE_VALIDITY=1 -I. -DLIBXML2=1 -I/usr/local/include
-O -qstrict -c DocParse.c -o DocParse.o
"DocParse.c", line 113.29: 1506-280 (E) Function
argument assignment between types "const unsigned
char*" and "char*" is not allowed.
and then more of the same on other lines.

Does anyone know what I can do to get this to compile
happy and install?  Any help would be appreciated.

I'll put the full transcript inline below in case that
helps.

M.


[EMAIL PROTECTED] /export/home/mlb# R CMD INSTALL XML*.gz
* Installing *source* package 'XML' ...
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler...
yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none
needed
checking how to run the C preprocessor... gcc -E
checking for xml-config... no
checking for xml2-config... /usr/bin/xml2-config
Using libxml version 2.
Located parser file
-I/opt/freeware/include/libxml2/parser.h
Checking for 1.8:  -I/opt/freeware/include/libxml2
Using libxml2.*
checking for gzopen in -lz... yes
checking for xmlParseFile in -lxml2... yes
checking for xmlHashSize in -lxml2... yes
Using built-in xmlHashSize
Checking DTD parsing (presence of externalSubset)...
checking for xmlHashSize in -lxml2... yes
Found xmlHashSize
checking for xmlDocDumpFormatMemoryEnc in -lxml2...
yes
checking libxml/xmlversion.h usability... yes
checking libxml/xmlversion.h presence... yes
checking for libxml/xmlversion.h... yes
Expat:  FALSE
Checking for return type of xmlHashScan element
routine.
No return value for xmlHashScan


Configuration information:

Libxml settings

libxml include directory:
-I/opt/freeware/include/libxml2
libxml library directory: -L/opt/freeware/lib -lxml2
-lz -lpthread -liconv -lm -lz  -lxml2
libxml 2: -DLIBXML2=1

Compilation flags: -DLIBXML
-I/opt/freeware/include/libxml2
-DUSE_EXTERNAL_SUBSET=1 -DROOT_HAS_DTD_NODE=1
-DDUMP_WITH_ENCODING=1 -DUSE_XML_VERSION_H=1
-DXML_ELEMENT_ETYPE=1 -DXML_ATTRIBUTE_ATYPE=1
-DNO_XML_HASH_SCANNER_RETURN=1
Link flags:   -L/opt/freeware/lib -lxml2
-lz -lpthread -liconv -lm -lz  -lxml2


configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating R/supports.R
config.status: creating inst/scripts/RSXML.csh
config.status: creating inst/scripts/RSXML.bsh
** libs
/usr/vac/bin/xlc_r -I/usr/local/lib/R/include
-DLIBXML -I/opt/freeware/include/libxml2
-DUSE_EXTERNAL_SUBSET=1 -DROOT_HAS_DTD_NODE=1
-DDUMP_WITH_ENCODING=1 -DUSE_XML_VERSION_H=1
-DXML_ELEMENT_ETYPE=1 -DXML_ATTRIBUTE_ATYPE=1
-DNO_XML_HASH_SCANNER_RETURN=1 -DUSE_R=1 -D_R_=1 
-DHAVE_VALIDITY=1 -I. -DLIBXML2=1 -I/usr/local/include
-O -qstrict -c DocParse.c -o DocParse.o
"DocParse.c", line 113.29: 1506-280 (E) Function
argument assignment between types "const unsigned
char*" and "char*" is not allowed.
"DocParse.c", line 113.17: 1506-068 (E) Operation
between types "char*" and "unsigned char*" is not
allowed.
"DocParse.c", line 176.88: 1506-275 (S) Unexpected
text ',' encountered.
"DocParse.c", line 205.17: 1506-068 (E) Operation
between types "const char*" and "const unsigned char*"
is not allowed.
"DocParse.c", line 261.56: 1506-280 (E) Function
argument assignment between types "const char*" and
"const unsigned char*" is not allowed.
"DocParse.c", line 292.22: 1506-196 (E) Initialization
between types "char*" and "unsigned char*" is not
allowed.
"DocParse.c", line 300.29: 1506-280 (E) Function
argument assignment between types "char*" and
"unsigned char*" is not allowed.
"DocParse.c", line 334.75: 1506-280 (E) Function
argument assignment between types "const char*" and
"const unsigned char*" is not allowed.
"DocParse.c", line 354.61: 1506-280 (E) Function
argument assignment between types "const char*" and
"const unsigned char*" is not allowed.
"DocParse.c", line 384.19: 1506-068 (E) Operation
between types "const char*" and "const unsigned char*"
is not allowed.
"DocParse.c", line 481.98: 1506-280 (E) Function
argument assignment between types "const char*" and
"unsigned char*" is not allowed.
"DocParse.c", line 484.86: 1506-280 (E) Function
argument assignment between types "const char*" and
"const unsigned char*" is not

[R] Fitting function with if-clause (nls; e.g. heaviside)

2004-06-23 Thread Karl Knoblick
Hallo!

I want to fit a function. The function is e.g.:
y = c+m1*x if x<0, c+m2*x if x>=0
where m1, m2 and c is a parameter and x, y are
variables of a data frame.

I think using  nls is appropriate. But I do not know,
how to type this formula in nls. Can anybody help?

(If there is a possibility to use a Heaviside-function
this would be enough.)

Karl






___
Bestellen Sie Y! DSL und erhalten Sie die AVM "FritzBox SL" für 0€.
Sie sparen 119€ und bekommen 2 Monate Grundgebührbefreiung.

__
[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] Automatic routine - help

2004-06-23 Thread Gabor Grothendieck

You already have a few solutions but here is one more:

   (z >= 0 & z <= 1) * z + (z > 1)

It uses the fact that TRUE and FALSE act as 1 and 0 in arithmetic.

Slightly shorter but trickier is:

   (z*z <= z) * z + (z > 1)

which uses the fact that z*z <= z only in the interval [0,1] .

Monica Palaseanu-Lovejoy  stud.man.ac.uk> writes:

: 
: Hi,
: 
: I would like to write a little automatic routine in R, but i am a too 
: much of a beginner for that. I will appreciate any help regarding this 
: particular problem.
: 
: LetÂs suppose I have a data.frame with j columns (from 1 to n) and i 
: rows (from 1 to p). I would like to write a procedure which reads 
: every column j (j from 1 to n) and compare each value with the 
: interval [0,1]. If z(i,j) is less than 0, then replace z(i,j) with 0. If z
(i,j) 
: is greater than 1, then replace z(i,j) with 1. If z(i,j) is inside the 
: interval [0,1] then donÂt change. In the end I would like to have a 
: new data.frame with the new values. 
: 
: I am not sure how complicated or long such a procedure might be, 
: so I will be very grateful for any help.
: 
: Thank you in advance,
: 
: Monica
: 
: __
: R-help  stat.math.ethz.ch 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] Perl--R interface

2004-06-23 Thread Arne.Muller
Hi,

look at http://www.omegahat.org/RSPerl/index.html. 

regards,

Arne

--
Arne Muller, Ph.D.
Toxicogenomics, Aventis Pharma
arne dot muller domain=aventis com

> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of XIAO LIU
> Sent: 23 June 2004 17:11
> To: [EMAIL PROTECTED]
> Subject: [R] Perl--R interface
> 
> 
> R users:
> 
> My R is 1.8.1 in Linux.  How can I call R in Perl process? 
> And call Perl from R?
> 
> Thanks
> 
> Xiao
> 
> __
> [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] Fitting function with if-clause (nls; e.g. heaviside)

2004-06-23 Thread Prof Brian Ripley
On Wed, 23 Jun 2004, Karl Knoblick wrote:

> I want to fit a function. The function is e.g.:
> y = c+m1*x if x<0, c+m2*x if x>=0
> where m1, m2 and c is a parameter and x, y are
> variables of a data frame.
> 
> I think using  nls is appropriate. But I do not know,
> how to type this formula in nls. Can anybody help?

It's a linear model (linear in the params)

lm( y ~ I(x*(x>0) + I(x*(x<0)))

although I would define some new variables to make that easier to read, 
e.g.

xplus <- x*(x>0)
xminus <- x*(x<0)
lm(y ~ xplus + xminus)

-- 
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] help with win.print

2004-06-23 Thread Joy, Tom
I am trying to batch the printing of some graphs using win.print when I leave the 
printer option blank it prompts me for a printer each time and then works fine when I 
put the printer name in however using the following code I get the error below. Does 
the printer need to be locally installed or can it print to a network printer like I 
am trying to?

win.print(width=8, height=10.5,printer="\\LBPS\LBMARK_4200")
 
Error in devga(paste("win.print:", printer, sep = ""), width, height,  : 
unable to start device devga

> Thanks,
> Tom Joy
> 

[[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] help with win.print

2004-06-23 Thread Prof Brian Ripley
Do remember that you need to double backslashes in R strings ... see the 
rw-FAQ.  As I recall forward slashes work here too.

On Wed, 23 Jun 2004, Joy, Tom wrote:

> I am trying to batch the printing of some graphs using win.print when I leave the 
> printer option blank it prompts me for a printer each time and then works fine when 
> I put the printer name in however using the following code I get the error below. 
> Does the printer need to be locally installed or can it print to a network printer 
> like I am trying to?
> 
> win.print(width=8, height=10.5,printer="\\LBPS\LBMARK_4200")
>  
> Error in devga(paste("win.print:", printer, sep = ""), width, height,  : 
> unable to start device devga

Try printer="LBPS\\LBMARK_4200"

-- 
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] Contour plots of PCA loadings

2004-06-23 Thread Laura Quinn
Hi,

I was wondering if there is a way of plotting smoothed contours of PCA
loadings onto a map. At the moment I have the loadings plotted as
positive/negative (red/blue) scaled circles centred around where the
physical stations are on a map - but I was wondering if there is a nicer
way of plotting this data, perhaps as contours of "regions of influence"
or somesuch?

Any suggestions would be gratefully received!

Thank you in advance,
Laura

__
[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 win.print

2004-06-23 Thread Uwe Ligges
Prof Brian Ripley wrote:
Do remember that you need to double backslashes in R strings ... see the 
rw-FAQ.  As I recall forward slashes work here too.

On Wed, 23 Jun 2004, Joy, Tom wrote:

I am trying to batch the printing of some graphs using win.print when I leave the 
printer option blank it prompts me for a printer each time and then works fine when I 
put the printer name in however using the following code I get the error below. Does 
the printer need to be locally installed or can it print to a network printer like I 
am trying to?
win.print(width=8, height=10.5,printer="\\LBPS\LBMARK_4200")
Error in devga(paste("win.print:", printer, sep = ""), width, height,  : 
   unable to start device devga

Try printer="LBPS\\LBMARK_4200"
I think it is only possible to specify names that are knwon by Windows 
to be installed printers.
Hence after installing the printer and calling it, e.g., LBMARK4200 on 
your system, you can say "printer = "LBMARK4200"

Uwe Ligges
__
[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] [Q] GET_DIM() crash on Windows only

2004-06-23 Thread Paul Roebuck
On Wed, 23 Jun 2004, Uwe Ligges wrote:

> Paul Roebuck wrote:
>
> > I have the following contrived code in package format.
> > On Solaris and Mac OS X, code runs just fine. On Windows,
> > it crashes the R environment with the "Send Bug Report"
> > dialog. I tried R 1.8.1 (Win2K) and R 1.9 (WinXP) binaries
> > with the same result. PCs otherwise appear properly
> > configured for creating R packages. Anything blatantly
> > wrong? Suggestions?
>
> Works for me (R-1.9.1, WinNT4.0), even with gctorture(TRUE).
> Did you use the recommended compiler and tools?

To the best of my knowledge, I did. I upgraded to R 1.9.1 to no
avail. What else should I look for at this point? Is there an
R package developer setup lint utility?



Here's my script:

@cls
@SETLOCAL
@set RBINDIR=C:\R\rw1091\bin
@set TOOLSBINDIR=C:\Rtools\bin
@set MINGWBINDIR=C:\MinGW\bin
@set PERLBINDIR=C:\Perl\bin
@set TEXBINDIR=C:\PROGRA~1\TeXLive\bin\win32
@set HCCBINDIR=C:\PROGRA~1\HTMLHE~1
@set 
PATH=%TOOLSBINDIR%;%RBINDIR%;%MINGWBINDIR%;%PERLBINDIR%;%TEXBINDIR%;%HCCBINDIR%;%WINDIR%\system32;%WINDIR%
@echo PATH=%PATH%
Rcmd build -binary getdim
Rcmd check getdim
@ENDLOCAL


Script output
-
PATH=C:\Rtools\bin;C:\R\rw1091\bin;C:\MinGW\bin;C:\Perl\bin;C:\PROGRA~1\TeXLive\
bin\win32;C:\PROGRA~1\HTMLHE~1;C:\WINDOWS\system32;C:\WINDOWS

Z:\R\examples\getdim>Rcmd build -binary getdim
* checking for file 'getdim/DESCRIPTION' ... OK
installing R.css in C:/tmp/Rbuild.2304


-- Making package getdim 
  adding build stamp to DESCRIPTION
  making DLL ...
  ... DLL made
  installing DLL
  installing R files
  installing man source files
  installing indices
  installing help
 >>> Building/Updating help pages for package 'getdim'
 Formats: text html latex example
  getdimtexthtmllatex   example
 >>> Building/Updating help pages for package 'getdim'
 Formats: chm
  getdimchm
Microsoft HTML Help Compiler 4.74.8702

Compiling z:\R\examples\getdim\getdim\chm\getdim.chm


Compile time: 0 minutes, 1 second
2   Topics
1   Local link
0   Internet links
1   Graphic


Created z:\R\examples\getdim\getdim\chm\getdim.chm, 20,587 bytes
Compression increased file by 9,197 bytes.
  adding MD5 sums

* DONE

* building 'getdim_1.0.zip'
  adding: getdim/ (stored 0%)
  adding: getdim/chtml/ (stored 0%)
  adding: getdim/chtml/getdim.chm (deflated 38%)
  adding: getdim/CONTENTS (deflated 20%)
  adding: getdim/DESCRIPTION (deflated 30%)
  adding: getdim/help/ (stored 0%)
  adding: getdim/help/AnIndex (deflated 13%)
  adding: getdim/help/getdim (deflated 45%)
  adding: getdim/html/ (stored 0%)
  adding: getdim/html/00Index.html (deflated 49%)
  adding: getdim/html/getdim.html (deflated 43%)
  adding: getdim/INDEX (stored 0%)
  adding: getdim/latex/ (stored 0%)
  adding: getdim/latex/getdim.tex (deflated 45%)
  adding: getdim/libs/ (stored 0%)
  adding: getdim/libs/getdim.dll (deflated 66%)
  adding: getdim/man/ (stored 0%)
  adding: getdim/man/getdim.Rd (deflated 30%)
  adding: getdim/MD5 (deflated 37%)
  adding: getdim/Meta/ (stored 0%)
  adding: getdim/Meta/hsearch.rds (deflated 64%)
  adding: getdim/Meta/Rd.rds (deflated 66%)
  adding: getdim/R/ (stored 0%)
  adding: getdim/R/getdim (deflated 37%)
  adding: getdim/R-ex/ (stored 0%)
  adding: getdim/R-ex/getdim.R (deflated 23%)


Z:\R\examples\getdim>Rcmd check getdim
* checking for working latex ... OK
* using log directory 'Z:/R/examples/getdim/getdim.Rcheck'
* checking for file 'getdim/DESCRIPTION' ... OK
* checking if this is a source package ... OK

installing R.css in Z:/R/examples/getdim/getdim.Rcheck


-- Making package getdim 
  adding build stamp to DESCRIPTION
  making DLL ...
  ... DLL made
  installing DLL
  installing R files
  installing man source files
  installing indices
  installing help
 >>> Building/Updating help pages for package 'getdim'
 Formats: text html latex example
  getdimtexthtmllatex   example
 >>> Building/Updating help pages for package 'getdim'
 Formats: chm
  adding MD5 sums

* DONE

* checking package directory ... OK
* checking for portable file names ... OK
* checking DESCRIPTION meta-information ... OK
* checking package dependencies ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for syntax errors ... OK
* checking R files for library.dynam ... OK
* checking S3 generic/method consistency ... OK
* checking for replacement functions with final arg not named 'value' ...
OK
* checking foreign function calls ... OK
* checking Rd files ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking for CRLF line endings in C sources/headers ... OK
* creating getdim-Ex.R ... OK
* checking examples ... ERROR
Running examples in getdim-E

Re: [R] Perl--R interface

2004-06-23 Thread Paul Roebuck
On Wed, 23 Jun 2004, XIAO LIU wrote:

> My R is 1.8.1 in Linux.  How can I call R in Perl process?
> And call Perl from R?
>

This is only one direction but worth a look as an
alternative.



--
SIGSIG -- signature too long (core dumped)

__
[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] converting apply output

2004-06-23 Thread Andrew Beckerman
Thanks eric... I figured this routine out as well.
cvt<-function(dat){
x<-as.list(rep(0,dim(dat)[2]))
for(i in 1:dim(dat)[2]){
x[[i]]<-dat[,i]
x}}
# get ragged array of 1's
dat<-apply(mat,2,function(x) which(x==1))
# deal with this using cvt to creat list
if(is.null(dim(dat))) dat2<-dat else dat2<-cvt(dat)
On 23 Jun 2004, at 13:13, Eric Lecoutre wrote:
Hi,
Why not try with the data.frame structure, wich internally yet  
consists in a list:

> lapply(as.data.frame(m1),function(x) which(x==1))
$V1
[1] 8 9
$V2
[1]  9 10
[...]
Eric
At 12:53 23/06/2004, Andrew Beckerman wrote:
Hi -
platform powerpc-apple-darwin6.8
status
major1
minor9.0
year 2004
I am trying to deal with the output of apply().  As indicated, when  
each call to 'FUN' returns a vector of length 'n', then 'apply'
returns an array of dimension 'c(n, dim(X)[MARGIN])'.  However, I  
would like this to be a list in the same format as is produced when  
'FUN' return vectors of different lengths ('apply'   returns a list  
of length 'dim(X)[MARGIN]').

e.g.
tt1<-c(0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,  
0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, ,0 ,0 ,0 ,0 ,0  
,0 ,1 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0  
,0 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,  
0, 0, 0, 0, 0, 0, 1, 0, 1, 0)
m1<-matrix(tt1,10,10)
out<-apply(m1,2,function(x) which(x==1))

produces an array,
> out
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]897867666 7
[2,]9   108988   10   107 9
but I would like out as a list of 10 elements with two elements in  
each, e.g.

[[1]]
[1]  8 9
[[2]]
[1] 9 10
etc.
I have tried apply(out,2,function(x) list(x))), but the subsrcripting  
is not equal to the pattern when FUN returns a vectors of different  
length.  Any help would be appreciated.

Cheers
andrew
__
[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
Eric Lecoutre
UCL /  Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve
Belgium
tel: (+32)(0)10473050
[EMAIL PROTECTED]
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre
If the statistics are boring, then you've got the wrong numbers.  
-Edward Tufte


 
-
Dr. Andrew Beckerman
Department of Animal and Plant Sciences, University of Sheffield,
Alfred Denny Building, Western Bank, Sheffield S10 2TN, UK
ph +44 (0)114 222 0026; fx +44 (0)114 222 0002
http://www.shef.ac.uk/beckslab
 
--

__
[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] Sorting elements in a data.frame

2004-06-23 Thread Dan Bolser

Hi,

I have data like this

print(x)

ID  VAL1VAL2
1   2   6
2   4   9
3   45  12
4   99  44

What I would like is data like this...

ID  VAL1VAL2
1   2   6
2   4   9
3   12  45
4   44  99


So that my analysis of the ratio VAL2/VAL1 is somehow uniform.

Any advice is welcome!

Dan.

__
[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] Sorting elements in a data.frame

2004-06-23 Thread Liaw, Andy
Do you mean:

> pmax(x[,1], x[,2]) / pmin(x[,1], x[,2])
[1] 3.00 2.25 3.75 2.25

??

Andy

> From: Dan Bolser
> 
> Hi,
> 
> I have data like this
> 
> print(x)
> 
> IDVAL1VAL2
> 1 2   6
> 2 4   9
> 3 45  12
> 4 99  44
> 
> What I would like is data like this...
> 
> IDVAL1VAL2
> 1 2   6
> 2 4   9
> 3 12  45
> 4 44  99
> 
> 
> So that my analysis of the ratio VAL2/VAL1 is somehow uniform.
> 
> Any advice is welcome!
> 
> Dan.

__
[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] Sorting elements in a data.frame

2004-06-23 Thread Dan Bolser
On Wed, 23 Jun 2004, Liaw, Andy wrote:

>Do you mean:
>
>> pmax(x[,1], x[,2]) / pmin(x[,1], x[,2])


Magic! 

I needed a p!





>Andy
>
>> From: Dan Bolser
>> 
>> Hi,
>> 
>> I have data like this
>> 
>> print(x)
>> 
>> ID   VAL1VAL2
>> 12   6
>> 24   9
>> 345  12
>> 499  44
>> 
>> What I would like is data like this...
>> 
>> ID   VAL1VAL2
>> 12   6
>> 24   9
>> 312  45
>> 444  99
>> 
>> 
>> So that my analysis of the ratio VAL2/VAL1 is somehow uniform.
>> 
>> Any advice is welcome!
>> 
>> Dan.
>
>
>--
>Notice:  This e-mail message, together with any attachments, contains information of 
>Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), 
>and/or its affiliates (which may be known outside the United States as Merck Frosst, 
>Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be confidential, 
>proprietary copyrighted and/or legally privileged. It is intended solely for the use 
>of the individual or entity named on this message.  If you are not the intended 
>recipient, and have received this message in error, please notify us immediately by 
>reply e-mail and then delete it from your system.
>--
>

__
[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] assigning from multiple return values

2004-06-23 Thread Jack Tanner
I know that if I have a function that returns multiple values, I should
do return(list(foo, bar)). But what do I do on the recieving end?
fn <- function(x) {
  return(list(foo, bar))
}
I know that at this point I could say
values.list <- fn(x)
and then access
values.list[1]
values.list[2]
But that's hideous. I'd rather be able to say something like
list(local_foo, local_bar) <- fn(x)
and have the right thing happen. I realize that it's my responsibility
to not screw up and say instead
list(local_bar, local_foo)
Any suggestions?
-JT
__
[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] assigning from multiple return values

2004-06-23 Thread Paul Roebuck
On Wed, 23 Jun 2004, Jack Tanner wrote:

> I know that if I have a function that returns multiple values, I should
> do return(list(foo, bar)). But what do I do on the recieving end?
>
> fn <- function(x) {
>return(list(foo, bar))
> }
>
> I know that at this point I could say
>
> values.list <- fn(x)
>
> and then access
>
> values.list[1]
> values.list[2]
>
> But that's hideous. I'd rather be able to say something like
>
> list(local_foo, local_bar) <- fn(x)
>
> and have the right thing happen. I realize that it's my responsibility
> to not screw up and say instead
>
> list(local_bar, local_foo)
>
> Any suggestions?
>

How about naming the list elements for clarity then?

fn <- function(x) {
foo <- x;
bar <- 1/x;
return(list(foo = foo,
bar = bar));
}

x <- 10;
values.list <- fn(x);
print(values.list$foo);
print(values.list$bar);


--
SIGSIG -- signature too long (core dumped)

__
[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] Sphericity test

2004-06-23 Thread Eduardo Dutra de Armas
Hi R-users
Does anybody know if there are functions or packages in R for sphericity
tests like Bartlett's or Mauchly's?

Thanks!

__
Eng. Agr., M.Sc. Eduardo Dutra de Armas
__
Centro de Energia Nuclear na Agricultura (CENA/USP)
Laboratório de Ecotoxicologia
Av.Centenário 303, C.P. 96, CEP 13400-970, Piracicaba, SP, Brasil
Fone: (55-19)34294761 - Fax: (55-19)34294610 - Cel: (55-19)81155564
(Áreas de atuação: Poluição de solo e água, Dinâmica Ambiental de
pesticidas, Biodegradação, Microbiologia Ambiental)
__


---



 

[[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] assigning from multiple return values

2004-06-23 Thread Gabor Grothendieck

Here are two approaches assuming foo is "zz" and bar is 3.

FIRST

You could pass the return variables in the argument list and then
assign them in the caller's frame like this:

fn <- function(x,y) {
assign(as.character(substitute(x)), "zz", sys.frame(-1))
assign(as.character(substitute(y)), 3, sys.frame(-1))
}
fn(a,b)  # sets a to "zz" and b to 3

SECOND

You can make this a bit prettier, though not perfect, like this:


"list2<-" <- function(x,y,value) {
assign(as.character(substitute(y)), value[[2]], sys.frame(-1))
value[[1]]
}
fn <- function()list("zz",3)
a <- 1 # first arg must exist prior to invoking list2. Its value not important.
list2(a,b) <- fn()


The two problems with list2 are:

1. the first argument must exist prior to invoking list2 although its
actual value is immaterial since it just gets overwritten anyways.

2. It only works for 2 args although you could write a list3, list4, etc.

Maybe someone could comment on these deficiencies.


Jack Tanner  hotmail.com> writes:

: 
: I know that if I have a function that returns multiple values, I should
: do return(list(foo, bar)). But what do I do on the recieving end?
: 
: fn <- function(x) {
:return(list(foo, bar))
: }
: 
: I know that at this point I could say
: 
: values.list <- fn(x)
: 
: and then access
: 
: values.list[1]
: values.list[2]
: 
: But that's hideous. I'd rather be able to say something like
: 
: list(local_foo, local_bar) <- fn(x)
: 
: and have the right thing happen. I realize that it's my responsibility
: to not screw up and say instead
: 
: list(local_bar, local_foo)
: 
: Any suggestions?
: 
: -JT
:

__
[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] assigning from multiple return values

2004-06-23 Thread Liaw, Andy
My $0.02:

If Jack feels that the fact that functions usually return a single list, and
one needs to access the components of the list separately, is somehow
hideous, then I'd rather suggest that R is perhaps the wrong language for
him.

To me the suggested `workarounds' are by far much more hideous...  They turn
perfectly tranparent code into...  gee, I don't even know how to begin
describing them...

Andy

> From: Gabor Grothendieck
> 
> 
> Here are two approaches assuming foo is "zz" and bar is 3.
> 
> FIRST
> 
> You could pass the return variables in the argument list and then
> assign them in the caller's frame like this:
> 
> fn <- function(x,y) {
>   assign(as.character(substitute(x)), "zz", sys.frame(-1))
>   assign(as.character(substitute(y)), 3, sys.frame(-1))
> }
> fn(a,b)  # sets a to "zz" and b to 3
> 
> SECOND
> 
> You can make this a bit prettier, though not perfect, like this:
> 
> 
> "list2<-" <- function(x,y,value) {
>   assign(as.character(substitute(y)), value[[2]], sys.frame(-1))
>   value[[1]]
> }
> fn <- function()list("zz",3)
> a <- 1 # first arg must exist prior to invoking list2. Its 
> value not important.
> list2(a,b) <- fn()
> 
> 
> The two problems with list2 are:
> 
> 1. the first argument must exist prior to invoking list2 although its
> actual value is immaterial since it just gets overwritten anyways.
> 
> 2. It only works for 2 args although you could write a list3, 
> list4, etc.
> 
> Maybe someone could comment on these deficiencies.
> 
> 
> Jack Tanner  hotmail.com> writes:
> 
> : 
> : I know that if I have a function that returns multiple 
> values, I should
> : do return(list(foo, bar)). But what do I do on the recieving end?
> : 
> : fn <- function(x) {
> :return(list(foo, bar))
> : }
> : 
> : I know that at this point I could say
> : 
> : values.list <- fn(x)
> : 
> : and then access
> : 
> : values.list[1]
> : values.list[2]
> : 
> : But that's hideous. I'd rather be able to say something like
> : 
> : list(local_foo, local_bar) <- fn(x)
> : 
> : and have the right thing happen. I realize that it's my 
> responsibility
> : to not screw up and say instead
> : 
> : list(local_bar, local_foo)
> : 
> : Any suggestions?
> : 
> : -JT
> :
> 
> __
> [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] [Q] GET_DIM() crash on Windows only

2004-06-23 Thread Uwe Ligges
Paul Roebuck wrote:
On Wed, 23 Jun 2004, Uwe Ligges wrote:

Paul Roebuck wrote:

I have the following contrived code in package format.
On Solaris and Mac OS X, code runs just fine. On Windows,
it crashes the R environment with the "Send Bug Report"
dialog. I tried R 1.8.1 (Win2K) and R 1.9 (WinXP) binaries
with the same result. PCs otherwise appear properly
configured for creating R packages. Anything blatantly
wrong? Suggestions?
Works for me (R-1.9.1, WinNT4.0), even with gctorture(TRUE).
Did you use the recommended compiler and tools?

To the best of my knowledge, I did. I upgraded to R 1.9.1 to no
avail. What else should I look for at this point? Is there an
R package developer setup lint utility?

Here's my script:
@cls
@SETLOCAL
@set RBINDIR=C:\R\rw1091\bin
@set TOOLSBINDIR=C:\Rtools\bin
@set MINGWBINDIR=C:\MinGW\bin
@set PERLBINDIR=C:\Perl\bin
@set TEXBINDIR=C:\PROGRA~1\TeXLive\bin\win32
@set HCCBINDIR=C:\PROGRA~1\HTMLHE~1
@set 
PATH=%TOOLSBINDIR%;%RBINDIR%;%MINGWBINDIR%;%PERLBINDIR%;%TEXBINDIR%;%HCCBINDIR%;%WINDIR%\system32;%WINDIR%
@echo PATH=%PATH%
Rcmd build -binary getdim
"--binary" is documented, but it should not matter in this case.

Rcmd check getdim
@ENDLOCAL
Script output
-
PATH=C:\Rtools\bin;C:\R\rw1091\bin;C:\MinGW\bin;C:\Perl\bin;C:\PROGRA~1\TeXLive\
bin\win32;C:\PROGRA~1\HTMLHE~1;C:\WINDOWS\system32;C:\WINDOWS
Since there is no further error message, it seems to be OK.
Which version of gcc are you using - and which runtime version?
You might want to send me both the source and the binary version of your 
package in a private message, and I'll try some further checks

 Uwe Ligges

Z:\R\examples\getdim>Rcmd build -binary getdim
* checking for file 'getdim/DESCRIPTION' ... OK
installing R.css in C:/tmp/Rbuild.2304
-- Making package getdim 
  adding build stamp to DESCRIPTION
  making DLL ...
  ... DLL made
  installing DLL
  installing R files
  installing man source files
  installing indices
  installing help
 >>> Building/Updating help pages for package 'getdim'
 Formats: text html latex example
  getdimtexthtmllatex   example
 >>> Building/Updating help pages for package 'getdim'
 Formats: chm
  getdimchm
Microsoft HTML Help Compiler 4.74.8702
Compiling z:\R\examples\getdim\getdim\chm\getdim.chm
Compile time: 0 minutes, 1 second
2   Topics
1   Local link
0   Internet links
1   Graphic
Created z:\R\examples\getdim\getdim\chm\getdim.chm, 20,587 bytes
Compression increased file by 9,197 bytes.
  adding MD5 sums
* DONE
* building 'getdim_1.0.zip'
  adding: getdim/ (stored 0%)
  adding: getdim/chtml/ (stored 0%)
  adding: getdim/chtml/getdim.chm (deflated 38%)
  adding: getdim/CONTENTS (deflated 20%)
  adding: getdim/DESCRIPTION (deflated 30%)
  adding: getdim/help/ (stored 0%)
  adding: getdim/help/AnIndex (deflated 13%)
  adding: getdim/help/getdim (deflated 45%)
  adding: getdim/html/ (stored 0%)
  adding: getdim/html/00Index.html (deflated 49%)
  adding: getdim/html/getdim.html (deflated 43%)
  adding: getdim/INDEX (stored 0%)
  adding: getdim/latex/ (stored 0%)
  adding: getdim/latex/getdim.tex (deflated 45%)
  adding: getdim/libs/ (stored 0%)
  adding: getdim/libs/getdim.dll (deflated 66%)
  adding: getdim/man/ (stored 0%)
  adding: getdim/man/getdim.Rd (deflated 30%)
  adding: getdim/MD5 (deflated 37%)
  adding: getdim/Meta/ (stored 0%)
  adding: getdim/Meta/hsearch.rds (deflated 64%)
  adding: getdim/Meta/Rd.rds (deflated 66%)
  adding: getdim/R/ (stored 0%)
  adding: getdim/R/getdim (deflated 37%)
  adding: getdim/R-ex/ (stored 0%)
  adding: getdim/R-ex/getdim.R (deflated 23%)
Z:\R\examples\getdim>Rcmd check getdim
* checking for working latex ... OK
* using log directory 'Z:/R/examples/getdim/getdim.Rcheck'
* checking for file 'getdim/DESCRIPTION' ... OK
* checking if this is a source package ... OK
installing R.css in Z:/R/examples/getdim/getdim.Rcheck
-- Making package getdim 
  adding build stamp to DESCRIPTION
  making DLL ...
  ... DLL made
  installing DLL
  installing R files
  installing man source files
  installing indices
  installing help
 >>> Building/Updating help pages for package 'getdim'
 Formats: text html latex example
  getdimtexthtmllatex   example
 >>> Building/Updating help pages for package 'getdim'
 Formats: chm
  adding MD5 sums
* DONE
* checking package directory ... OK
* checking for portable file names ... OK
* checking DESCRIPTION meta-information ... OK
* checking package dependencies ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for syntax errors ... OK
* checking R files for library.dynam ... OK
* checking S3 generic/method consistency ... OK
* checking for replacement functions with final arg not named 'value' ...
OK
* checking foreign function calls ... OK
* checking 

Re: [R] assigning from multiple return values

2004-06-23 Thread Peter Dalgaard
"Liaw, Andy" <[EMAIL PROTECTED]> writes:

> My $0.02:
> 
> If Jack feels that the fact that functions usually return a single list, and
> one needs to access the components of the list separately, is somehow
> hideous, then I'd rather suggest that R is perhaps the wrong language for
> him.
> 
> To me the suggested `workarounds' are by far much more hideous...  They turn
> perfectly tranparent code into...  gee, I don't even know how to begin
> describing them...

I'm not sure that the idea of multiple assignment as such is all that
horrid. Other languages have them and it's actually kind of fun to see
if you can come up with a neat implementation. 

However, Gabor is definitely on the wrong track with list()<- It is
the kind of thing that looks like a good idea initially, but if you
think things through from a consistency viewpoint, you realize that it
doesn't quite make sense. Replacement functions are just that -
replacement functions. They logically require that there is an object
within which there is something to replace.


-- 
   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] Tick marks in xyplot

2004-06-23 Thread Patrick Connolly
On Wed, 23-Jun-2004 at 07:32AM -0500, Deepayan Sarkar wrote:

[...]

|> 1. You can specify the limits, tick positions, and axis labels 
|> individually for each panel (see documentation for 'scales' in ?xyplot; 
|> all the relevant components - at, lab, etc - can be lists). 

How difficult would it be to make mgp one of the 'relevant
components'?  I often find I'd like to decrease the mgp[2] setting.  I
think that's the only reason why I'd like to have mgp in the list, so
if there's a smarter way of achieving that, mgp would be unnecessary.

Is there a smarter way?

-- 
Patrick Connolly
HortResearch
Mt Albert
Auckland
New Zealand 
Ph: +64-9 815 4200 x 7188
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~

__
[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] assigning from multiple return values

2004-06-23 Thread Jack Tanner
Rolf Turner wrote:
	> fn <- function(x) {
		list(local_foo=foo, local_bar=bar)
	}
 

OK, that works nicely. (And thanks to Paul Roebuck, who mentioned the
values.list$foo notation.)
(the ``return(...)'' is brought to you by your Department of
Redundancy Department.)
 

Aha! LISP reards its head. So what happens if I do
fn <- function(x) {
 some stuff
 ...
 end of stuff
 list(foo = foo, bar = bar)
}
return.value <- fn(x)
Will return.value ever contain any residuals from "stuff", or will it
always be exactly the result of the last statement, list(foo...) here?
The very fact that you are talking about ``multiple values''
indicates that you're not really understanding what's going on.
Functions in R always return just ***one*** value.  That value is an
object which may have an arbitrarily complicated (list structure).
Related objects get bundled up into lists, giving you just one object
to deal with.  Then you can pass that one object to another function,
which can then pick apart that object and use the components in the
appropriate way without you, the user, having to fiddle with them.
 

Fine, but the whole notion of loose coupling goes out the window if
you're passing lists of related (but very different) objects from
function to function, and each function has to be aware of the order of
the items in the list.
Liaw, Andy wrote:
If Jack feels that the fact that functions usually return a single 
list, and
one needs to access the components of the list separately, is somehow
hideous
I don't; I think that this is fine when you can access the components of
the list by name only, without regard to order.
Thanks to all for your help.
__
[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] Error message handling

2004-06-23 Thread Kang . Changku




Dear, R experts.
Does anybody have experience with 'optim' function?

I have an error message as the following.

Error in optim(transcoefs, fn = hfdeviance, gr = hfdeviance.grad, method
= "BFGS",  :
initial value in vmmin is not finite

I want to make a comment when this happen.
Is there way I can put *my* message after this error occur?

Thanks in advance

+
Changku Kang
National Center for Environmental Assessment
EPA  (B211F)
919-541-1396
919-541-0245 (fax)
[EMAIL PROTECTED]

Graduate Student
Department of Statistics, NCSU
[EMAIL PROTECTED]
919-513-2956
+

__
[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] Tick marks in xyplot

2004-06-23 Thread Deepayan Sarkar
Quoting Patrick Connolly <[EMAIL PROTECTED]>:

> On Wed, 23-Jun-2004 at 07:32AM -0500, Deepayan Sarkar wrote:
> 
> [...]
> 
> |> 1. You can specify the limits, tick positions, and axis labels 
> |> individually for each panel (see documentation for 'scales' in ?xyplot; 
> |> all the relevant components - at, lab, etc - can be lists). 
> 
> How difficult would it be to make mgp one of the 'relevant
> components'?  I often find I'd like to decrease the mgp[2] setting.  I
> think that's the only reason why I'd like to have mgp in the list, so
> if there's a smarter way of achieving that, mgp would be unnecessary.

These (and other similar things) are currently hard-coded, but I have plans to
make these part of the lattice settings eventually. This is completely
vapourware right now, but I have hopes of getting it done in time for R 2.0.0.

If you mean different values of these for different panels though, I don't think
 that's ever going to happen.

Deepayan

__
[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] A way to list only variables or functions?

2004-06-23 Thread Patrick Connolly
On Mon, 21-Jun-2004 at 03:50PM +0100, Barry Rowlingson wrote:

|> Duncan Murdoch wrote:
|> 
|> 
|> > I seem to recall that S-PLUS has such a function, but I forget the
|> > name of it.   Probably R does too, on CRAN if not in the base
|> > packages.
|> 
|> objects.summary() I think it was.
|> 
|> It always bothered me that the Nth thing you teach Unix users is 'ls' 
|> and the N+1th thing is 'ls -l' (for very small N). Then you teach them 
|> R, and there's no 'ls -l' equivalent immediately obvious.
|> 
|>   Not sure what such a function could show, there being no permissions, 
|> or dates on R objects, but object.size() and class/mode at least would 
|> be useful.
|> 
|>   So is something like this in CRAN? I say +1 to putting it in the base 
|> packages

I hesitate to mention it again.  Last time I did there was minimal
interest.  However, the question has been asked again, so perhaps now
is different

I made myself a function in the S-PLUS days which I've modified to
work in R.  It involved adding another few functions to add dates to
objects.

This is the sort of output it gives:

Object Mode   Rows Cols LenDate   
 1 last.warning list   --   --1 NA/NA/NA  
 2 sim.notuff17C.df dataframe  100  9 9 09/06/2004
 3 box.sim  function   --   --1 04/06/2004
 4 box.simC function   --   --1 04/06/2004
 5 multi.simfunction   --   --1 04/06/2004
 6 multi.simC   function   --   --1 04/06/2004
 7 sim.100B function   --   --1 04/06/2004
 8 sim.100C function   --   --1 04/06/2004
 9 sim.100.df   dataframe  100  9 9 04/06/2004
10 sim.notuff17.df  dataframe  100  9 9 04/06/2004
11 sim.notuff.dfdataframe  100  9 9 04/06/2004
12 sim.tuff.df  dataframe  100  9 9 04/06/2004
13 aa   numeric100  9   900 03/06/2004
14 sim.100A function   --   --1 03/06/2004
15 sim.100  function   --   --1 01/06/2004
16 develop.df   dataframe  161  7 7 28/05/2004
17 glm.both function   --   --1 24/05/2004
18 lm.gall  function   --   --1 24/05/2004
19 aphidgall.df dataframe  79   4 4 12/05/2004
20 pears.gall   function   --   --1 13/11/2003
21 glm.gallEPS  function   --   --1 27/08/2003

I've toyed with the idea of adding an object size column but it's not
important enough for my use.  Since I revisit projects over a period
of years at times, the date is very useful information -- in fact,
it's the main reason why I wrote it.

My code is not elegant enough for an esteemed place on CRAN.  I could
make it a lot better myself if I spent the time on it, but it works
well enough for me as it is, so in that sense, it ain't broke.
However, if anyone is interested in having such functionality my code
could be a good starting point.

Best

-- 
Patrick Connolly
HortResearch
Mt Albert
Auckland
New Zealand 
Ph: +64-9 815 4200 x 7188
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~

__
[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] nlme questions (e.g., specifying group membership, changing options)

2004-06-23 Thread [EMAIL PROTECTED]

I'm trying to better understand the nlme package and have a few questions.

 

1.) 

Other than using various coding strategies (e.g., dummy coding, effect coding), is 
there a way to identify group membership (i.e., treatment) directly? For example, the 
following code will fit a two group logistic growth curve (where 'Score' is repeatedly 
measured over 'Time' for each of the individuals (ID)):

 

nlme(Score ~ (ALPHA + Group)/(1+exp(-(GAMMA + Group)*(Time - (BETA+Group,

data=LE,

fixed=ALPHA + BETA + GAMMA ~ 1,

random=ALPHA + BETA + GAMMA ~ 1,

groups=~ID,

start = c(ALPHA = 1, BETA = 3.25, GAMMA = 2.5))



Rather than specifying the effect of Group in such a manner, is there a simpler way to 
identify group membership in order to test the effect of group differences on the 
parameters of the model? I thought (removing the dummy codes and) specifying group 
membership by: 'groups=~ID/Groups' might work, but an error is returned. I also 
thought specifying group membership by :'fixed=ALPHA + BETA + GAMMA ~ 1' might work, 
but an error is also returned.  

 

2.) 

When will, that is under what circumstances, will there be something different than 
'~1' on the right hand side of the 'fixed' and 'random' specification lines?

 

3.)

Given that I figure out a way to specify group membership/treatment, how are starting 
values for both groups specified? Can the covariance structure also be given starting 
values?

 

Sorry for what might turn out to be simply questions. But, as of yet I've not been 
able to understand exactly what is going on. Thanks for any help you might be able to 
provide.

Have a good one,

Ken



-


[[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


[R] anova

2004-06-23 Thread fciclone
Could someone please tell me if it is a way to define 
the number of decimals (for example 4 digits) in a 
presentation of anova() results. I couldn't apply round
()function.

Thanks in advance.
Alex
 
__
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - É grátis!
http://antipopup.uol.com.br/

__
[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] anova

2004-06-23 Thread Ulises Mora Alvarez
Hi!

options(digits = 5)

Good look.

On Wed, 23 Jun 2004, fciclone wrote:

> Could someone please tell me if it is a way to define 
> the number of decimals (for example 4 digits) in a 
> presentation of anova() results. I couldn't apply round
> ()function.
> 
> Thanks in advance.
> Alex
>  
> __
> Acabe com aquelas janelinhas que pulam na sua tela.
> AntiPop-up UOL - É grátis!
> http://antipopup.uol.com.br/
> 
> __
> [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
> 

-- 
Ulises M. Alvarez
LAB. DE ONDAS DE CHOQUE
FISICA APLICADA Y TECNOLOGIA AVANZADA
UNAM
[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] assigning from multiple return values

2004-06-23 Thread Gabor Grothendieck

I think I've found a workaround that avoids the two problems in the
replacement function approach.With the definitions of list
and [<-.result shown, one can write list[a,b] on the
left side of an assignment where the right side of the assignment
evaluates to a list of the same length (or if the list on the right
side is shorter then the otherwise unfilled variables are set to NA and
if the list on the right side is longer the excess entries are ignored).   
Unlike the previous workaround using a replacement function, one
can have a variable number of arguments to list[] and the first 
argument to list[] no longer has to be predefined.

list <- structure(NA,class="result")
"[<-.result" <- function(x,...,value) {
   args <- as.list(match.call())
   args <- args[-c(1:2,length(args))]
   length(value) <- length(args)
   for(i in seq(along=args))
  eval(substitute(x <- v,list(x=args[[i]],v=value[[i]])),env=sys.frame(-1))
   x
}

# it is used like this:

x <- 1:4
fn <- function() list("zz",99)
list[a,x[2]] <- fn()






Gabor Grothendieck  myway.com> writes:

: 
: Here are two approaches assuming foo is "zz" and bar is 3.
: 
: FIRST
: 
: You could pass the return variables in the argument list and then
: assign them in the caller's frame like this:
: 
: fn <- function(x,y) {
:   assign(as.character(substitute(x)), "zz", sys.frame(-1))
:   assign(as.character(substitute(y)), 3, sys.frame(-1))
: }
: fn(a,b)  # sets a to "zz" and b to 3
: 
: SECOND
: 
: You can make this a bit prettier, though not perfect, like this:
: 
: "list2<-" <- function(x,y,value) {
:   assign(as.character(substitute(y)), value[[2]], sys.frame(-1))
:   value[[1]]
: }
: fn <- function()list("zz",3)
: a <- 1 # first arg must exist prior to invoking list2. Its value not 
important.
: list2(a,b) <- fn()
: 
: The two problems with list2 are:
: 
: 1. the first argument must exist prior to invoking list2 although its
: actual value is immaterial since it just gets overwritten anyways.
: 
: 2. It only works for 2 args although you could write a list3, list4, etc.
: 
: Maybe someone could comment on these deficiencies.
: 
: Jack Tanner  hotmail.com> writes:
: 
: : 
: : I know that if I have a function that returns multiple values, I should
: : do return(list(foo, bar)). But what do I do on the recieving end?
: : 
: : fn <- function(x) {
: :return(list(foo, bar))
: : }
: : 
: : I know that at this point I could say
: : 
: : values.list <- fn(x)
: : 
: : and then access
: : 
: : values.list[1]
: : values.list[2]
: : 
: : But that's hideous. I'd rather be able to say something like
: : 
: : list(local_foo, local_bar) <- fn(x)
: : 
: : and have the right thing happen. I realize that it's my responsibility
: : to not screw up and say instead
: : 
: : list(local_bar, local_foo)
: : 
: : Any suggestions?
: : 
: : -JT
: :
: 
: __
: R-help  stat.math.ethz.ch 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] truncated normal regression

2004-06-23 Thread B. Dan Wood
Does anyone have example code for a truncated normal regression using the
survival package? Or any other package? Thanks.

 

 

 

 

 

__
[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] assigning from multiple return values

2004-06-23 Thread Gabor Grothendieck


Just a few more examples:

# swap a and b without explicitly creating a temporary
a <- 1; b <- 2
list[a,b] <- list(b,a)

# get eigenvectors and eigenvalues
list[eval, evec] <- eigen(cbind(1,1:3,3:1))

# get today's month, day, year
require(chron)
list[Month, Day, Year] <- month.day.year(unclass(Sys.Date()))

# get first two components of linear model ignoring rest
list[Coef, Resid] <- lm(rnorm(10) ~ seq(10))





Gabor Grothendieck  myway.com> writes:

: 
: I think I've found a workaround that avoids the two problems in the
: replacement function approach.With the definitions of list
: and [<-.result shown, one can write list[a,b] on the
: left side of an assignment where the right side of the assignment
: evaluates to a list of the same length (or if the list on the right
: side is shorter then the otherwise unfilled variables are set to NA and
: if the list on the right side is longer the excess entries are ignored).   
: Unlike the previous workaround using a replacement function, one
: can have a variable number of arguments to list[] and the first 
: argument to list[] no longer has to be predefined.
: 
: list <- structure(NA,class="result")
: "[<-.result" <- function(x,...,value) {
:args <- as.list(match.call())
:args <- args[-c(1:2,length(args))]
:length(value) <- length(args)
:for(i in seq(along=args))
:   eval(substitute(x <- v,list(x=args[[i]],v=value[[i]])),env=sys.frame(-
1))
:x
: }
: 
: # it is used like this:
: 
: x <- 1:4
: fn <- function() list("zz",99)
: list[a,x[2]] <- fn()
: 
: Gabor Grothendieck  myway.com> writes:
: 
: : 
: : Here are two approaches assuming foo is "zz" and bar is 3.
: : 
: : FIRST
: : 
: : You could pass the return variables in the argument list and then
: : assign them in the caller's frame like this:
: : 
: : fn <- function(x,y) {
: : assign(as.character(substitute(x)), "zz", sys.frame(-1))
: : assign(as.character(substitute(y)), 3, sys.frame(-1))
: : }
: : fn(a,b)  # sets a to "zz" and b to 3
: : 
: : SECOND
: : 
: : You can make this a bit prettier, though not perfect, like this:
: : 
: : "list2<-" <- function(x,y,value) {
: : assign(as.character(substitute(y)), value[[2]], sys.frame(-1))
: : value[[1]]
: : }
: : fn <- function()list("zz",3)
: : a <- 1 # first arg must exist prior to invoking list2. Its value not 
: important.
: : list2(a,b) <- fn()
: : 
: : The two problems with list2 are:
: : 
: : 1. the first argument must exist prior to invoking list2 although its
: : actual value is immaterial since it just gets overwritten anyways.
: : 
: : 2. It only works for 2 args although you could write a list3, list4, etc.
: : 
: : Maybe someone could comment on these deficiencies.
: : 
: : Jack Tanner  hotmail.com> writes:
: : 
: : : 
: : : I know that if I have a function that returns multiple values, I should
: : : do return(list(foo, bar)). But what do I do on the recieving end?
: : : 
: : : fn <- function(x) {
: : :return(list(foo, bar))
: : : }
: : : 
: : : I know that at this point I could say
: : : 
: : : values.list <- fn(x)
: : : 
: : : and then access
: : : 
: : : values.list[1]
: : : values.list[2]
: : : 
: : : But that's hideous. I'd rather be able to say something like
: : : 
: : : list(local_foo, local_bar) <- fn(x)
: : : 
: : : and have the right thing happen. I realize that it's my responsibility
: : : to not screw up and say instead
: : : 
: : : list(local_bar, local_foo)
: : : 
: : : Any suggestions?
: : : 
: : : -JT
: : :
: : 
: : __
: : R-help  stat.math.ethz.ch 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-help  stat.math.ethz.ch 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] Automatic routine - help

2004-06-23 Thread Richard A. O'Keefe
I note that ?min actually contains a relevant example:

plot(x, pmin(cH, pmax(-cH, x)), type='b', main= "Huber's function")
^^

It's always worth timing things.  The timing tests below are the best
of several repetitions, to avoid worries about things like paging and GC.

Make a data frame with 10 variables and 2000 cases.

> m <- matrix(rnorm(10*2000), ncol=10)
> colnames(m) <- LETTERS[1:10]
> z <- as.data.frame(m)

See how long it takes to just make a copy of z.

> system.time(w <- z+0)
[1] 0.08 0.01 0.16 0.00 0.00

See how long pmax(pmin(...)...) takes.

> system.time(w <- pmax(pmin(z, 1), 0))
[1] 0.08 0.01 0.16 0.00 0.00

See how long the z[z < 0] <- 0; z[z > 1] <- 1 trick takes.

> system.time({ w <- z; w[w < 0] <- 0; w[w > 1] <- 1 })
[1] 0.23 0.01 0.31 0.00 0.00

__
[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 handle twin peaks - normal distribution

2004-06-23 Thread Unung Istopo Hartanto
Hi R Users,

Sorry if its out of topic. I would like to ask you about twin peaks -
normal distribution. How R can handle it, any example to explain it in
R.

Thanks,

regards,

Unung

__
[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] Covered Labels

2004-06-23 Thread Jim Lemon
Martina Renninger wrote:
> Dear All!
>
>
>
> How can I cope with overlapping or covered labels (covered by labels
> from other data points) in plots?

This doesn't solve every such problem, but it has helped me in the past.
You will probably have to expand the xlim and ylim a bit to fit the extreme 
labels onto the plot.

Also, there seems to be a typo in the HTML help for dist(), mentioning 
as.matrix.dist() which should be as.matrix().

Jim
# thigmophobe returns the direction (as n|e|s|w) _away_ from
# the nearest point where x and y are vectors of 2D coordinates

thigmophobe<-function(x,y) {
 # get the current upper and lower limits of the plot
 plot.span<-par("usr")
 x.span<-plot.span[2] - plot.span[1]
 y.span<-plot.span[4] - plot.span[3]
 # if either axis is logarithmic, transform the values into logarithms
 if(par("xlog")) x<-log(x)
 if(par("ylog")) y<-log(y)
 # scale the values to the plot span
 # this avoids the numerically larger
 # axis dominating the distance measure
 x<-x/x.span
 y<-y/y.span
 # get the distance matrix as a full matrix
 xy.dist<-as.matrix(dist(cbind(x,y)))
 lenx<-length(x)
 nearest.index<-rep(0,lenx)
 for(index in 1:lenx)
  nearest.index[index]<-as.numeric(names(which.min(xy.dist[-index,index])))
 # get the x and y differences for each point to the nearest point
 xdiff<-x - x[nearest.index]
 ydiff<-y - y[nearest.index]
 # first set the east/west direction
 dir.ew<-ifelse(xdiff > 0,"e","w")
 # now do the north/south
 dir.ns<-ifelse(ydiff > 0,"n","s")
 dir.away<-ifelse(abs(xdiff)>abs(ydiff),dir.ew,dir.ns)
 return(dir.away)
}

# thigmophobe.labels positions labels at points so that they
# are most distant from the nearest other point, where the
# points are described as x and y coordinates.

thigmophobe.labels<-function(x,y,labels,...) {
 if(!missing(x) && !missing(y)) {
  lenx<-length(x)
  if(missing(labels)) labels<-as.character(1:lenx)
  dir.away<-thigmophobe(x,y)
  xadjust<-strwidth("M")
  yadjust<-strheight("M")*1.5
  text.adj<-rep(0,lenx)
  for(i in 1:lenx) {
   if(dir.away[i] == "n") {
y[i]<-y[i]+yadjust
text.adj[i]<-0.5
   }
   if(dir.away[i] == "e") {
x[i]<-x[i]+xadjust
text.adj[i]<-0
   }
   if(dir.away[i] == "s") {
y[i]<-y[i]-yadjust
text.adj[i]<-0.5
   }
   if(dir.away[i] == "w") {
x[i]<-x[i]-xadjust
text.adj[i]<-1
   }
  }
  text(x,y,labels,...)
 }
 else
  cat("Usage: thigmophobe.labels(x,y,labels=1:length(x),...)\n")
}
__
[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] assigning from multiple return values

2004-06-23 Thread Richard A. O'Keefe
Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
fn <- function(x,y) {
assign(as.character(substitute(x)), "zz", sys.frame(-1))
assign(as.character(substitute(y)), 3, sys.frame(-1))
}
fn(a,b)  # sets a to "zz" and b to 3

"list2<-" <- function(x,y,value) {
assign(as.character(substitute(y)), value[[2]], sys.frame(-1))
value[[1]]
}
fn <- function()list("zz",3)
a <- 1 # first arg must exist prior to invoking list2. Its value not important.
list2(a,b) <- fn()

There is still another way, which doesn't use substitute, as.character, or
assign.  Instead of returning two results, accept an extra argument which
is a function that decides what to do with them.

> f <- function(handler) { handler("zz", 3) }
> f(function(x, y) { a <<- x; b <<- y })
> a
[1] "zz"
> b
[1] 3
> g <- function() {
+ u <- v <- NULL # make it clear these are local to g
+ f(function(x,y) {u <<- x; v <<- y})
+ list(u, v)  # see what we got
+ }
> g()
[[1]]
[1] "zz"

[[2]]
[1] 3

Whenever I would have wanted to pass "a variable" to an R function,
this is what I do instead.  It works so well that I am still happily
ignorant of how to use substitute().  It's also much more compiler-friendly.

__
[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] Error message handling

2004-06-23 Thread Prof Brian Ripley
On Wed, 23 Jun 2004 [EMAIL PROTECTED] wrote:

> Dear, R experts.
> Does anybody have experience with 'optim' function?

Yes.

> I have an error message as the following.
> 
> Error in optim(transcoefs, fn = hfdeviance, gr = hfdeviance.grad, method
> = "BFGS",  :
> initial value in vmmin is not finite
> 
> I want to make a comment when this happen.

 Function 'fn' can return 'NA' or 'Inf' if the function cannot be
 evaluated at the supplied value, but the initial value must have a
 computable finite value of 'fn'. (Except for method '"L-BFGS-B"'
 where the values should always be finite.)

It's your error so you can control it (by not making the error).

> Is there way I can put *my* message after this error occur?

You can use try/tryCatch and similar constructs.  But it would be better
to use a valid starting value as optim asks, and you can so that by
calling hfdeviance(transcoefs) and checking it is finite.

-- 
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] Covered Labels

2004-06-23 Thread Prof Brian Ripley
On Thu, 24 Jun 2004, Jim Lemon wrote:

> Martina Renninger wrote:
> > Dear All!
> >
> >
> >
> > How can I cope with overlapping or covered labels (covered by labels
> > from other data points) in plots?
> 
> This doesn't solve every such problem, but it has helped me in the past.
> You will probably have to expand the xlim and ylim a bit to fit the extreme 
> labels onto the plot.
> 
> Also, there seems to be a typo in the HTML help for dist(), mentioning 
> as.matrix.dist() which should be as.matrix().

Not a typo: here is a function as.matrix.dist, try
getAnywhere("as.matrix.dist").  More elegant would be `the "dist" method
of as.matrix().'

-- 
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] R 1.9.0, special characters in variable names.

2004-06-23 Thread Sixten Borg
Hello all,

I upgraded from R 1.8.1 to 1.9.0 (Windows XP), and spotted an odd thing.

The last three letters in the Swedish alphabet are å, ä and ö. (In case they don't 
show correctly: they are a with a ring, a with two dots, and o with two dots (HTML: 
å  ä ö).

When I use these as variable names in a data.frame, odd things happen:
In R 1.8.1, å (å) doesn't work while the others do.
In R 1.9.0, ö (ö) doesn't work while the others do.

Please find examples below. It would be nice if all three could be used in variable 
names. At least in Sweden :-)

Thanks...
Sixten.

#
# R 1.9.0: ö is renamed to X.
#

> data.frame(a=1, å=2, ä=3, ö=4)
  a å ä X.
1 1 2 3  4
> version
 _  
platform i386-pc-mingw32
arch i386   
os   mingw32
system   i386, mingw32  
status  
major1  
minor9.0
year 2004   
month04 
day  12 
language R  
> 


#
# R 1.8.1: å is renamed to X.
#

> data.frame(a=1, å=2, ä=3, ö=4)
  a X. ä ö
1 1  2 3 4
> version
 _  
platform i386-pc-mingw32
arch i386   
os   mingw32
system   i386, mingw32  
status  
major1  
minor8.1
year 2003   
month11 
day  21 
language R  


#

__
[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