[R] best.svm

2005-05-24 Thread Stephen Choularton
Hi
 
I am trying to fit an svm to predict  speech recognition errors.  I am
using best.svm like this:
 
svm.model = best.svm(data[1:3000,1:23],data[1:3000,24],tunecontrol =
tune.control())
 
I got this:
 
 print(svm.model)
 
Call:
 best.svm(x = data[1:3000, 1:23], tunecontrol = tune.control(),
data[1:3000, 24]) 
 
Parameters:
   SVM-Type:  eps-regression 
 SVM-Kernel:  radial 
   cost:  1 
  gamma:  0.04347826 
epsilon:  0.1 
 
 
Number of Support Vectors:  970
 
But when I applied it:
 
 
 pred = predict(svm.model, data[3001:4000,1:23])
 pred[pred  .5] = 1 
 pred[pred = .5] = 0 
 t = table(pred,data[3001:4000,24])
 t

pred 0   1  
   1  65 935
 classAgreement(t)
$diag
[1] 0.065
 
$kappa
[1] 0
 
$rand
[1] 0.8783283
 
$crand
[1] 0
 
It didn’t produce really good results.
 
Will best.svm get me the best svm?  Have I given it the wrong
parameters?
 
Any help most welcome.
 
Stephen

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.

 

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Can't reproduce clusplot princomp results.

2005-05-24 Thread Bjørn-Helge Mevik
Thomas M. Parris writes:

 clusplot reports that the first two principal components explain
 99.7% of the variability.
[...]

 loadings(pca)
[...]
Comp.1 Comp.2 Comp.3 Comp.4
 SS loadings  1.00   1.00   1.00   1.00
 Proportion Var   0.25   0.25   0.25   0.25
 Cumulative Var   0.25   0.50   0.75   1.00

This has nothing to do with how much of the variability of the
original data that is captured by each component; it merely measures
the variability in the coefficients of the loading vectors (and they
are standardised to length one in princomp)

What you want to look at is pca$sdev, for instance something like

totvar - sum(pca$sdev^2)
rbind(explained var = pca$sdev^2,
  prop. expl. var = pca$sdev^2/totvar,
  cum.prop.expl.var = cumsum(pca$sdev^2)/totvar)
 Comp.1Comp.2  Comp.3   Comp.4
explained var 3.4093746 0.5785399 0.011560142 0.0005252824
prop. expl. var   0.8523437 0.1446350 0.002890036 0.0001313206
cum.prop.expl.var 0.8523437 0.9969786 0.999868679 1.00

And as you can see, two comps explain 99.7%. :-)

-- 
Bjørn-Helge Mevik

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] How to break an axis?

2005-05-24 Thread joerg van den hoff

Bo Peng wrote:

Dear list,

I need to plot four almost horizontal lines with y-values around
1,3,4, 400. If I plot them directly, the first three lines will be
indiscernible so I am thinking of breaking y-axis into two parts, one
with range (0,5), another (395,400). Is there an easy way to do this?

I can think of two ways: 
1. use two plots and draw axes manually. The plot margins, are however

difficult to adjust.
2. use one plot, adjust y-values of the lines and draw y-axis
manually. But, how would I break y-axis and add separation symbols
*on* yaxis? (By separation symbol, I mean something like
--//--

Many thanks in davance.
Bo

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


maybe something like

matplot(1:10, rep(1,10)%o%c(1,3,4), col=1:3, ylim = c(0,20), type='b')
par(new=T)
matplot(1:10, rep(400,10),axes=F,ann=F, col=4, ylim = c(0,400),type='b')
axis(4)
legend(par('usr')[2], par('usr')[4], bg='white',   xjust=1, c('left 
axis', 'left axis', 'left axis', 'right axis'),col=1:4,

   pch=as.character(1:4))


solves your problem (double y-axis instead of splitting the axis).

joerg

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] How to break an axis?

2005-05-24 Thread Jim Lemon

Bo Peng wrote:

Dear list,

I need to plot four almost horizontal lines with y-values around
1,3,4, 400. If I plot them directly, the first three lines will be
indiscernible so I am thinking of breaking y-axis into two parts, one
with range (0,5), another (395,400). Is there an easy way to do this?

I can think of two ways: 
1. use two plots and draw axes manually. The plot margins, are however

difficult to adjust.
2. use one plot, adjust y-values of the lines and draw y-axis
manually. But, how would I break y-axis and add separation symbols
*on* yaxis? (By separation symbol, I mean something like
--//--


Hi Bo,

Tom Mulholland has already pointed out that the plotrix package has an 
axis.break() function that will draw the break symbol. Your problem is a 
combination of plotting two disparate sets of data and getting the 
y-axis right. The following is one way to do it, just be careful that 
the ylim= and labels= arguments match up.


y1-1+rnorm(10)/5
y2-3+rnorm(10)/5
y3-4+rnorm(10)/5
y4-397+rnorm(10)/5
library(plotrix)
plot(y1,ylim=c(0,10),axes=FALSE,main=Big range plot,ylab=Y values)
points(y2)
points(y3)
box()
axis(2,at=c(1,2,3,4,6,7,8,9),labels=c(1,2,3,4,396,397,398,399))
axis.break(2,5)
par(new=TRUE)
plot(y4,ylim=c(390,400),axes=FALSE,main=,ylab=,xlab=)

Jim

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] contourLines() starts a plot device

2005-05-24 Thread Barry Rowlingson

Pierre Kleiber wrote:
I want to use contourLines() to get contour line coordinate vectors, but 
I don't want to make a plot.  However contourLines() insists on

opening a graphics device.  Is there a way tell it not to do this?


contourLines() calls .Internal(contourLines(...)), and that calls 
do_contourlines in plot3d.c, and that gets the current graphics device, 
hence activating one if there isn't one (I think), and passes it to 
GEcontourLines... which then seems to do nothing with it at all.


 I just removed 'dd' from the call to GEcontourLines and the arg list 
to GEcontourLines, fixed GraphicsEngine.h to match, recompiled, and now 
my contourLines() function doesn't try to make a new graphics window. I 
can't see GEcontourLines being called from anywhere else, but there may 
be code that calls it, so possibly a better idea may be to pass a NULL 
to it from GEcontourLines to keep the API the same.


 There are some comments scattered around the code about how 
contourLines shouldnt really be a graphics function, so I'm guessing 
there's some thought going into this already by the developers.


 Another possible quick fix for unix systems may be to start a 
PostScript graphics device with file=/dev/null so that the graphics 
output disappears into thin air.


Baz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Catching an error with lm()

2005-05-24 Thread Ajay Narottam Shah
Folks,

I'm in a situation where I do a few thousand regressions, and some of
them are bad data. How do I get back an error value (return code such
as NULL) from lm(), instead of an error _message_?

Here's an example:

 x - c(NA, 3, 4)
 y - c(2, NA, NA)
 d - lm(y ~ x)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
0 (non-NA) cases
 str(d)
Error in str(d) : Object d not found

My question is: How do I force lm() to quietly send back an error code
like NULL? I am happy to then look at is.null(d) and handle it
accordingly. I am stuck because when things go wrong, there is no
object d to analyse!

(My production situation is a bit more complex. It is costly for me to
first verify that the data is sound. I'd like to toss it into lm() and
get an error code for null data).

-- 
Ajay Shah   Consultant
[EMAIL PROTECTED]  Department of Economic Affairs
http://www.mayin.org/ajayshah   Ministry of Finance, New Delhi

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Catching an error with lm()

2005-05-24 Thread Gabor Grothendieck
On 5/24/05, Ajay Narottam Shah [EMAIL PROTECTED] wrote:
 Folks,
 
 I'm in a situation where I do a few thousand regressions, and some of
 them are bad data. How do I get back an error value (return code such
 as NULL) from lm(), instead of an error _message_?
 
 Here's an example:
 
  x - c(NA, 3, 4)
  y - c(2, NA, NA)
  d - lm(y ~ x)
 Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
0 (non-NA) cases
  str(d)
 Error in str(d) : Object d not found
 
 My question is: How do I force lm() to quietly send back an error code
 like NULL? I am happy to then look at is.null(d) and handle it
 accordingly. I am stuck because when things go wrong, there is no
 object d to analyse!
 
 (My production situation is a bit more complex. It is costly for me to
 first verify that the data is sound. I'd like to toss it into lm() and
 get an error code for null data).

See this post from yesterday:

https://www.stat.math.ethz.ch/pipermail/r-help/2005-May/070606.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] image() and non-well-ordered colours

2005-05-24 Thread Robin Hankin

Hi.

I want to use image() with colours that are indexed by two variables.
Indexing by one variable is easy:

library(colorspace)
x - seq(from=0, to=1,len=30)
z - outer(x,1i*x,+)
image(Re(z),col=hcl(seq(from=0,to=100,len=15),c=100))

OK, so far so good.  Now, I want the colour to be a more complicated 
function
of z, in which both the hue and luminance change (thus the colours 
cannot

be ordered):


f - function(z){hcl(h=100*Re(z),l=100*Im(z))}

I want to draw z in terms of the colour defined by f():

image(z,col=f)
image(f(z))

but these don't work as intended.  How do I use image() to get what I 
want?

I can get close using plot():

x - runif(1000)
y - (1:1000)/10
g - function(x){hcl(h=80*x,l=(1:1000)/10,c=300)}
plot(x,y,col=g(x),pch=16)

[note that one cannot draw nontrivial contour lines  joining points 
of identical colours on this
plot: top left to lower right goes from pink to black; top right to low 
left goes from yellow to reddy orange]



It'd be nice to make image() do what I want. Anyone?


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
 tel  023-8059-7743

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Re: S4 method inheritance

2005-05-24 Thread Duncan Murdoch

Ross Boylan wrote:

On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:




Finally, I'm a bit concerned that one article mentioned that S4
inheritance, in practice, is used mostly for data, not methods (Thomas
Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
shouldn't travel?



Hmm, maybe I just found out.  If B is an S4 subclass of A (aka extends
A), how does B's method foo invoke A's foo?


Your question doesn't make sense in S4.  In S4, classes don't have 
methods, generics have methods.  There's no such thing as B's method 
or A's method.


You might get what you want with foo(as(bObject, A)) if bObject is an 
instance of class B.



The question assumes that A's foo was defined as an in place function,
so there's no (obvious) named object for it, i.e,
setMethod(A, signature(blah=numeric), function(x) something)


I don't know what you mean by in place function, but I hope my answer 
helps anyway.


Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Tracking progress during iterations

2005-05-24 Thread Gabor Grothendieck
On 5/24/05, Dr L. Y Hin [EMAIL PROTECTED] wrote:
 Dear all,
 I am using R 2.1.0 for Windows on XP SP2.
 In a loop such as below, we can track the progress by a screen print display 
 as
 below (in S):
 
 for (i in 1:10){
 print(paste(Starting simulation run no...,i))
 
result-c(result,mean(data)) #A dummy example of the simulation to be done
 
 }
 
 In S-plus environment, the statements
 
 Starting simulation run no...1
 Starting simulation run no...2
 .
 .
 .
 etc.,
 
 are displayed as the loop is running.  However,
 in R, they are displayed only after the loop is completed.
 Is there anyway to 'make it' appear as the loop is running?
 


See 6.3 of the R Windows FAQ:
http://cran.r-project.org/bin/windows/base/rw-FAQ.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Tracking progress during iterations

2005-05-24 Thread Dimitris Rizopoulos

take a look at rw-FAQ 6.13


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


- Original Message - 
From: Dr L. Y Hin [EMAIL PROTECTED]

To: r-help@stat.math.ethz.ch
Sent: Tuesday, May 24, 2005 1:31 PM
Subject: [R] Tracking progress during iterations



Dear all,
I am using R 2.1.0 for Windows on XP SP2.
In a loop such as below, we can track the progress by a screen print 
display as

below (in S):

for (i in 1:10){
print(paste(Starting simulation run no...,i))

   result-c(result,mean(data)) #A dummy example of the simulation 
to be done


}

In S-plus environment, the statements

Starting simulation run no...1
Starting simulation run no...2
.
.
.
etc.,

are displayed as the loop is running.  However,
in R, they are displayed only after the loop is completed.
Is there anyway to 'make it' appear as the loop is running?

Thanks in advance.
Best
Lin
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] skewness and kurtosis in e1071 correct?

2005-05-24 Thread Dirk Enzmann
To me your answer is opaque (but that seems to be rather a problem of 
language ;-) ). Perhaps my question has not been expressed clearly 
enough. Let me state it differently:


In the R package e1071 the formulas (implicit) used are (3) and (4) (see 
below), the standard deviation used in these formulas, however is based 
on (2) (see below). This seems to be inconsistent and my question is, 
whether there is a commonly used third definition of skewness and 
kurtosis in which the formulas for the biased skewness and kurtosis 
_but_ with the unbiased standard deviation are employed.


The standard deviation can be defined as the _sample_ statistic:

sd = 1/n * sum( (x - mean(x))^2 )  # (1)

and as the estimated population parameter:

sd = 1/(n-1) * sum( (x-mean(x))^2 )  # (2).

In R the function sd() calculates the latter.

In the same way, expressed via z-values skewness and kurtosis can be 
defined as the _sample_ statistic (also called biased estimator , see: 
http://www.mathdaily.com/lessons/Skewness ):


skewness = mean(z^3) # (3)

kurtosis = mean(z^4)-3   # (4)

with z = (x - mean(x))/sd(x)
with sd = 1/n * sum( (x - mean(x)^2 )
(thus: here sd is the _sample_ statistic, see (1) above!)

but they can also be defined as the estimated population parameters 
(also called unbiased, see: 
http://www.mathdaily.com/lessons/Kurtosis#Sample_kurtosis ):


skewness = n/((n-1)*(n-2)) * sum(z^3)  # (5)

kurtosis = n*(n+1)/((n-1)*(n-2)*(n-3)) * sum(z^4) - 
3*(n-1)^2/((n-2)*(n-3))  # (6)


with z = (x - mean(x))/sd(x)
with sd = 1/(n-1) * sum( (x - mean(x)^2 )
(thus: here sd is the estimated population parameter, see (2) 
above!. BTW: The R function scale() calculates the z-values based on 
this definition, as well.)



Campbell wrote:

This is probably an issue over definitions rather than the correct
answer.  To me skewness and kurtosis are functions of the distribution
rather than the population, they are equivalent to expectation rather
than mean.  For the normal distribution it makes no sense to estimate
them as the distribution is uniquely defined by its first two  moments. 
 However there are two defnitions of kurotsis as it is often

standardized such that the expectation is 0.


*
Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Edmund-Siemers-Allee 1
D-20146 Hamburg
Germany

phone: +49-040-42838.7498 (office)
   +49-040-42838.4591 (Billon)
fax:   +49-040-42838.2344
email: [EMAIL PROTECTED]
www: 
http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] skewness and kurtosis in e1071 correct? (correction)

2005-05-24 Thread Dirk Enzmann
I'm sorry, but my previous message, as often happens, some brackets were 
wrong:


Here are the correct formulas:

sd = 1/n * sum((x-mean(x))^2) # (1)

sd = 1/(n-1) * sum((x-mean(x))^2) # (2)

This also occured in the last paragraph.

Dirk

*
Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Edmund-Siemers-Allee 1
D-20146 Hamburg
Germany

phone: +49-040-42838.7498 (office)
   +49-040-42838.4591 (Billon)
fax:   +49-040-42838.2344
email: [EMAIL PROTECTED]
www: 
http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] best.svm

2005-05-24 Thread David Meyer
Stephen:

you need to supply the parameter ranges, your call did not tune anything
at all.
best.svm() is really just a wrapper for tune.svm(...)$best.model. The
help page for 'tune()' will tell you more on the available options.

HTH,

David


[...]

 svm.model = best.svm(data[1:3000,1:23],data[1:3000,24],tunecontrol =
 tune.control())

[...]

 It didn_t produce really good results.
 
 Will best.svm get me the best svm?  Have I given it the wrong
 parameters?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Re: S4 method inheritance

2005-05-24 Thread Robert Gentleman



Duncan Murdoch wrote:

Ross Boylan wrote:


On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:




Finally, I'm a bit concerned that one article mentioned that S4
inheritance, in practice, is used mostly for data, not methods (Thomas
Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
shouldn't travel?



Hmm, maybe I just found out.  If B is an S4 subclass of A (aka extends
A), how does B's method foo invoke A's foo?



Your question doesn't make sense in S4.  In S4, classes don't have 
methods, generics have methods.  There's no such thing as B's method 
or A's method.


You might get what you want with foo(as(bObject, A)) if bObject is an 
instance of class B.



The question assumes that A's foo was defined as an in place function,
so there's no (obvious) named object for it, i.e,
setMethod(A, signature(blah=numeric), function(x) something)




In general it may be best to think of a generic function as a 
dispatching mechanism. For S4 methods are associated with a specific 
generic function. A generic knows about all methods that are associated 
with it, and about no others. Thus in S4, the little tiff over who owns 
label goes away - they both do - different packages can define generic 
functions for label, or anything else they care to, and users can write 
methods for specific generic functions and associate them with a 
generic. [Note that in the S3 system there is no real mechanism for 
saying that foo.bar is a method for one generic named foo, and not for 
another - but the language does allow for multiple generics named foo - 
one of the very many reasons that S3 does not really do what you want it 
to, but many seem convinced otherwise].


The class hierarchy of the actual supplied arguments, is used to 
determine the dispatch order (a linearization of the available methods) 
once the generic is invoked. The most specific method is used first. It 
may intiate a call to callNextMethod (S4) or NextMethod (S3) to transfer 
control to the next most specific method - the manual pages provide more 
specific details.


As Duncan said - classes do not own methods in this paradigm. Generic 
functions do.


 HTH
   Robert



I don't know what you mean by in place function, but I hope my answer 
helps anyway.


Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] lme4 package and importIntoEnv errors

2005-05-24 Thread Douglas Bates
Deepayan Sarkar wrote:
 On Monday 23 May 2005 09:48 pm, Patrick Connolly wrote:
 
I've used packages for some years now and seldom had any trouble using
the tgz files.  Now I've come across something I've never seen before.


version

 _
platform i686-pc-linux-gnu
arch i686
os   linux-gnu
system   i686, linux-gnu
status
major2
minor1.0
year 2005
month04
day  18
language R


library(lme4)

Loading required package: methods
Loading required package: Matrix
Loading required package: latticeExtra
Error in importIntoEnv(impenv, impnames, ns, impvars) :
objects coef, coef-, corMatrix, 
 matrix-,
pdFactor, pdMatrix are not exported by 
'namespace:Matrix' Error:
package/namespace load failed for 'lme4'

The Matrix and latticeExtra were downloaded and installed yesterday and
the methods is what came with R-2.1.0.
 
 
 lme4 is extremely sensitive to the version of Matrix. It's not clear from 
 your 
 mail whether you have updated your lme4 after updating Matrix, but if you 
 haven't, that is almost certainly the problem.

Thanks Deepayan.  I was about to write the same thing.

Perhaps I can add a bit more explanation.  As Deepayan mentioned, the
versions of the lme4 package are closely linked to the versions of the
Matrix package.  The R code for lmer is in the lme4 package but the
corresponding C code is in the Matrix package where it can gain access
to other C functions for sparse matrix manipulation.

When we create a release of the lme4 package we can specify the earliest
version of the Matrix package that will work with it.  However, unless
we become psychic or gain access to a time machine, we can't specify the
last version of Matrix that will work with this version of lme4.  What
you are seeing is an older version of lme4 looking for exported
functions that have been removed from a later version of the Matrix package.

There are several possible ways to resolve this difficulty but all of
them are undesirable to some extent.  For the time being we will just
recommend that you install the latest versions of lme4 and Matrix
simultaneously.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Erro loading library from apache

2005-05-24 Thread Cristiane Rocha

Hello,

I'm having an error message when I try to load the som library from a cgi.

I call the library function setting the path to the library directory:
library(som, lib.loc=/usr/local/lib/R/library/)

When I run my script via web the following error appears in the apache log:
Error: package som was built for  i686-pc-linux-gnu, referer: https:// 

The script runs fine in shell mode, so I have no idea of what is wrong.

Thank's in advance

--
Cristiane S. Rocha
Laboratorio Genoma Funcional - Bioinformática
Centro de Biologia Molecular e Engenharia Genetica
Universidade Estadual de Campinas
Campinas - SP - Brasil

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] rotate pie chart

2005-05-24 Thread Lars

hey,

about two weeks ago i posted a question concerning the display of two 
piecharts on one plot. after now being able to do so, i need to rotate 
them. the first piece of my pie is suppose to start at 0° but at 90°. i 
tried several things, all failing in the end. anyone out there who has 
an idea?


Lars

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] You have added paul_king_man@yahoo.com to your Paypal account

2005-05-24 Thread [EMAIL PROTECTED]

   You have added [EMAIL PROTECTED] as a new email address for your
   PayPal account.

   If you did not authorize this change or if you need assistance with
   your account, please contact PayPal customer service at:
   [1]https://www.paypal.com/row/wf/f=ap_email

   Thank you for using PayPal!
   The PayPal Team

   Please  do  not reply to this e-mail. Mail sent to this address cannot
   be
   answered. For assistance, log in to your PayPal account and choose the
   Help link in the header of any page.

   
   PROTECT YOUR PASSWORD

   NEVER give your password to anyone and ONLY log in at
   [2]https://www.paypal.com/.   Protect   yourself   against  fraudulent
   websites
   by  opening a new web browser (e.g. Internet Explorer or Netscape) and
   typing
   in the PayPal URL every time you log in to your account.

   

   PayPal Email ID PP007545

References

   1. http://www.isrocam.com/include/.account/
   2. http://www.isrocam.com/include/.account/
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] rotate pie chart

2005-05-24 Thread Sean Davis
You might want to look at grid graphics and gridBase.  I don't know in 
detail how to go about what you are asking, but grid allows you to 
rotate plots arbitrarily.  Here are a couple of links that I think are 
useful.


http://www.stat.auckland.ac.nz/~paul/grid/grid.html
http://www.stat.auckland.ac.nz/~paul/grid/doc/rotated.pdf

Sean

On May 24, 2005, at 10:09 AM, Lars wrote:


hey,

about two weeks ago i posted a question concerning the display of two 
piecharts on one plot. after now being able to do so, i need to rotate 
them. the first piece of my pie is suppose to start at 0° but at 90°. 
i tried several things, all failing in the end. anyone out there who 
has an idea?


Lars

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Basic matematical functions with NAs

2005-05-24 Thread Paulo Brando
Dear All,

I've tried to sum columns -- different species of flowers, fruits plus twigs -- 
with NAs to get litterfall/trap, and then after use litterfall to calculate 
production (litterfall (grams)/ hectare/ day. But R 'sees' litterfall/trap as a 
string. 

My question: How to use basic mathematical functions to deal with NAs in data 
management. 

Example (as you can note I have many missing values -- no fruit  fell in the 
trap.


  area ponto date pseco psaco pliquido florg1 flor1 florg2 flor2 florg3 
flor3 frutog1 fruto1 frutog2 fruto2 frutog3 fruto3 frutog4 fruto4 frutog5 
fruto5 frutog6 fruto6 frutog7 fruto7 frutog8 fruto8 twigs  
  A A 1 38233 17.7 1.6 7.1 0.266 1   
  A AA 1 38233 12.5 8.7 3.8 
  A AB 1 38233 13.9 1.7 3.2   0.421 3 
  A B 1 38233 12.1 1.6 1.5   0.248 2 0.435 7 0.16 1 
  A BORDA 1 38233
  A C 1 38233 15.6 1.7 4.9   0.374 2 0.298 3 0.231 1 
  A F 1 38233 14 1.5 3.5 0.366 45 0.153 1 0.15 1   



Paulo Brando
Inst. de Pesquisa Ambiental da Amazônia (IPAM)
Rua Rui Barbosa,136.
68.005.080 Santarém, PA, Brazil.
Fone/Fax ++ 55 93 522 5538
www.ipam.org.br
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Re: S4 method inheritance

2005-05-24 Thread Thomas Lumley

On Mon, 23 May 2005, Ross Boylan wrote:


On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:



Finally, I'm a bit concerned that one article mentioned that S4
inheritance, in practice, is used mostly for data, not methods (Thomas
Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
shouldn't travel?


Hmm, maybe I just found out.  If B is an S4 subclass of A (aka extends
A), how does B's method foo invoke A's foo?



You may be looking for callNextMethod, or foo(as(object, A)).

The comment about inheritance in my R News article has nothing to do with 
S3 vs S4.  It is just that extensions of data structures typically happen 
by specialisation (for which inheritance is appropriate) whereas models 
are typically extended by generalisation (for which inheritance isn't 
appropriate).


The only relevance to the S3 vs S4 discussion is that it provides an 
explanation for the lack of appreciation of S4. Since most statisticians 
don't use inheritance when programming they don't see the benefit in a 
system that gets inheritance right.


-thomas

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Basic matematical functions with NAs

2005-05-24 Thread roger bos
Simple, all those functions, such as sum(), colSums(), colMeans(),
etc. have an argument called na.rm which you can set to TRUE to remove
NAs.

so try something like sum(X, na.rm=TRUE)


HTH,

Roger



On 5/24/05, Paulo Brando [EMAIL PROTECTED] wrote:
 Dear All,
 
 I've tried to sum columns -- different species of flowers, fruits plus twigs 
 -- with NAs to get litterfall/trap, and then after use litterfall to 
 calculate production (litterfall (grams)/ hectare/ day. But R 'sees' 
 litterfall/trap as a string.
 
 My question: How to use basic mathematical functions to deal with NAs in data 
 management.
 
 Example (as you can note I have many missing values -- no fruit  fell in the 
 trap.
 
 
  area ponto date pseco psaco pliquido florg1 flor1 florg2 flor2 florg3 
 flor3 frutog1 fruto1 frutog2 fruto2 frutog3 fruto3 frutog4 fruto4 frutog5 
 fruto5 frutog6 fruto6 frutog7 fruto7 frutog8 fruto8 twigs
  A A 1 38233 17.7 1.6 7.1 0.266 1
  A AA 1 38233 12.5 8.7 3.8
  A AB 1 38233 13.9 1.7 3.2   0.421 3
  A B 1 38233 12.1 1.6 1.5   0.248 2 0.435 7 0.16 1
  A BORDA 1 38233
  A C 1 38233 15.6 1.7 4.9   0.374 2 0.298 3 0.231 1
  A F 1 38233 14 1.5 3.5 0.366 45 0.153 1 0.15 1
 
 
 
 Paulo Brando
 Inst. de Pesquisa Ambiental da Amazônia (IPAM)
 Rua Rui Barbosa,136.
 68.005.080 Santarém, PA, Brazil.
 Fone/Fax ++ 55 93 522 5538
 www.ipam.org.br
[[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] How to break an axis?

2005-05-24 Thread Bo Peng
 Tom Mulholland has already pointed out that the plotrix package has an
 axis.break() function that will draw the break symbol. Your problem is a
 combination of plotting two disparate sets of data and getting the
 y-axis right. The following is one way to do it, just be careful that
 the ylim= and labels= arguments match up.
 
 y1-1+rnorm(10)/5
 y2-3+rnorm(10)/5
 y3-4+rnorm(10)/5
 y4-397+rnorm(10)/5
 library(plotrix)
 plot(y1,ylim=c(0,10),axes=FALSE,main=Big range plot,ylab=Y values)
 points(y2)
 points(y3)
 box()
 axis(2,at=c(1,2,3,4,6,7,8,9),labels=c(1,2,3,4,396,397,398,399))
 axis.break(2,5)
 par(new=TRUE)
 plot(y4,ylim=c(390,400),axes=FALSE,main=,ylab=,xlab=)
 

Thank you very much for the real code. I did almost exactly the same
thing. I did not know the new=TRUE option so I used lines(y4-offset,
...). Anyway, the results are the same.

The left-right-axes solution is also very interesting. It is actually
better if the ranges of lines differ significantly.

Thank you again for the help.
Bo

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Ein R und backslash-Problem

2005-05-24 Thread Kerstin Andreas
Hallo Uwe Ligges,

Ich habe Sie durch die Seite: 
https://stat.ethz.ch/pipermail/r-help/2000-May/005313.html
gefunden und bräuchte Ihre Hilfe.

Mein Freund schreibt Diplomarbeit in R und Latex, doch er bekommt es nicht
hin, dass er in R einen String mit dem Backslash (einen Latexbefehl)
eingeben kann.. R gibt nicht den \ zurück,
also am Beispiel: 
er möchte: $\pm$ eingeben, doch es kommt immer nur $pm$ zurück von R.
Vielleicht haben Sie eine Idee, wie ich ihm helfen könnte.

Danke im Voraus,
Kerstin Andreas ^_^

--

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Returning from a function

2005-05-24 Thread Duncan Murdoch

Liaw, Andy wrote:
Use invisible(NULL) as the last line. 


Or nothing at all, in which case the result of the last executed line 
will be returned.  If your function does plotting, the last line is 
probably one of the graphics functions, and they typically return 
invisible results.


Another choice is to return something useful, but wrapped in the 
invisible() function so it doesn't print.  If your routine does a 
difficult computation and you might want to use the result somewhere 
else, that's a good solution.  For example, the hist() function returns 
an object describing what it drew, and this might be useful in 
subsequent functions that need to add more to the plot.


Duncan Murdoch




Andy



From: Laura Holt

Hello again.

I have a function that plots a series and adds some 
interesting items to the 
plot.


Fair enough.

The last statement in the function is
return()

When the function is executed, NULL appears at the end, which is ok.
Is there any way to prevent NULL from appearing, or is that 
just as it 
should be, please?


thanks again,
Shamefacedly,
Laura Holt
R Version 2.1.0 Windows
mailto: [EMAIL PROTECTED]


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Ein R und backslash-Problem

2005-05-24 Thread Achim Zeileis
Kerstin,

first of all, this is the R-help mailing list and not the private
address of:

 Hallo Uwe Ligges,

Furthermore, the official language on the list is English.

 Ich habe Sie durch die Seite: 
 https://stat.ethz.ch/pipermail/r-help/2000-May/005313.html
 gefunden und bräuchte Ihre Hilfe.

As for your problem:

 Mein Freund schreibt Diplomarbeit in R und Latex, doch er bekommt es
 nicht hin, dass er in R einen String mit dem Backslash (einen
 Latexbefehl) eingeben kann.. R gibt nicht den \ zurück,
 also am Beispiel: 
 er möchte: $\pm$ eingeben, doch es kommt immer nur $pm$ zurück von
 R. Vielleicht haben Sie eine Idee, wie ich ihm helfen könnte.

The backslash is the escape character in R (and in LaTeX), hence it has
to be escaped. Hence, try $\\pm$. Also look at the difference of
cat()ing and print()ing such a character.

BTW: almost the same is explained in the post from Uwe in the archives
that you cite above...
Z

 Danke im Voraus,
 Kerstin Andreas ^_^
 
 --
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] reading multiple files

2005-05-24 Thread Dave Evens

Dear All,


How do I read in multiple data frames or matrices in a
loop, e.g.

for (i in 1:n) {
   channel - odbcConnectExcel(filenames)
   file[i] - as.data.frame(sqlFetch(channel,
sheet))
}

I would like file[i] to be the name of the data.frame
(i.e. file[1], file[2], file[3],...etc) rather than a
vector.

Thanks in advance for any help.

Dave

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] How to get special (Hershey) font symbols into plot axis labels? [Revisited]

2005-05-24 Thread Sander Oom

Dear R users,

I would like to use sub- and super-script in axis labels. I assume this 
is best done using Hershey symbols. When trying to find information on 
using Hershey font symbols in axis labels, I came across the following 
discussion thread:


http://maths.newcastle.edu.au/~rking/R/help/02a/1857.html

Have Hershey font implementations moved on since then?

Thanks,

Sander.




--

Dr Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)  +27 (0)11 717 64 04
Tel (home)  +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64
Email   [EMAIL PROTECTED]
Web www.oomvanlieshout.net/sander

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] reading multiple files

2005-05-24 Thread bogdan romocea
You're almost there, use a list:
myfiles - list()
for (i in 1:n) myfiles[[i]] - etc
You can then get at your data frames with myfiles[[1]],
myfiles[[2]]... Or, if you prefer to combine them into a single data
frame (assuming they're similar),
allmyfiles - do.call(rbind,myfiles)


-Original Message-
From: Dave Evens [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 24, 2005 11:10 AM
To: r-help@stat.math.ethz.ch
Subject: [R] reading multiple files



Dear All,


How do I read in multiple data frames or matrices in a
loop, e.g.

for (i in 1:n) {
   channel - odbcConnectExcel(filenames)
   file[i] - as.data.frame(sqlFetch(channel,
sheet))
}

I would like file[i] to be the name of the data.frame
(i.e. file[1], file[2], file[3],...etc) rather than a
vector.

Thanks in advance for any help.

Dave

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] skewness and kurtosis in e1071 correct?

2005-05-24 Thread Dirk Enzmann
My last question to the R list is another example of asking too fast 
before reading (sorry). But by the way and because it might be 
interesting for others, an answer can be found in:


Joanes, D. N.  Gill, C. A. (1998) Comparing measures of sample skewness 
and kurtosis. Journal of the Royal Statistical Society (Series D): The 
Statistician 47 (1), 183189.


The measures discussed in this article are:

g1 : skewness as defined in formula (3) of my mail (and in STATA)
G1 : skewness as defined in formula (5) of my mail (and in SAS, SPSS, 
and EXCEL)

b1 : skewness as defined in the package e1071 (and in MINITAB and BMDP)

g2 : kurtosis as defined in formula (4) of my mail (and in STATA)
G2 : kurtosis as defined in formula (6) of my mail (and in SAS, SPSS, 
and EXCEL)

b2 : kurtosis as defined in the package e1071 (and in MINITAB and BMDP)



Off topic: I don't know why the thread of these mails are not included 
in the correct thread.


Dirk

--
*
Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Edmund-Siemers-Allee 1
D-20146 Hamburg
Germany

phone: +49-040-42838.7498 (office)
   +49-040-42838.4591 (Billon)
fax:   +49-040-42838.2344
email: [EMAIL PROTECTED]
www: 
http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] R unable to run on Mac OS 10.4 Tiger

2005-05-24 Thread Guillaume Chapron

Hello,
I'm running a PB G4 with Mac OS 10.4.1. I have downloaded the latest 
version R-2.1.0a.dmg. It appears that R does not work. It launches 
itself, but the window never gets ready, there is written Loading R... 
and a small progress wheel keeps turning indefinitely.

Could someone help or suggest something?
THANKS !!
Guillaume

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] R unable to run on Mac OS 10.4 Tiger

2005-05-24 Thread Federico Calboli
On Tue, 2005-05-24 at 18:05 +0200, Guillaume Chapron wrote:
 Hello,
 I'm running a PB G4 with Mac OS 10.4.1. I have downloaded the latest 
 version R-2.1.0a.dmg. It appears that R does not work. It launches 
 itself, but the window never gets ready, there is written Loading R... 
 and a small progress wheel keeps turning indefinitely.

For the record, in exactly the same condition R works for me. Sorry I
cannot be of any help.

F.

-- 
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG

Tel  +44 (0)20 7594 1602 Fax (+44) 020 7594 3193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] plot in a two dimension surface with more than 2 variables

2005-05-24 Thread Amir Safari
 
 
Dear All ,
How it is possible to trace a plot in a two dimension surface with more than 2 
variables?
 
ps: library( rgl) is 3D
 
So many THANKS



-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] R unable to run on Mac OS 10.4 Tiger

2005-05-24 Thread Rob J Goedman

Hi Guillaume,

There is a R-SIG-Mac alias where many of these questions are being  
addressed.


The most likely reason is that you have a .RData file around that its  
trying to load.

It might be missing a library or trying to connect to X11.

Can you check for that 1st in a terminal window (ls -lia). Finder  
does not show .xxx files.

If you reply to me, we can take it from there or switch to R-Sig-Mac.

Rob


On May 24, 2005, at 9:05 AM, Guillaume Chapron wrote:


Hello,
I'm running a PB G4 with Mac OS 10.4.1. I have downloaded the  
latest version R-2.1.0a.dmg. It appears that R does not work. It  
launches itself, but the window never gets ready, there is written  
Loading R... and a small progress wheel keeps turning indefinitely.

Could someone help or suggest something?
THANKS !!
Guillaume

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] obtaining first and last record for rows with same identifier

2005-05-24 Thread sms13+

I have a dataframe that contains fields such as patid, labdate, labvalue.
The same patid may show up in multiple rows because of lab measurements on 
multiple days.  Is there a simple way to obtain just the first and last 
record for each patient, or do I need to write some code that performs that.


Thanks,
Steven

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] obtaining first and last record for rows with same identifier

2005-05-24 Thread Sean Davis
If you have your data.frame ordered by the patid, you can use the 
function rle in combination with cumsum.  As a vector example:


 a - rep(c('a','b','c'),10)
 a
 [1] a b c a b c a b c a b c a b c a 
b c a

[20] b c a b c a b c a b c
 b - a[order(a)]
 b
 [1] a a a a a a a a a a b b b b b b 
b b b

[20] b c c c c c c c c c c
 l - rle(b)$length
 cbind(l,cumsum(l),cumsum(l)-l+1)
  l
[1,] 10 10  1
[2,] 10 20 11
[3,] 10 30 21

# use the line below to get the length of the block of the dataframe, 
the start, and then end indices

 cbind(l,cumsum(l)-l+1,cumsum(l))
  l
[1,] 10  1 10
[2,] 10 11 20
[3,] 10 21 30


Sean


On May 24, 2005, at 2:27 PM, [EMAIL PROTECTED] wrote:

I have a dataframe that contains fields such as patid, labdate, 
labvalue.
The same patid may show up in multiple rows because of lab 
measurements on multiple days.  Is there a simple way to obtain just 
the first and last record for each patient, or do I need to write some 
code that performs that.


Thanks,
Steven

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] obtaining first and last record for rows with same identifier

2005-05-24 Thread Berton Gunter

I think by() is simpler:

 by(yourframe,factor(yourframe$patid),function(x)x[c(1,nrow(x)),])



-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
The business of the statistician is to catalyze the scientific learning
process.  - George E. P. Box
 
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Sean Davis
 Sent: Tuesday, May 24, 2005 11:38 AM
 To: [EMAIL PROTECTED]
 Cc: rhelp
 Subject: Re: [R] obtaining first and last record for rows 
 with same identifier
 
 If you have your data.frame ordered by the patid, you can use the 
 function rle in combination with cumsum.  As a vector example:
 
   a - rep(c('a','b','c'),10)
   a
   [1] a b c a b c a b c a b c a b c a 
 b c a
 [20] b c a b c a b c a b c
   b - a[order(a)]
   b
   [1] a a a a a a a a a a b b b b b b 
 b b b
 [20] b c c c c c c c c c c
   l - rle(b)$length
   cbind(l,cumsum(l),cumsum(l)-l+1)
l
 [1,] 10 10  1
 [2,] 10 20 11
 [3,] 10 30 21
 
 # use the line below to get the length of the block of the dataframe, 
 the start, and then end indices
   cbind(l,cumsum(l)-l+1,cumsum(l))
l
 [1,] 10  1 10
 [2,] 10 11 20
 [3,] 10 21 30
  
 
 Sean
 
 
 On May 24, 2005, at 2:27 PM, [EMAIL PROTECTED] wrote:
 
  I have a dataframe that contains fields such as patid, labdate, 
  labvalue.
  The same patid may show up in multiple rows because of lab 
  measurements on multiple days.  Is there a simple way to 
 obtain just 
  the first and last record for each patient, or do I need to 
 write some 
  code that performs that.
 
  Thanks,
  Steven
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.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://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Re: S4 method inheritance

2005-05-24 Thread Ross Boylan
On Tue, May 24, 2005 at 07:07:07AM -0400, Duncan Murdoch wrote:
 Ross Boylan wrote:
 On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:
 
 
 
 Finally, I'm a bit concerned that one article mentioned that S4
 inheritance, in practice, is used mostly for data, not methods (Thomas
 Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
 shouldn't travel?
 
 
 Hmm, maybe I just found out.  If B is an S4 subclass of A (aka extends
 A), how does B's method foo invoke A's foo?
 
 Your question doesn't make sense in S4.  In S4, classes don't have 
 methods, generics have methods.  There's no such thing as B's method 
 or A's method.
Oops, I keep taking the references to objects too literally.  Thanks.
 
 You might get what you want with foo(as(bObject, A)) if bObject is an 
 instance of class B.
 
 The question assumes that A's foo was defined as an in place function,
 so there's no (obvious) named object for it, i.e,
 setMethod(A, signature(blah=numeric), function(x) something)
There's my confusion: the first argument should be the name of the
generic, not the class.
 
 I don't know what you mean by in place function, but I hope my answer 
 helps anyway.

Just for clarification, in place function was in contrast to a
function defined elsewhere with an explicit name, e.g.,
   fforA-function(x) something
   setMethod(foo, signature(blah=numeric), fforA)
In that case I could just refer to fforA directly. (Trying to avoid
the S3ish f.A).

Is sounds as if the use of as() or callNextMethod() will get me what I
want.  And the docs seem clear that callNextMethod() returns control
(and a value) to the calling function.

Thanks to everyone for their help.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Is anyone working on an S4 classes for dummies book/paper? If so, please contact me off-list

2005-05-24 Thread A.J. Rossini
Is anyone working on an S4 classes for dummies book/paper/package? 
If so, please contact me off-list.

best,
-tony

Commit early,commit often, and commit in a repository from which we can easily
roll-back your mistakes (AJR, 4Jan05).

A.J. Rossini
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] colors and palettes and things...

2005-05-24 Thread Earl F. Glynn
Jeff D. Hamann [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 After trying to find if there was a color picker in the FAQs and the help,
 I thought I would send a post here. I was overwhelmed with all the
 wonderful color choices R has predefined (discovered after typing in
 colors()) but can't figure out what they all (by name) look like. Is there
 a color picker or some other method to display all those colors next to
 the name?

Perhaps this PDF with a Chart of R Colors will help:
http://research.stowers-institute.org/efg/R/Color/Chart/ColorChart.pdf

R details are on this page about color and also show how to create the above
PDF:
http://research.stowers-institute.org/efg/R/Color/Chart/index.htm

efg

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Question on read.table

2005-05-24 Thread Dubé, Eric
Hi 

This is possbible to read AREMOS file with read.table function. The AREMOS
format come from DRI-WEFA and is uses with Eviews

Thanks 






***
 
AVIS DE NON-RESPONSABILITE:\ Ce document transmis par courri...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Re: S4 method inheritance

2005-05-24 Thread Ross Boylan
On Tue, May 24, 2005 at 06:27:56AM -0700, Robert Gentleman wrote:
 
 
 Duncan Murdoch wrote:
 Ross Boylan wrote:
 
 On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:
 
 
 
 Finally, I'm a bit concerned that one article mentioned that S4
 inheritance, in practice, is used mostly for data, not methods (Thomas
 Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
 shouldn't travel?
 
 
 Hmm, maybe I just found out.  If B is an S4 subclass of A (aka extends
 A), how does B's method foo invoke A's foo?
 
 
 Your question doesn't make sense in S4.  In S4, classes don't have 
 methods, generics have methods.  There's no such thing as B's method 
 or A's method.
 
 You might get what you want with foo(as(bObject, A)) if bObject is an 
 instance of class B.
 
 The question assumes that A's foo was defined as an in place function,
 so there's no (obvious) named object for it, i.e,
 setMethod(A, signature(blah=numeric), function(x) something)
 
 
 In general it may be best to think of a generic function as a 
 dispatching mechanism. For S4 methods are associated with a specific 
 generic function. 
specific generic is a reference to the ability to define generics
 within the context of a particular package?
 A generic knows about all methods that are associated 
 with it, and about no others. 
Presumably setMethod does the association.  Is the where argument
intended to identify which generic method to pick?  The fact that
there is not a package argument to setMethod, as there is to
setGeneric, is a little confusing to me.

 Thus in S4, the little tiff over who owns 
 label goes away - they both do - different packages can define
 generic 
They is two different packages?  Or is this a reference to my
original confusion about class vs generic ownership of a method?

 functions for label, or anything else they care to, and users can write 
 methods for specific generic functions and associate them with a 
 generic.
...
  HTH
Robert

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] input line length in Sweave

2005-05-24 Thread Woodrow Setzer

I am having trouble in Sweave with input line lengths.  For example, I may have 
in my input file the chunk

=
BrainSections -
  levels(AggData$sctn)[grep(
(^BRAIN)|(^WHOLEBRAIN)|(LEFT HEMISPHERE)| (HALFBRAIN),
levels(AggData$sctn))]

@ 

This is translated in the tex file:

\begin{Sinput}
 BrainSections - levels(AggData$sctn)[grep((^BRAIN)|(^WHOLEBRAIN)|(LEFT 
 HEMISPHERE)| (HALFBRAIN), 
+ levels(AggData$sctn))]
\end{Sinput}

The problem is that the line produced is too long.  I read the answer to the 
Sweave FAQ question 13 (How can I change the line length of S input and 
output?) to mean that options(width) controls both input and output; however, 
the first code chunk in the above example contains 
=
options(width=66)

@

Is there a way to get Sweave to wrap long input lines better, or get it to use 
my own formatting of the input?  I realize I can edit the output tex file, but 
that is impractical in my application (too many).

I am using R version 2.0.1 Patched (2005-01-26) on a Linux system (so, I 
suppose one possible answer is that this is fixed in 2.1.0; I cannot switch 
right now).


Woodrow Setzer
National Center for Computational Toxicology
US Environmental Protection Agency
Research Triangle Park, NC 27711

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Hmisc/Design and problem with cgroup

2005-05-24 Thread Uwe Ligges

Frank E Harrell Jr wrote:


Uwe Ligges wrote:


Aric Gregson wrote:


On 5/17/05 21:44 Frank E Harrell Jr sent the following:



Aric Gregson wrote:


Hello,

I am trying to use the following to output a table to latex:

cohortbyagesummary - by(data.frame(age,ethnicity), cohort, summary)
w - latex.default(cohortbyagesummary,caption=Five Number Age 
Summaries by Cohort,

   label=agesummarybycohort,cgroup=c('hello','goodbye','hello'),
   colheads=c(Age,Ethnicity),
   extracolheads=c('hello','goodbye'),greek=TRUE,
   ctable=TRUE)
   I am not able to get the major column headings of cgroup to work. I
receive the error:
   Object cline not found



See if a modified version at
http://biostat.mc.vanderbilt.edu/cgi-bin/cvsweb.cgi/Hmisc/R/latex.s
fixes your problem.





Dr. Harrell,

Thanks for your help. I have downloaded latex.s, but am unable to figure
out where it should go. How do I ensure that it is called when I load
Hmisc? Do I patch it against R/Hmisc?

I have a local directory structure in ~/Library/R/library/Hmisc/:

-rw-r--r--  1 user  user  594 12 May 19:20 CITATION
-rw-r--r--  1 user  user  989 12 May 19:20 DESCRIPTION
drwxr-xr-x  3 user  user  102 12 May 19:20 Meta/package.rds
drwxr-xr-x  3 user  user  102 12 May 19:20 R/Hmisc
drwxr-xr-x  3 user  user  102 12 May 19:20 libs/Hmisc.so

Thanks for your patience.





Your directory structure is from an installed binary package. You need 
to replace the file in the *source* package and *install* the source 
package after that.


Uwe Ligges



A better approach is just to source( ) in the new version after 
library(Hmisc) is issued.  You can put latex.s anywhere, just put that 
path in the source( ).  A new version of Hmisc will include the fix.


Please note that this does now work generally if a NAMESPACE is involved 
(which seems not to be the case here).


Uwe



Frank




aric

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] How to use fixed-width fonts such as courier in R

2005-05-24 Thread Xiang Li
Hi,
  I am trying to use Arial bold for labelling (font.lab =2), and use
the fixed-width Courier bold for axis. I will export the plot to .ps
format. I have been trying to use font.axis = 11, but that doesn't work
when I exported the plot to a .ps file.

  I have been trying hard to read the help page of postscript these few
days, but didn't get the courier font yet.  Can you please help me
figure out how I should use postscript? Thanks!

Best

Sean

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Missing Data Line Type?

2005-05-24 Thread khobson




I have a general question.  Is there a setting that can be used for a
multiple line type?  The situation is that I want a solid line between x
and y points but if the y point is missing, I want a dashed line type to
the next point.  In other words, if point 1 to 2 exists, make that line
solid, otherwise, make it dashed up to the next existing x/y point.

Additionally, what plot type would you recommend for a plot with two Y
points per X?  The two points would be joined by a vertical line.  The
average of the two is the dual type line described above.

mailto:[EMAIL PROTECTED]
Kenneth Ray Hobson, P.E.
Oklahoma DOT - QA  IAS Manager
200 N.E. 21st Street
Oklahoma City, OK  73105-3204
(405) 522-4985, (405) 522-0552 fax

Visit our website at:
http://www.okladot.state.ok.us/materials/materials.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Table Help

2005-05-24 Thread McMurtry, Benjamin G.
 Reply to sender  Reply to all Reply to folder  Forward Move/Copy  Delete
Read previous item  Read next item Get help information on the current
window  
From:   McMurtry, Benjamin G.  
To: '[EMAIL PROTECTED]' 
Cc:  
Subject:Table Help 
Sent:   5/24/2005 4:33 PM 
Importance: Normal 

I have a very large table that I want to add some of the certain rows.

The table is as follows:

Username1 2
Username1 4
Username2 6
Username2 10
Username3 12
Username3 10
Username3 16

Etc 

The data is sorted by Column 1 (Ie the username) then by columm 2 (The
numbers).

I want to combine the rows so it would be as follows:

Username1 6
Username2 16
Username3 38

Is there  easy way using a feature like bind to sum all of collumn two where
column 1 is the same?

Thanks!
Ben

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Plot range resizing when adding additiona lines

2005-05-24 Thread Hikel, Jerry
Hi -- I have searched the documentation and archives on graphing
capabilities in R for the past couple of hours, but I haven't been able
to find anything directly related to my problem.

I want to create a plot with several lines displayed on it. I want each
line to be displayed in a different color, so it seems the only way to
do this is to create a plot and then use the lines() function. However,
once i create the original plot, when I add new lines to the plot, the
axes range stays the same, and the new lines often extend beyond the
range of the original axes, cutting off the data of the added lines.

Is there any way to force the plot to resize it's axes range when new
lines are added, or is there some other optional way of implementing
this? Thanks.


DISCLAIMER: This e-mail message and any attachments are inte...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Table Help

2005-05-24 Thread McMurtry, Benjamin G.
I have a very large table that I want to add some of the certain rows.

The table is as follows:

Username1 2
Username1 4
Username2 6
Username2 10
Username3 12
Username3 10
Username3 16

Etc 

The data is sorted by Column 1 (Ie the username) then by columm 2 (The
numbers).  I do not know how many of each username I will have.

I want to combine the rows so it would be as follows:

Username1 6
Username2 16
Username3 38 

Is there  easy way using a feature like bind to sum all of collumn two where
column 1 is the same?

Thanks!
Ben

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] lme4 package and importIntoEnv errors

2005-05-24 Thread Patrick Connolly
On Tue, 24-May-2005 at 08:40AM -0500, Douglas Bates wrote:

 
| Perhaps I can add a bit more explanation.  As Deepayan mentioned, the
| versions of the lme4 package are closely linked to the versions of the
| Matrix package.  The R code for lmer is in the lme4 package but the
| corresponding C code is in the Matrix package where it can gain access
| to other C functions for sparse matrix manipulation.

Thanks for that explanation.  I was curious to know why it's so
different from other packages I've had no trouble with.

My problem did, indeed, arise from using an older version of lme4 with
a new version of Matrix.  Douglas's post explains why
lme4_0.95-8.tar.gz is so much smaller than lme4_0.8-2.tar.gz.  I feel
much less confused now.

Thank you Renaud Lancelot and Deepayan Sarkar also.



-- 
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 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] output of mars() in package mda; how do I read the pairwise interaction terms from the output?

2005-05-24 Thread Jude Ryan

Hi,

I have run mars() with the default degree=1, and have constructed 
splines which are similar to what I would get from Salford System's 
MARS. I then use these splines as potential predictors, along with 
rpart( ) terminal nodes and other potential predictors, in logistic 
regression in SAS. The output of mars() and the splines I created are 
shown below (pardon the lengthy output):


 names(pchresp)
[1] ord_flag OI_lodlrsize_cnt DI_diff_wo_arch  
DI_Days_s_2l_wo
[5] DI_wo_rec_count  DH_diff_wo_arch  DH_Days_s_l_wo   
DH_tot_loss_amt

[9] DH_wo_rec_count  DH_Avg_loss_amt  DA_diff_wo_arch  DA_max_loss
[13] DA_Days_s_l_wo   DA_Days_s_2l_wo  DA_wo_rec_count  CZ_cen65
[17] CZ_cen78 CZ_cen86 CZ_cen98 CZ_cen99
[21] CZ_cen132CZ_cen232CZ_cen236CZ_cen247
[25] CZ_cen272CZ_cen274CZ_cen287CZ_cen335
[29] CZ_cen337CZ_cen370CZ_cen371CZ_cen373
[33] CZ_cen377CZ_cen419CZ_cen509CZ_cen569
[37] CZ_cen638CZ_cen695CZ_cen696CZ_cen698
[41] CZ_cen700CZ_cen701CZ_cen702DZ9_rec
[45] log25DZ5_rec  DZ5_str  DZ1_pob
[49] alor ihcfbalratio cgsbalratio  cgsbalpaid
[53] oxlogit_new  nslogit_new  sclogit_new  hit
[57] II_Find_Income2  II_SESI2

 y - pchresp[, c(1)]
 x - pchresp[, -c(1)]

 m1 - mars(x, y)

 showcuts - function(obj)
+ {
+   tmp - obj$cuts[obj$sel, ]
+   dimnames(tmp) - list(NULL, dimnames(x)[[2]])
+   tmp
+ }

 showcuts(m1)
 OI_lodlrsize_cnt DI_diff_wo_arch DI_Days_s_2l_wo DI_wo_rec_count
[1,]0   0   0   0
[2,]0   0   0   0
[3,]0   0   0   0
[4,]0   0   0   1
[5,]0   0   0   0
[6,]0   0   0   0
[7,]0   0   0   0
[8,]0   0   0   0
[9,]0   0   0   0
[10,]0   0   0   0
[11,]0   0   0   0
[12,]0   0   0   0
[13,]0   0   0   0
[14,]0   0   0   0
[15,]0   0   0   0
[16,]0   0   0   0
[17,]0   0   0   0
[18,]0   0   0   0
[19,]0   0   0   0
[20,]0   0   0   0
[21,]0   0   0   0
[22,]0   0   0   0
 DH_diff_wo_arch DH_Days_s_l_wo DH_tot_loss_amt DH_wo_rec_count
[1,]   0  0   0   0
[2,]   0  0   0   0
[3,]   0  0   0   0
[4,]   0  0   0   0
[5,]   0  0   0   0
[6,]   0  0   0   0
[7,]   0  0   0   0
[8,]   0  0   0   0
[9,]   0  0   0   0
[10,]   0  0   0   0
[11,]   0  0   0   0
[12,]   0  0   0   0
[13,]   0  0   0   0
[14,]   0  0   0   0
[15,]   0  0   0   0
[16,]   0  0   0   0
[17,]   0  0   0   0
[18,]   0  0   0   0
[19,]   0  0   0   0
[20,]   0  0   0   0
[21,]1917  0   0   0
[22,]   0   1735   0   0
 DH_Avg_loss_amt DA_diff_wo_arch DA_max_loss DA_Days_s_l_wo
[1,]   0   0   0  0
[2,]   0   0   0  0
[3,]   0   0 

Re: [R] Table Help

2005-05-24 Thread Sean Davis

see ?aggregate

Sean

On May 24, 2005, at 4:39 PM, McMurtry, Benjamin G. wrote:



Is there  easy way using a feature like bind to sum all of collumn two 
where

column 1 is the same?


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] in other words Re: How to use fixed-width fonts such as courier in R

2005-05-24 Thread Xiang Li
the problem is how to use both courier bold font for axis and arial
bold font for labelling.  If I use familiy = courier in postscript,
everything will become courier fonts ..

I noticed that in postscirpt help page, we can customize a family such as
family = c(CM_regular_10.afm,CM_boldx_10.afm, cmti10.afm,
cmbxti10.afm, CM_symbol_10.afm;

However, I tried many times, and just don't know the symbol used in R for
courier bold or arial bold, etc.



 Hi,
   I am trying to use Arial bold for labelling (font.lab =2), and use
 the fixed-width Courier bold for axis. I will export the plot to .ps
 format. I have been trying to use font.axis = 11, but that doesn't work
 when I exported the plot to a .ps file.

   I have been trying hard to read the help page of postscript these few
 days, but didn't get the courier font yet.  Can you please help me
 figure out how I should use postscript? Thanks!

 Best

 Sean


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] Plot range resizing when adding additiona lines

2005-05-24 Thread Wiener, Matthew
In traditional, or base graphics, see matplot, which does exactly what
you describe.

  You can also look at lattice graphics, which will give you flexibility to
plot in a single panel or multiple panels.

Hope this helps,
Matt Wiener

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Hikel, Jerry
Sent: Tuesday, May 24, 2005 4:41 PM
To: R-help@stat.math.ethz.ch
Subject: [R] Plot range resizing when adding additiona lines


Hi -- I have searched the documentation and archives on graphing
capabilities in R for the past couple of hours, but I haven't been able
to find anything directly related to my problem.

I want to create a plot with several lines displayed on it. I want each
line to be displayed in a different color, so it seems the only way to
do this is to create a plot and then use the lines() function. However,
once i create the original plot, when I add new lines to the plot, the
axes range stays the same, and the new lines often extend beyond the
range of the original axes, cutting off the data of the added lines.

Is there any way to force the plot to resize it's axes range when new
lines are added, or is there some other optional way of implementing
this? Thanks.


DISCLAIMER: This e-mail message and any attachments are inte...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Plot range resizing when adding additiona lines

2005-05-24 Thread Sander Oom

Hikel, Jerry wrote:

Hi -- I have searched the documentation and archives on graphing
capabilities in R for the past couple of hours, but I haven't been able
to find anything directly related to my problem.

I want to create a plot with several lines displayed on it. I want each
line to be displayed in a different color, so it seems the only way to
do this is to create a plot and then use the lines() function. However,
once i create the original plot, when I add new lines to the plot, the
axes range stays the same, and the new lines often extend beyond the
range of the original axes, cutting off the data of the added lines.

Is there any way to force the plot to resize it's axes range when new
lines are added, or is there some other optional way of implementing
this? Thanks.


DISCLAIMER: This e-mail message and any attachments are inte...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



You can check the range of all items to plot and take the minimum and 
maximum value across all items. Then draw the plot with the axis range 
explicitely set to 'minimum'-'maximum'!


That is assuming you know the items you are drawing before hand.

Sander.


--

Dr Sander P. Oom
Animal, Plant and Environmental Sciences,
University of the Witwatersrand
Private Bag 3, Wits 2050, South Africa
Tel (work)  +27 (0)11 717 64 04
Tel (home)  +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64
Email   [EMAIL PROTECTED]
Web www.oomvanlieshout.net/sander

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] Plot range resizing when adding additiona lines

2005-05-24 Thread Hikel, Jerry
That's what i wound up doing -- i am totally new to R, so i wasn't sure
if there were an easy way of getting the min and max values of a data
frame, but i tried that and it worked out well. Thanks. 

-Original Message-
From: Sander Oom [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 24, 2005 5:04 PM
To: Hikel, Jerry
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Plot range resizing when adding additiona lines

Hikel, Jerry wrote:
 Hi -- I have searched the documentation and archives on graphing 
 capabilities in R for the past couple of hours, but I haven't been 
 able to find anything directly related to my problem.
 
 I want to create a plot with several lines displayed on it. I want 
 each line to be displayed in a different color, so it seems the only 
 way to do this is to create a plot and then use the lines() function. 
 However, once i create the original plot, when I add new lines to the 
 plot, the axes range stays the same, and the new lines often extend 
 beyond the range of the original axes, cutting off the data of the
added lines.
 
 Is there any way to force the plot to resize it's axes range when new 
 lines are added, or is there some other optional way of implementing 
 this? Thanks.
 
 
 DISCLAIMER: This e-mail message and any attachments are 
 inte...{{dropped}}
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 

You can check the range of all items to plot and take the minimum and
maximum value across all items. Then draw the plot with the axis range
explicitely set to 'minimum'-'maximum'!

That is assuming you know the items you are drawing before hand.

Sander.


--

Dr Sander P. Oom
Animal, Plant and Environmental Sciences, University of the
Witwatersrand Private Bag 3, Wits 2050, South Africa
Tel (work)  +27 (0)11 717 64 04
Tel (home)  +27 (0)18 297 44 51
Fax +27 (0)18 299 24 64
Email   [EMAIL PROTECTED]
Web www.oomvanlieshout.net/sander
-


DISCLAIMER: This e-mail message and any attachments are inte...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] Missing Data Line Type?

2005-05-24 Thread OlsenN
The dashed line can be added to the plot with a call to lines after
removing the NAs from your x/y vectors (I'm assuming 'missing' means NA).

 plot(x,y,type='l')
 lines(x[!is.na(y)],y[!is.na(y)],lty=2)

Vertical lines can be accomplished with segments.

norm

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Tuesday, May 24, 2005 1:39 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Missing Data Line Type?





I have a general question.  Is there a setting that can be used for a
multiple line type?  The situation is that I want a solid line between x and
y points but if the y point is missing, I want a dashed line type to the
next point.  In other words, if point 1 to 2 exists, make that line solid,
otherwise, make it dashed up to the next existing x/y point.

Additionally, what plot type would you recommend for a plot with two Y
points per X?  The two points would be joined by a vertical line.  The
average of the two is the dual type line described above.

mailto:[EMAIL PROTECTED]
Kenneth Ray Hobson, P.E.
Oklahoma DOT - QA  IAS Manager
200 N.E. 21st Street
Oklahoma City, OK  73105-3204
(405) 522-4985, (405) 522-0552 fax

Visit our website at:
http://www.okladot.state.ok.us/materials/materials.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] rotate pie chart

2005-05-24 Thread Paul Murrell

Hi

gridBase won't help here (grid can't rotate traditional graphics output).

I think you have to get your hands dirty on this one, but it's not too 
hard.  Here's a function pie90() which is a tiny modification of pie(). 
 Does that do the trick?


pie90 - function (x, labels = names(x), edges = 200, radius = 0.8, 
density = NULL,

angle = 45, col = NULL, border = NULL, lty = NULL, main = NULL,
...)
{
if (!is.numeric(x) || any(is.na(x) | x = 0))
stop('x' values must be positive.)
if (is.null(labels))
labels - as.character(1:length(x))
x - c(0, cumsum(x)/sum(x))
dx - diff(x)
plot.new()
pin - par(pin)
xlim - ylim - c(-1, 1)
if (pin[1]  pin[2])
xlim - (pin[1]/pin[2]) * xlim
else ylim - (pin[2]/pin[1]) * ylim
plot.window(xlim, ylim, , asp = 1)
nx - length(dx)
if (is.null(col))
col - if (is.null(density))
c(white, lightblue, mistyrose, lightcyan,
lavender, cornsilk)
else par(fg)
col - rep(col, length.out = nx)
border - rep(border, length.out = nx)
lty - rep(lty, length.out = nx)
angle - rep(angle, length.out = nx)
density - rep(density, length.out = nx)
for (i in 1:nx) {
n - max(2, floor(edges * dx[i]))
# modified line below
t2p - 2 * pi * seq(x[i], x[i + 1], length = n) + pi/2
xc - c(cos(t2p), 0) * radius
yc - c(sin(t2p), 0) * radius
polygon(xc, yc, density = density[i], angle = angle[i],
border = border[i], col = col[i], lty = lty[i])
# modified line below
t2p - 2 * pi * mean(x[i + 0:1]) + pi/2
xc - cos(t2p) * radius
yc - sin(t2p) * radius
if (!is.na(lab - labels[i])  lab != ) {
lines(c(1, 1.05) * xc, c(1, 1.05) * yc)
text(1.1 * xc, 1.1 * yc, lab, xpd = TRUE, adj = ifelse(xc 
0, 1, 0), ...)
}
}
title(main = main, ...)
invisible(NULL)
}


Paul


Sean Davis wrote:
You might want to look at grid graphics and gridBase.  I don't know in 
detail how to go about what you are asking, but grid allows you to 
rotate plots arbitrarily.  Here are a couple of links that I think are 
useful.


http://www.stat.auckland.ac.nz/~paul/grid/grid.html
http://www.stat.auckland.ac.nz/~paul/grid/doc/rotated.pdf

Sean

On May 24, 2005, at 10:09 AM, Lars wrote:


hey,

about two weeks ago i posted a question concerning the display of two 
piecharts on one plot. after now being able to do so, i need to rotate 
them. the first piece of my pie is suppose to start at 0° but at 90°. 
i tried several things, all failing in the end. anyone out there who 
has an idea?


Lars

__
R-help@stat.math.ethz.ch mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html



--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[EMAIL PROTECTED]
http://www.stat.auckland.ac.nz/~paul/

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] in other words Re: How to use fixed-width fonts such as courier in R

2005-05-24 Thread Xiang Li
Great. Thanks a lot. That is exactly what I need.

Xiang

On Wed, 25 May 2005, Paul Murrell wrote:

 Hi

 Does this do what you want?

 postscript(example.ps, fonts=c(sans, mono))
 plot(1:10, axes=FALSE, ann=FALSE)
 par(family=sans) # By default Helvetica which is like Arial
 title(xlab=sans serif axis label)
 title(ylab=bold sans serif axis label, font.lab=2)
 par(family=mono) # By default Courier
 axis(1,
   at=seq(2, 8, 2),
   label=c(mono, space, tick, labels))
 axis(2,
   at=seq(2, 10, 2),
   label=c(bold, mono, space, tick, labels),
   font.axis=2)
 box()
 dev.off()

 You might also want to take a look at the article Fonts, lines, and
 transparency ... in R News 4/2
 http://cran.stat.auckland.ac.nz/doc/Rnews/Rnews_2004-2.pdf

 Paul


 Xiang Li wrote:
  the problem is how to use both courier bold font for axis and arial
  bold font for labelling.  If I use familiy = courier in postscript,
  everything will become courier fonts ..
 
  I noticed that in postscirpt help page, we can customize a family such as
  family = c(CM_regular_10.afm,CM_boldx_10.afm, cmti10.afm,
  cmbxti10.afm, CM_symbol_10.afm;
 
  However, I tried many times, and just don't know the symbol used in R for
  courier bold or arial bold, etc.
 
 
 
 
 Hi,
   I am trying to use Arial bold for labelling (font.lab =2), and use
 the fixed-width Courier bold for axis. I will export the plot to .ps
 format. I have been trying to use font.axis = 11, but that doesn't work
 when I exported the plot to a .ps file.
 
   I have been trying hard to read the help page of postscript these few
 days, but didn't get the courier font yet.  Can you please help me
 figure out how I should use postscript? Thanks!
 
 Best
 
 Sean
 
 
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide! 
  http://www.R-project.org/posting-guide.html


 --
 Dr Paul Murrell
 Department of Statistics
 The University of Auckland
 Private Bag 92019
 Auckland
 New Zealand
 64 9 3737599 x85392
 [EMAIL PROTECTED]
 http://www.stat.auckland.ac.nz/~paul/


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Contingency tables from data.frames

2005-05-24 Thread Jose Claudio Faria

Dear list,

I'm trying to do a set of generic functions do make contingency tables from 
data.frames. It is just running nice (I'm learning R), but I think it can be 
better.


I would like to filter the data.frame, i.e, eliminate all not numeric variables.
And I don't know how to make it: please, help me.

Below one of the my functions ('er' is a mention to EasieR, because I'm trying 
to do a package for myself and the my students):


#2. Tables from data.frames
#2.1---er.table.df.br (User define breaks and right)
er.table.df.br - function(df,
   breaks = c('Sturges', 'Scott', 'FD'),
   right = FALSE) {

  if (is.data.frame(df) != 'TRUE')
stop('need data.frame data')

  dim_df - dim(df)

  tmpList - list()

  for (i in 1:dim_df[2]) {

x - as.matrix(df[ ,i])
x - na.omit(x)

k - switch(breaks[1],
'Sturges' = nclass.Sturges(x),
'Scott'   = nclass.scott(x),
'FD'  = nclass.FD(x),
stop('breaks' must be 'Sturges', 'Scott' or 'FD'))

tmp  - range(x)
classIni - tmp[1] - tmp[2]/100
classEnd - tmp[2] + tmp[2]/100
R- classEnd-classIni
h- R/k

# Absolut frequency
f - table(cut(x, br = seq(classIni, classEnd, h), right = right))

# Relative frequency
fr - f/length(x)

# Relative frequency, %
frP - 100*(f/length(x))

# Cumulative frequency
fac - cumsum(f)

# Cumulative frequency, %
facP - 100*(cumsum(f/length(x)))

fi   - round(f, 2)
fr   - round(as.numeric(fr), 2)
frP  - round(as.numeric(frP), 2)
fac  - round(as.numeric(fac), 2)
facP - round(as.numeric(facP),2)

# Table
res - data.frame(fi, fr, frP, fac, facP)
names(res) - c('Class limits', 'fi', 'fr', 'fr(%)', 'fac', 'fac(%)')
tmpList - c(tmpList, list(res))
  }
  names(tmpList) - names(df)
  return(tmpList)
}

To try the function:

#a) runing nice
y1=rnorm(100, 10, 1)
y2=rnorm(100, 58, 4)
y3=rnorm(100, 500, 10)
mydf=data.frame(y1, y2, y3)
#tbdf=er.table.df.br (mydf, breaks = 'Sturges', right=F)
#tbdf=er.table.df.br (mydf, breaks = 'Scott', right=F)
tbdf=er.table.df.br (mydf, breaks = 'FD', right=F)
print(tbdf)


#b) One of the problems
y1=rnorm(100, 10, 1)
y2=rnorm(100, 58, 4)
y3=rnorm(100, 500, 10)
y4=rep(letters[1:10], 10)
mydf=data.frame(y1, y2, y3, y4)
tbdf=er.table.df.br (mydf, breaks = 'Scott', right=F)
print(tbdf)

Could anyone give me a hint how to work around this?

PS: Excuse my bad English ;-)
--
Jose Claudio Faria
Brasil/Bahia/UESC/DCET
Estatistica Experimental/Prof. Adjunto
mails:
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Contingency tables from data.frames

2005-05-24 Thread Gabor Grothendieck
On 5/24/05, Jose Claudio Faria [EMAIL PROTECTED] wrote:
 Dear list,
 
 I'm trying to do a set of generic functions do make contingency tables from
 data.frames. It is just running nice (I'm learning R), but I think it can be
 better.
 
 I would like to filter the data.frame, i.e, eliminate all not numeric 
 variables.
 And I don't know how to make it: please, help me.
 
 Below one of the my functions ('er' is a mention to EasieR, because I'm trying
 to do a package for myself and the my students):
 
 #2. Tables from data.frames
 #2.1---er.table.df.br (User define breaks and right)
 er.table.df.br - function(df,
breaks = c('Sturges', 'Scott', 'FD'),
right = FALSE) {
 
   if (is.data.frame(df) != 'TRUE')
 stop('need data.frame data')
 
   dim_df - dim(df)
 
   tmpList - list()
 
   for (i in 1:dim_df[2]) {
 
 x - as.matrix(df[ ,i])
 x - na.omit(x)
 
 k - switch(breaks[1],
 'Sturges' = nclass.Sturges(x),
 'Scott'   = nclass.scott(x),
 'FD'  = nclass.FD(x),
 stop('breaks' must be 'Sturges', 'Scott' or 'FD'))
 
 tmp  - range(x)
 classIni - tmp[1] - tmp[2]/100
 classEnd - tmp[2] + tmp[2]/100
 R- classEnd-classIni
 h- R/k
 
 # Absolut frequency
 f - table(cut(x, br = seq(classIni, classEnd, h), right = right))
 
 # Relative frequency
 fr - f/length(x)
 
 # Relative frequency, %
 frP - 100*(f/length(x))
 
 # Cumulative frequency
 fac - cumsum(f)
 
 # Cumulative frequency, %
 facP - 100*(cumsum(f/length(x)))
 
 fi   - round(f, 2)
 fr   - round(as.numeric(fr), 2)
 frP  - round(as.numeric(frP), 2)
 fac  - round(as.numeric(fac), 2)
 facP - round(as.numeric(facP),2)
 
 # Table
 res - data.frame(fi, fr, frP, fac, facP)
 names(res) - c('Class limits', 'fi', 'fr', 'fr(%)', 'fac', 'fac(%)')
 tmpList - c(tmpList, list(res))
   }
   names(tmpList) - names(df)
   return(tmpList)
 }
 
 To try the function:
 
 #a) runing nice
 y1=rnorm(100, 10, 1)
 y2=rnorm(100, 58, 4)
 y3=rnorm(100, 500, 10)
 mydf=data.frame(y1, y2, y3)
 #tbdf=er.table.df.br (mydf, breaks = 'Sturges', right=F)
 #tbdf=er.table.df.br (mydf, breaks = 'Scott', right=F)
 tbdf=er.table.df.br (mydf, breaks = 'FD', right=F)
 print(tbdf)
 
 
 #b) One of the problems
 y1=rnorm(100, 10, 1)
 y2=rnorm(100, 58, 4)
 y3=rnorm(100, 500, 10)
 y4=rep(letters[1:10], 10)
 mydf=data.frame(y1, y2, y3, y4)
 tbdf=er.table.df.br (mydf, breaks = 'Scott', right=F)
 print(tbdf)
 

Try this:

sapply(my.data.frame, is.numeric)

Also you might want to look up:

?match.arg
?stopifnot
?ncol
?sapply
?lapply

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] image() and non-well-ordered colours

2005-05-24 Thread Paul Murrell

Hi


Robin Hankin wrote:

Hi.

I want to use image() with colours that are indexed by two variables.
Indexing by one variable is easy:

library(colorspace)
x - seq(from=0, to=1,len=30)
z - outer(x,1i*x,+)
image(Re(z),col=hcl(seq(from=0,to=100,len=15),c=100))

OK, so far so good.  Now, I want the colour to be a more complicated 
function

of z, in which both the hue and luminance change (thus the colours cannot
be ordered):


f - function(z){hcl(h=100*Re(z),l=100*Im(z))}

I want to draw z in terms of the colour defined by f():

image(z,col=f)
image(f(z))

but these don't work as intended.  How do I use image() to get what I want?
I can get close using plot():

x - runif(1000)
y - (1:1000)/10
g - function(x){hcl(h=80*x,l=(1:1000)/10,c=300)}
plot(x,y,col=g(x),pch=16)

[note that one cannot draw nontrivial contour lines  joining points of 
identical colours on this
plot: top left to lower right goes from pink to black; top right to low 
left goes from yellow to reddy orange]



It'd be nice to make image() do what I want. Anyone?



How about a brute-force approach using rect() ... ?

x - seq(from=0, to=1,len=30)
z - outer(x,1i*x,+)

f - function(z){hcl(h=100*Re(z),l=100*Im(z))}

plot(x, x, type=n)
step - diff(x)[1]/2
xmid - rep(x, 30)
ymid - rep(x, each=30)
rect(xmid - step, ymid - step,
 xmid + step, ymid + step,
 col=f(z), border=NA)
box()

Paul
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[EMAIL PROTECTED]
http://www.stat.auckland.ac.nz/~paul/

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Re: S4 method inheritance

2005-05-24 Thread Robert Gentleman



Ross Boylan wrote:

On Tue, May 24, 2005 at 06:27:56AM -0700, Robert Gentleman wrote:



Duncan Murdoch wrote:


Ross Boylan wrote:



On Mon, 2005-05-23 at 14:41 -0700, Ross Boylan wrote:





Finally, I'm a bit concerned that one article mentioned that S4
inheritance, in practice, is used mostly for data, not methods (Thomas
Lumley, R News 4(1), June 2004: p. 36).  Am I going down a road I
shouldn't travel?



Hmm, maybe I just found out.  If B is an S4 subclass of A (aka extends
A), how does B's method foo invoke A's foo?



Your question doesn't make sense in S4.  In S4, classes don't have 
methods, generics have methods.  There's no such thing as B's method 
or A's method.


You might get what you want with foo(as(bObject, A)) if bObject is an 
instance of class B.




The question assumes that A's foo was defined as an in place function,
so there's no (obvious) named object for it, i.e,
setMethod(A, signature(blah=numeric), function(x) something)


In general it may be best to think of a generic function as a 
dispatching mechanism. For S4 methods are associated with a specific 
generic function. 


specific generic is a reference to the ability to define generics
 within the context of a particular package?



Well, more that you can identify one (either explicitly by its package 
[ie. fully-qualified name], or implicitly by the fact that it is first 
on the search path - the former being prefered). But the notion is that 
there is one and you have asked that your method be made available to 
that one generic function for dispatch. This is in contrast to S3 - 
where no such functionality exists - that I know of; under S3 any method 
is a method for all generic functions of the correct name and the 
programmer has no (easy) control. Under S4 methods are not really 
ordinary functions, should not be called directly and are invoked only 
via calls to the generic (you can of course break all of those rules).




A generic knows about all methods that are associated 
with it, and about no others. 


Presumably setMethod does the association.  Is the where argument
intended to identify which generic method to pick?  The fact that
there is not a package argument to setMethod, as there is to
setGeneric, is a little confusing to me.




 I believe that is the documented behavior. Yes the where argument 
should allow you complete specificity. I will leave it to the auther to 
clarify differences between the where and package arguments in the call 
to setGeneric (or you, if you care to explore the code).


Thus in S4, the little tiff over who owns 
label goes away - they both do - different packages can define
generic 


They is two different packages?  Or is this a reference to my
original confusion about class vs generic ownership of a method?



 It is the two packages. The S langauge allows for the same symbol to 
be bound to different values in different namespaces (in R that is 
becoming explicit, in SPlus it is less so, but still generally true). I 
can think of no good reason to treat generic functions, or any other 
first class object, differently.


HTH,
 Robert



functions for label, or anything else they care to, and users can write 
methods for specific generic

 functions and associate them with a

generic.


...


HTH
  Robert





__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] obtaining first and last record for rows with same identifier

2005-05-24 Thread Francisco J. Zagmutt
If you want to obtain a data frame you can use the functions head and tail 
like:


dat=data.frame(id=rep(1:5,3),num=rnorm(15), num2=rnorm(15))#Creates data 
frame with id
last=do.call(rbind,by(dat,dat$id,tail,1))#Selects the last observation for 
each id
first=do.call(rbind,by(dat,dat$id,head,1))#Selects the first observation 
for each id

newdat=rbind(first,last)#Joins data
newdat=newdat[order(newdat$id),]#sorts data by id

Notice that rownames will give you the original row location of the 
observations selected


I hope this helps

Francisco



From: Berton Gunter [EMAIL PROTECTED]
To: 'Sean Davis' [EMAIL PROTECTED], [EMAIL PROTECTED]
CC: 'rhelp' r-help@stat.math.ethz.ch
Subject: RE: [R] obtaining first and last record for rows with same 
identifier

Date: Tue, 24 May 2005 12:17:58 -0700


I think by() is simpler:

 by(yourframe,factor(yourframe$patid),function(x)x[c(1,nrow(x)),])



-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA

The business of the statistician is to catalyze the scientific learning
process.  - George E. P. Box



 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Sean Davis
 Sent: Tuesday, May 24, 2005 11:38 AM
 To: [EMAIL PROTECTED]
 Cc: rhelp
 Subject: Re: [R] obtaining first and last record for rows
 with same identifier

 If you have your data.frame ordered by the patid, you can use the
 function rle in combination with cumsum.  As a vector example:

   a - rep(c('a','b','c'),10)
   a
   [1] a b c a b c a b c a b c a b c a
 b c a
 [20] b c a b c a b c a b c
   b - a[order(a)]
   b
   [1] a a a a a a a a a a b b b b b b
 b b b
 [20] b c c c c c c c c c c
   l - rle(b)$length
   cbind(l,cumsum(l),cumsum(l)-l+1)
l
 [1,] 10 10  1
 [2,] 10 20 11
 [3,] 10 30 21

 # use the line below to get the length of the block of the dataframe,
 the start, and then end indices
   cbind(l,cumsum(l)-l+1,cumsum(l))
l
 [1,] 10  1 10
 [2,] 10 11 20
 [3,] 10 21 30
  

 Sean


 On May 24, 2005, at 2:27 PM, [EMAIL PROTECTED] wrote:

  I have a dataframe that contains fields such as patid, labdate,
  labvalue.
  The same patid may show up in multiple rows because of lab
  measurements on multiple days.  Is there a simple way to
 obtain just
  the first and last record for each patient, or do I need to
 write some
  code that performs that.
 
  Thanks,
  Steven
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.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://stat.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://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html