[R] {grid} plain units with non NULL data arguments

2007-08-14 Thread Wolfram Fischer
In help(unit) I read:

 The 'data' argument must be a list when the 'unit.length()'
 is greater than 1.  For example, 'unit(rep(1, 3), c(npc,
 strwidth, inches), data=list(NULL, my string, NULL))'.

In the newest R-versions it is not anymore allowed to let strings
in the data-argument for plain units, otherwise one gets the
following error:
Non-NULL value supplied for plain unit

I have some labels. Between them I wanted to set a distance of 1.5 lines.
(I wanted to use that for a grid.layout for a legend:
The space is for the symbols.)

labels - c( ':', 'a', 'bb', 'ccc', '', 'e' )
n - length( labels )
s - as.list( c( labels[1], rep( labels[-1], each=2 ) ) )
u - unit( data=s, x=c( 1, rep( c( 1.5, 1 ), n-1 ) ),
units=c( 'strwidth', rep( c( 'lines', 'strwidth' ), n-1 ) ) )

How can I insert the NULL values into the list ``s''?

To fill every second element of s with NULL, I tried:
s[ 2 * ( 1 : length( labels[-1] ) ) ] - NULL
But this deletes every second element.

The following would work:
s[ 2 * ( 1 : length( labels[-1] ) ) ] - NA
But unit() does not accept NAs.


Regards - Wolfram

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] : regular expressions: escaping a dot

2007-06-28 Thread Wolfram Fischer
What's really the problem with:

 regexpr( '\.odt$', Yodt, perl=TRUE )
Warning: '\.' is an unrecognized escape in a character string
Warning: unrecognized escape removed from \.odt$
[1] 5
attr(,match.length)
[1] 4

I know that I could use:
 regexpr( '[.]odt$', Yodt, perl=TRUE )

But it seems to me that the first expression is also
an accepted regular expression in accordance with perl.

Regards - Wolfram

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] html image maps for panels of a lattice graphic

2007-02-15 Thread Wolfram Fischer
Is there a function to produce images and corresponding
html image maps for the panels of a lattice graphic?

Thanks - Wolfram

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] Problems with 'delay'/'delayedAssign' when installing data package

2007-02-15 Thread Wolfram Fischer
I downloaded:
http://www.bioconductor.org/data/metaData/hgu95av2_1.7.0.tar.gz
described as:
Package: hgu95av2 
Title: A data package containing annotation data for hgu95av2 
Version: 1.7.0 
Created: Wed Jan 12 16:57:23 2005 
Author: Lin,Chenwei 
Description: Annotation data file for hgu95av2 assembled using data
   from public data repositories 
   Maintainer: Lin,Chenwei  [EMAIL PROTECTED]  
   LazyLoad: yes 
   Depends: R(= 2.0.0) 
   License: LGPL 
   Packaged: Thu Mar  3 15:43:00 2005; biocbuild

It is an example database of the geneplotter library.

Trying to install, I got:
$ R CMD INSTALL hgu95av2_1.7.0.tar.gz 

* Installing *source* package 'hgu95av2' ...
** R
** data
** preparing package for lazy loading
Error: 'delay' is defunct.
Use 'delayedAssign' instead.
See help(Defunct)
Execution halted
ERROR: lazy loading failed for package 'hgu95av2'
** Removing '/usr/local/lib64/R-2.4.1/library/hgu95av2'

How to by-pass this problem?

Thanks - Wolfram

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] lattice: defining an own function using args for formula and groups

2006-12-08 Thread Wolfram Fischer

x.fun - function( formula, data ) dotplot( formula, data )
x.grp - function( formula, groups, data ) dotplot( formula, groups, data )

data( barley )

 x.fun( variety ~ yield | site, data=barley )
# no problem

 dotplot( variety ~ yield | site, groups=year, data=barley )
# no problem

 x.grp( variety ~ yield | site, groups=year, data=barley )
object year not found # that's my error, so I do:

 x.grp( variety ~ yield | site, groups=barley$year, data=barley )
Error in eval(expr, envir, enclos) : numeric 'envir' arg not of length one

 traceback()
9: eval(substitute(groups), data, environment(formula))
8: bwplot.formula(x = formula, data = c(2, 2, 2, 2, 2, 2, 2, 2,  ...

Why it is a problem calling x.grp() and no problem calling x.fun() ?
What could I do to get work x.grp() ?

Thanks - Wolfram

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] Why the factor levels returned by cut() are not ordered?

2006-11-29 Thread Wolfram Fischer
What is the reason, that the levels of the factor
returned by cut() are not marked as ordered levels?

 is.ordered( cut( breaks=3, sample(10 ) ) )
FALSE

 help(factor)
...
If 'ordered' is 'TRUE', the factor levels are assumed to be ordered.
...

Wolfram

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] merge dataframes with conditions formulated as logical expressions

2006-06-14 Thread Wolfram Fischer
I have a data.frame df containing two variables:
GRP: Factor
VAL: num

I have a data.frame dp containing:
GRP: Factor
MIN.VAL: num
MAX.VAL: num
VAL2: num
with several rows per GRP
where dp[i-1, MAX.VAL]  dp[i, MIN.VAL]
within the same GRP.

I want to create df[i, VAL2] - dpp[z, VAL2] 
withi along df 
and dpp - subset( dp, GRP = df[i, GRP] )
so that it is true for each i:
df[i, VAL]  dpp[z, MIN.VAL]
   and  df[i, VAL] = dpp[z, MAX.VAL]

Is there an easy/efficient way to do that?

Example:
df - data.frame( GRP=c( A, A, B ), VAL=c( 10, 100, 200 ) )
dp - data.frame( GRP=c( A, A, B, B ),
MIN.VAL=c( 1, 50, 1, 70 ), MAX.VAL=c( 49, 999, 59, 999 ), 
VAL2=c( 1.1, 2.2, 3.3, 4.4 ) )

The result should be:
df$VAL2 - c( 1.1, 2.2, 4.4 )

Thanks - Wolfram

__
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] merge dataframes with conditions formulated as logical expressions

2006-06-14 Thread Wolfram Fischer
--- Reply to: ---
Date:14.06.06 16:17 (+)
From:Adaikalavan Ramasamy [EMAIL PROTECTED]
Subject: Re: [R] merge dataframes with conditions formulated as logical 
expressions

 You have discontinuity between your MIN.VAL and MAX.VAL for a given
 group. If this is true in practise, then you may want to check and
 report when VAL is in the discontinuous region.

Your solution without concerning discontinuity is better
because it is more general.

 Here is my solution that ignores that (and only uses MIN.VAL and
 completely disrespecting MAX.VAL). Not very elegant but should do
 the trick.
 
 
  df - data.frame( GRP=c( A, A, B ), VAL=c( 10, 100, 200 ) )
  dp - data.frame( GRP=c( A, A, B, B ), MIN.VAL=c( 1, 50, 1,
 70 ), MAX.VAL=c( 49, 999, 59, 999 ),  VAL2=c( 1.1, 2.2, 3.3, 4.4 ) )
 
  x - split(df, df$GRP)
  y - split(dp, dp$GRP)
 
  out - NULL
  for(g in names(x)){
 
xx - x[[g]]
yy - y[[g]]
 
w   - cut(xx$VAL, breaks=c(yy$MIN.VAL, Inf), labels=F)
tmp - cbind(xx, yy[w, VAL2])
colnames(tmp) - c(GRP, VAL, VAL2)
out - rbind(out, tmp)
  } 
  out
 
 Regards, Adai

Thanks for this solution.

I did not yet try to program a conventional solution
because I thought there would be a nice shortcut in R
to solve the problem comparably elegantly as in SQL:
select df.*, dp.VAL2
from df, dp
where df.GRP = dp.GRP
  and df.VAL  dp.MIN_VAL
  and df.VAL = dp.MAX_VAL

Wolfram

 On Wed, 2006-06-14 at 16:55 +0200, Wolfram Fischer wrote:
  I have a data.frame df containing two variables:
  GRP: Factor
  VAL: num
  
  I have a data.frame dp containing:
  GRP: Factor
  MIN.VAL: num
  MAX.VAL: num
  VAL2: num
  with several rows per GRP
  where dp[i-1, MAX.VAL]  dp[i, MIN.VAL]
  within the same GRP.
  
  I want to create df[i, VAL2] - dpp[z, VAL2] 
  withi along df 
  and dpp - subset( dp, GRP = df[i, GRP] )
  so that it is true for each i:
  df[i, VAL]  dpp[z, MIN.VAL]
 and  df[i, VAL] = dpp[z, MAX.VAL]
  
  Is there an easy/efficient way to do that?
  
  Example:
  df - data.frame( GRP=c( A, A, B ), VAL=c( 10, 100, 200 ) )
  dp - data.frame( GRP=c( A, A, B, B ),
  MIN.VAL=c( 1, 50, 1, 70 ), MAX.VAL=c( 49, 999, 59, 999 ), 
  VAL2=c( 1.1, 2.2, 3.3, 4.4 ) )
  
  The result should be:
  df$VAL2 - c( 1.1, 2.2, 4.4 )
  
  Thanks - Wolfram
  
  __

__
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] lattice: calling functions

2006-02-14 Thread Wolfram Fischer
I defined three functions:

 fun0 - function( x=1:5, y=1:5, ... ) xyplot( y ~ x, ... )

 fun1 - function( x=1:5, y=1:5, ... ) fun2( y ~ x, ... )
 fun2 - function( ... ) xyplot( ... )

The call of fun0() works as expected.

The call of fun1() causes the following error:
'Error in eval(expr, envir, enclos) : object y not found'

How should I define fun2 to avoid the error?

Thanks - Wolfram

__
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] automated response

2005-07-22 Thread Wolfram Fischer
Zu Ihrer Information:

Ihre Post kann im Moment nicht sofort bearbeitet werden,
denn das Buero bleibt geschlossen bis am 7.8.2005.


Buecherbestellungen koennen Sie direkt senden an:
- in der Schweiz: mailto:[EMAIL PROTECTED]
- in Deutschland und Oesterreich: mailto:[EMAIL PROTECTED]

Wolfram Fischer - ZIM

__
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] cmdscale: missing dimnames in R 2.1.0

2005-05-03 Thread Wolfram Fischer - Z I M
When running the first example of cmdscale I got in R 2.0.1:

 loc-cmdscale(eurodist)
 str(loc)
 num [1:21, 1:2] 2290.3 -825.4   59.2  -82.8 -352.5 ...
 - attr(*, dimnames)=List of 2
  ..$ : chr [1:21] Athens Barcelona Brussels Calais ...
  ..$ : NULL


In R 2.1.0 I get:

 loc-cmdscale(eurodist)
 str(loc)
 num [1:21, 1:2] 2290.3 -825.4   59.2  -82.8 -352.5 ...
 - attr(*, dimnames)=List of 2
  ..$ : NULL
  ..$ : NULL

I miss the names of the cities. What can I do?

Thanks - Wolfram

__
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] function corresponding to map of perl

2005-04-15 Thread Wolfram Fischer
--- In reply to: ---
Date:15.04.05 08:08 (+0200)
From:Wolfram Fischer [EMAIL PROTECTED]
Subject: [R] function corresponding to map of perl

 Is there a function in R that corresponds to the
 function ``map'' of perl?
 
 It could be called like:
   vector.a - map( vector.b, FUN, args.for.FUN )
 
 It should execute for each element ele.b of vector.b:
   FUN( vector.b, args.for.FUN)
 
 It should return a vector (or data.frame) of the results
 of the calls of FUN.
 
 It nearly works using:
apply( data.frame( vector.b ), 1, FUN, args.for.FUN )
 But when FUN is called ele.b from vector.b is no known.

Here I made a mistake. I realised now that ``apply'' does the job,
e.g.
apply( data.frame( 1:3 ), 1, paste, sep='', X )

Wolfram

__
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] function corresponding to map of perl

2005-04-14 Thread Wolfram Fischer
Is there a function in R that corresponds to the
function ``map'' of perl?

It could be called like:
vector.a - map( vector.b, FUN, args.for.FUN )

It should execute for each element ele.b of vector.b:
FUN( vector.b, args.for.FUN)

It should return a vector (or data.frame) of the results
of the calls of FUN.

It nearly works using:
 apply( data.frame( vector.b ), 1, FUN, args.for.FUN )
But when FUN is called ele.b from vector.b is no known.

Thanks - Wolfram

__
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 change letters after space into capital letters

2005-04-11 Thread Wolfram Fischer
What is the easiest way to change within vector of strings
each letter after a space into a capital letter?

E.g.:
  c( this is an element of the vector of strings, second element )
becomes:
  c( This Is An Element Of The Vector Of Strings, Second Element )

My reason to try to do this is to get more readable abbreviations.
(A suggestion would be to add an option to abbreviate() which changes
letters after space to uppercase letters before executing the abbreviation
algorithm.)

Thanks - Wolfram

__
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 test the existence of a name in a dataframe

2004-12-07 Thread Wolfram Fischer
I wanted to test if there exists already a name (which is
incidentally a substring of another name) in a dataframe.
I did e.g.:

 data(swiss)
 names(swiss)
[1] FertilityAgriculture  Examination  Education   
[5] Catholic Infant.Mortality

 ! is.null(swiss$EduX)
[1] FALSE

 ! is.null(swiss$Edu)
[1] TRUE

I did not expect to get TRUE here because ``Edu'' does not exist
as name of ``swiss''.

I did finally:
 'Edu' %in% names(swiss)
for which I got the expected FALSE.

My question: What is the recommended way to do such a test?

Thanks - Wolfram Fischer

__
[EMAIL PROTECTED] 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] split() and paste() a vector to get a multi line string

2004-12-01 Thread Wolfram Fischer
How can I get a multi line string from a vector of string tokens
in an easy manner (e.g. for the use as xlab of a plot)?

I have e.g.:
   tokens - letters[1:5]
[1] a b c d e

I search:
[1] a, b, c\nd, e

I tried:
   nlines - 2
   ntokens.line - ceiling(length(tokens) / nlines)
   token.list - split(tokens, rep( 1:ntokens.line, each=ntokens.line, 
 len=length(tokens)))
$1
[1] a b c
$2
[1] d e

I could work with a data.frame, e.g.:
   paste(collapse='\n', apply(token.df, MARGIN=1, FUN=paste, collapse=', 
 '))

but I got an error when converting token.list to a data frame:
   token.df - data.frame( token.list )
Error in data.frame(1 = c(a, b, c), 2 = c(d, e), check.names = 
FALSE) : 
arguments imply differing number of rows: 3, 2

What can I do (other than using a loop now)?

Thanks - Wolfram

__
[EMAIL PROTECTED] 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] lattice: ordering the entries in a dotplot of a vector

2004-11-10 Thread Wolfram Fischer
I tried:
n - 9
x - sample(n)
names(x) - LETTERS[1:n]
dotplot( sort(x) )

The lines of the dotplot are not ordered according to the values of x
(but according to the names of x).

So I did:

dfx - data.frame( x=x, label=factor( names(x), names(x)[order(x)] ) )
dotplot( label ~ x, data=dfx )

So I got what I wanted.

My question: Is there an easier solution for doing that?

Wolfram

__
[EMAIL PROTECTED] 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] ave gives unexpected NA's

2004-10-22 Thread Wolfram Fischer
[R 2.0.0 on Linux]

I tried:
 df - data.frame(
 grp1=factor( c('A' ,'A' ,'A' ,'D', 'D' ) ) ,
 grp2=factor( c('a1','a2','a2','d1','d1') )
 )
 df
  grp1 grp2 val
1A   a1   1
2A   a2   2
3A   a2   4
4D   d1   8
5D   d1  16

I got:
 with( df, ave( val, grp1, grp2, FUN=sum ) )
[1]  1 24 24 NA NA

I have expected to get:
[1]  1 6 24

Do I misunderstand something with `ave' or is there a bug?

Thanks - Wolfram

__
[EMAIL PROTECTED] 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] Chernoff faces

2004-10-08 Thread Wolfram Fischer
  Kenneth == Kenneth Cabrera [EMAIL PROTECTED] writes:
 
 Kenneth Hello everybody: Does any one has a function to build Chernoff
 Kenneth faces?
 
 Many of us don't think it's worth them.
 But we know that opinions differ and gladly incorporate
 (good quality) submissions of source code.
 
 R *is* an open source project and to some extent a community effort.
 Please don't hesitate to contribute and enter the hall of fame of R
 contributors :-)
 
 Martin 

An example code from H.P. Wolf (2003) can be found at:
http://www.wiwi.uni-bielefeld.de/~wolf/ : S/R - functions : faces

Wolfram

__
[EMAIL PROTECTED] 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] inverse function of order()

2004-10-04 Thread Wolfram Fischer
I have:

 d - sample(10:100, 9)
 o - order(d)
 r - d[o]

How I can get d (in the original order), knowing only r and o?

Thanks - Wolfram

__
[EMAIL PROTECTED] 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] Adding ranks to a repeatedly ragged array

2004-09-13 Thread Wolfram Fischer
How can I add an extra column containing the rank
to a ragged array indexed by more than one grouping
factors?

E.g. with the barley dataset: 
How can I to add an additional column ``rank''
containing the rank of the ``yield'' of
the different varieties in relation to the indices
``year'' and ``site'' to the barley dataframe?

I achieved to calculate the ranks with:
rank.lists -
with( barley, tapply( yield, list( site=site, year=year ), rank ) )
but I do not manage to merge this result
to the original dataframe ``barley''.

Thanks!

Wolfram

__
[EMAIL PROTECTED] 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] variable values in plotmath expressions

2004-09-03 Thread Wolfram Fischer
I tried:

t - sample text
x - 333

plot( 1, 1
, main=expression( main[x1] )
, xlab=expression( paste( t, xlab[x2] ) )
, sub=parse( text = paste( sub[, x, ] ) )
)

The displayed labels for ``main'' and ``sub'' are as expected.
But ``xlab'' shows only t not sample text.
How can I insert the string on which ``t'' points?

I tried e.g.:
, ylab=parse( text = paste( t, ylab[, x, ] ) )
but I received an error (as suspected).

Wolfram

__
[EMAIL PROTECTED] 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] Getting elements of a matrix by a vector of column indices

2004-07-08 Thread Wolfram Fischer
I have e.g.
t - matrix( nrow=2, ncol=3, byrow=TRUE, c('a1','a2','a3','b1','b2','b3') )
and
i - c( 3, 2)

Is it possible to formulate a simple expression that gets
c( t[ 1, i[1] ], t[ 2, i[2] ] )
(and so on for longer matrices)?

The result would be:
[1] a3 b2

Thanks - Wolfram

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


Re: [R] Getting elements of a matrix by a vector of column indice s

2004-07-08 Thread Wolfram Fischer
Thanks for you answer! It works.

   m - outer(letters[1:5], 1:4, paste, sep=)

The following works with the help of your proposition:
   rowidx.n - c( 2, 3, 4)
   colidx.n - c( 1, 3, 2)
   idx.n - cbind( rowidx.n, colidx.n )
   m[idx.n]
[1] b1 c3 d2

In my real data there was an additional difficulty:
I had names of rows and columns as indices:
   rownames(m) - paste('R', 1:nrow(m), sep=)
   colnames(m) - paste('C', 1:ncol(m), sep= )

And the following did not work anymore:
   rowidx - c( 'R2', 'R3', 'R4' )
   colidx - c( 'C1', 'C3', 'C2' )
   idx - cbind( rowidx, colidx )
   m[idx]
NA NA NA NA NA NA 
  NA   NA   NA   NA   NA   NA 

Do you have another suggestion? - Thanks! Wolfram

--- In reply to: ---
Date:08.07.04 08:21 (-0400)
From:Liaw, Andy [EMAIL PROTECTED]
Subject: RE: [R] Getting elements of a matrix by a vector of column indice s

 See if the following helps:
 
  m - outer(letters[1:5], 1:4, paste, sep=)
  m
  [,1] [,2] [,3] [,4]
 [1,] a1 a2 a3 a4
 [2,] b1 b2 b3 b4
 [3,] c1 c2 c3 c4
 [4,] d1 d2 d3 d4
 [5,] e1 e2 e3 e4
  idx - c(2, 1, 3, 4, 2)
  m[cbind(1:5, idx)]
 [1] a2 b1 c3 d4 e2
 
 Andy
 
  From: Wolfram Fischer
  
  I have e.g.
  t - matrix( nrow=2, ncol=3, byrow=TRUE, 
  c('a1','a2','a3','b1','b2','b3') )
  and
  i - c( 3, 2)
  
  Is it possible to formulate a simple expression that gets
  c( t[ 1, i[1] ], t[ 2, i[2] ] )
  (and so on for longer matrices)?
  
  The result would be:
  [1] a3 b2
  
  Thanks - Wolfram
  
  __
  [EMAIL PROTECTED] mailing list
  https://www.stat.math.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide! 
  http://www.R-project.org/posting-guide.html
  
  
 
 
 --
 Notice:  This e-mail message, together with any attachments, contains information of 
 Merck  Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), 
 and/or its affiliates (which may be known outside the United States as Merck Frosst, 
 Merck Sharp  Dohme or MSD and in Japan, as Banyu) that may be confidential, 
 proprietary copyrighted and/or legally privileged. It is intended solely for the use 
 of the individual or entity named on this message.  If you are not the intended 
 recipient, and have received this message in error, please notify us immediately by 
 reply e-mail and then delete it from your system.
 --

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


[R] lattice: cumsum and xyplot

2004-06-11 Thread Wolfram Fischer
I want to display cumulative summary functions with lattice.

First I tried to get cumulated data:
library(lattice)
data(barley)

d.cum - with( barley, by( yield, INDICES=list(site=site,year=year), FUN=cumsum ) )

I got a list of vectors.
I tried to get a dataframe which I could use in xyplot.
But neither of the following functions led to the goal:

d.cum.df1 - as.data.frame.list( d.cum )
d.cum.df2 - as.data.frame.array( d.cum )


Then I tried to solve my problem within the panel function.
But now I had to set a value for ylim.

test.xyplot - function( data=barley, yr=1931, ymax=600, type='l', ... ){
print( xyplot( data=data, subset=year==yr
, type=type
, panel=function( x, y, ... ){
panel.xyplot( x, cumsum(y), ... )
}
, ylim=c( 0, ymax )
, yield ~ variety | site
, scales=list( x=list( alternating=1, rot=90 ) )
, ...
))
}

What could I do to get a dataframe containing the cumulative values
of ``yield'' which I could use to get the cumulative summary plots?

Thanks - Wolfram

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


Re: [R] lattice: cumsum and xyplot

2004-06-11 Thread Wolfram Fischer
--- In reply to: ---
Date:11.06.04 09:33 (+0200)
From:Wolski [EMAIL PROTECTED]
Subject: Re: [R] lattice: cumsum and xyplot

 Hi!
 To get a data.frame
 
 as.data.frame(do.call(rbind,d.cum))

Thanks for this interesting hint.
To get the lost names of factors again,
I tried now the following solution:

data(barley)
d.cum -
with( barley, by( yield, INDICES=list(site=site,year=year), FUN=function(x)x ) 
)

test.bylist2dataframe - function( bylist, col.names=NULL ){
veqq - as.data.frame( do.call( 'rbind', d.cum ) )
if( ! is.null( col.names ) ) colnames( veqq ) - col.names
viqt.vars - names( dimnames(bylist) )
if( length( viqt.vars ) == 2 ){
veqq[,viqt.vars[1]] - as.factor(
rep( dimnames( bylist )[[viqt.vars[1]]], times=dim(bylist)[2] 
) )
veqq[,viqt.vars[2]] - as.factor(
rep( dimnames( bylist )[[viqt.vars[2]]], each=dim(bylist)[1] ) 
)
}
veqq
}

d.cum.dfr - test.bylist2dataframe( d.cum, col.names=unique( as.character( 
barley$variety ) ) )

But now I have the following problems:
- ``d.cum.dfr'' is not yet normalised.
- My solution works only for two ``INDICES''.

So, what to do? - Wolfram

 *** REPLY SEPARATOR  ***
 
 On 6/11/2004 at 9:17 AM Wolfram Fischer wrote:
 
 I want to display cumulative summary functions with lattice.
 
 First I tried to get cumulated data:
 library(lattice)
 data(barley)
 
 d.cum - with( barley, by( yield, INDICES=list(site=site,year=year),
 FUN=cumsum ) )
 
 I got a list of vectors.
 I tried to get a dataframe which I could use in xyplot.
 But neither of the following functions led to the goal:
 
 d.cum.df1 - as.data.frame.list( d.cum )
 d.cum.df2 - as.data.frame.array( d.cum )
 
 
 Then I tried to solve my problem within the panel function.
 But now I had to set a value for ylim.
 
 test.xyplot - function( data=barley, yr=1931, ymax=600, type='l',
 ... ){
 print( xyplot( data=data, subset=year==yr
 , type=type
 , panel=function( x, y, ... ){
 panel.xyplot( x, cumsum(y), ... )
 }
 , ylim=c( 0, ymax )
 , yield ~ variety | site
 , scales=list( x=list( alternating=1, rot=90 ) )
 , ...
 ))
 }
 
 What could I do to get a dataframe containing the cumulative values
 of ``yield'' which I could use to get the cumulative summary plots?
 
 Thanks - Wolfram

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


[R] mosaicplot: color recycling and defaults of xlab/ylab

2004-04-23 Thread Wolfram Fischer

PROBLEMS

(a) colors are not recycled over all fields of a mosaicplot.
(b) default xlab/ylab annotation does not always correspond to ``dir''.


EXAMPLE

par( mfcol = c( 2, 3 ) )
haircolors - c( 'black', 'brown', 'red', 'sandybrown' )
eyecolors - c( 'saddlebrown', 'skyblue', 'sandybrown', 'seagreen2' )

mosaicplot( main='(1)', ~Eye + Hair, color=haircolors, data=HairEyeColor)
mosaicplot( main='(2)', ~Hair + Eye, color=eyecolors, data=HairEyeColor)
mosaicplot( main='(3)', ~Eye + Hair, color=rep( each=4, eyecolors), data=HairEyeColor)
mosaicplot( main='(4)', ~Hair + Eye, color=rep( each=4, haircolors ), 
data=HairEyeColor )
mosaicplot( main='(5)', ~Eye + Hair, color=haircolors, dir=c('h','v'), 
data=HairEyeColor )
mosaicplot( main='(6)', ~Eye + Hair, color=haircolors, dir=c('h','v'), 
data=HairEyeColor, xlab='Hair', ylab='Eye' )


COMMENTS AND QUESTIONS

(1) and (2) are normal mosaicplots with colors of fields
set in correspondance to the colors of hairs resp. of eyes.

(3) is like (1) but I tried to get ``eyecolors''.
Problem (a); what could I do to get ``eyecolors'' in the fields?

(4) is like (2) but the colors should be ``haircolors''.
Same problem as in (3).

(5) is a mirrored version of (1):
I saw: Mirroring does not change the attribution of colors.
If all fields of each line would have the same color
(e.g. the last line should be green)
I could change ``colors=eyecolors''
and I would receive the graphic I searched.

Here I encountered Problem (b):
In this case, default xlab should be 'Hair' and ylab should be 'Eye'
(6) I solved that problem provisionally by using the xlab and ylab options.



Thanks - Wolfram

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


[R] converting lists got by tapply to dataframes

2004-03-10 Thread Wolfram Fischer
I have two lists:

xa - list( X=c(1,2,3), Y=c(4,5,6), Z=c(7,8,9) )

xb - with( barley, tapply( X=seq(1:nrow(barley)), INDEX=site
, FUN=function(z)yield[z]))

I can convert xa to a dataframe easily with:
as.data.frame(xa)

But if i try the same with xb I get:
as.data.frame(xb)
Error in as.data.frame.default(xb) :
can't coerce array into a data.frame

What helps?

(NB: I know the formula for xb is stupid, but it generates the same
type of list as the list I get from my real problem.)

Wolfram

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


Re: [R] lattice: adding text between grouped panels?

2004-01-22 Thread Wolfram Fischer
--- In reply to Deepayan Sarkar: ---
Date:20.01.04 10:40 (-0600)

Thank you again for your very helpful and inspiring answer!
Some additional questions will follow below.

 On Tuesday 20 January 2004 04:14, Wolfram Fischer wrote:
  How one can add a text (e.g. the labels of an axis)
  in a space between grouped panels which was created
  by using the argument ``between''?
 
  Example:
  data(barley)
  dotplot(variety ~ yield | site * year, data=barley,
  between=list(x=c( 0, 0, 6 ))
  How to add labels for the y axis in the space in the middle?
 
 Formally, there's no mechanism to do that. However, most reasonable usage can 
 be achieved by the panel function, e.g. (to add a y-axis tick and label at 
 the mean y-value):
 
 panel = function(x, y, ...) {
 panel.xyplot(x, y, ...)
 grid.yaxis(at = mean(y))
 }
 
 Normally, this would not work because all graphical output produced by the 
 panel function is 'clipped', i.e., anything falling outside the panel is not 
 drawn. This can be controlled by the setting
 
  trellis.par.get(clip)
 $panel
 [1] TRUE
 
 $strip
 [1] TRUE
 
 
 So you need to do something like 
 
  lset(list(clip = list(panel = FALSE)))
 
 before calling xyplot (or whatever). Of course, turning clipping off has the 
 disadvantage that unintended things can happen. Most panel functions are 
 safe, but some are not (like panel.abline).

This good idea seams to work. But:

- How can I determine in which panel I am?
  Principally I could to that by using a strip function.
  But the presence of a strip function allways (?) allocates
  space for the strip(s). How can I determine the panel
  when I don't want to display strips?


 Just in case you missed it, there's a much safer way to add customized tick 
 marks and labels to each panel, using the scales argument. From ?xyplot, 
 
 
   scales: list determining how the x- and y-axes (tick marks and
 
   [...]
 
   at: location of tick marks along the axis (in native
   coordinates), or a list as long as the number of panels
   describing tick locations for each panel.
 
   labels: Labels (strings or expressions) to go along with
   'at'. Can be a list like 'at' as well.
 
 But this may not be what you want.

Thanks for this hint!

When I wanted add labels to each panel group of:

my.barley - subset( barley, ! ( site == Grand Rapids  year == 1932 ) )

with( my.barley, dotplot(variety ~ yield | year * site, layout=c(6,2)
, between=list(x=c(0,6


I tried:
with( my.barley, dotplot(variety ~ yield | year * site, layout=c(6,2)
, scales=list( rot=0, y=list( relation='sliced'
, at = rep( list( 1: nlevels( variety ), NULL ), 6 )

I used:
- ``sliced'' because there was an error when I did not use it:
the at and labels components of scales may not be
lists when relation = same.
- the at-option to eliminate the yaxis-labels within the panel groups.

I received:
- Several warning messages.
- No axis labels for panel groups with an empty first panel.
- Gigant scales in the second panels of each panel group.

What can I do to:
- Have normal scales in the second panels of each panel group?
- Eliminate the space between the first and the second panel
  in each group.

 Hth,
 
 Deepayan

Thanks! Wolfram

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


[R] lattice: adding text between grouped panels?

2004-01-20 Thread Wolfram Fischer
How one can add a text (e.g. the labels of an axis)
in a space between grouped panels which was created
by using the argument ``between''?

Example:
data(barley)
dotplot(variety ~ yield | site * year, data=barley,
between=list(x=c( 0, 0, 6 ))
How to add labels for the y axis in the space in the middle?


Thanks

Wolfram

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


[R] grid: dividing units by numbers

2003-10-29 Thread Wolfram Fischer
How can I divide a unit by an number
or average a vector of units, e.g.:

u1 - unit( 3, 'npc' )
u2 - unit( 6, 'npc' )

u1 / 2
( u1 + u2 ) / 2
mean( unit.c(u1,u2) )

I would use that e.g. to to calculate the coordinates
of the midpoint of a line.

Wolfram

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] How can strheight be calculated in lattice/grid?

2003-10-27 Thread Wolfram Fischer
If I have drawn a string with ``ltext( x, y, labels=first string )''
how can a draw a second string just one line (or strheight(X)
below the first string regardless of the size and scales of the panel?

Thanks
Wolfram

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] lattice/levelplot: panels with values can be empty

2003-10-09 Thread Wolfram Fischer
I tried:
library(lattice)

F0  - c( 'A', 'A', 'B', 'B' )
F1  - c(  1 ,  1 ,  1 ,  2 )
F2  - c(  8 ,  9 ,  8 ,  9 )
VAL - c(  20,  50,  10,  60 )
df - data.frame( F0, F1, F2, VAL )

levelplot( VAL ~ F1 * F2 | F0, data=df )

I got an empty field for F0 == 'A'
and a colored field for F0 == 'B'.
I expected two colored fields. - What can I do?

Thanks. Wolfram

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] problem with srt vector in xyplot {lattice}

2003-01-24 Thread Wolfram Fischer - Z/I/M
[ R 1.6.1 ]

PROBLEM
The plot of the appended code does produce 
a postscript file which is not interpretable
by gv under Linux.

REMARK
If the srt argument is commented out or set to a constant
like 45 or 90, the ps file becomes interpretable.

CODE
xytest - function( ... ){
with( airquality, { print( xyplot(
  Ozone ~ Temp | Month
, panel = function( x, y, subscripts, ... ){
ltext( x, y, Temp[subscripts]
, srt = 45 / max( Solar.R, na.rm=T ) * Solar.R
)
}
, ...
)
)})
}

xytest()## works!

trellis.device( 'postscript', file = 'x.ps' )
xytest()
dev.off()


QUESTION
Is there a workaround?


Wolfram

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



[R] conversion of a list of matrices into a dataframe

2003-01-23 Thread Wolfram Fischer
DATA
I have data from two (or more) locations with ID: 'A' and 'B'
for three (or more) YEARS: 1999 to 2001
of two (or more) variables: VAR1, VAR2.

 x
  ID YEAR VAR1 VAR2
1  A 199992
2  B 199989
3  A 200023
4  B 200034
5  A 200195
6  B 200172

DESIRED RESULT
I want to calculate the rank of the values of each variable
for each location (ID) in every year.
I want to get the ranks in a dataframe 'x.ranked'
having the same structure as the original dataframe 'x'
(which should be ready for the use by lattice functions).

 x.ranked
  ID YEAR VAR1 VAR2
1  A 199921
2  B 199912
3  A 200011
4  B 200022
5  A 200122
6  B 200111


EXAMPLE CODE
x - data.frame(
  ID= rep( c('A', 'B' ), 3 )
, YEAR  = rep( c( 1999, 2000, 2001 ), each=2 )
, VAR1  = c( 9, 8,  2, 3,  9, 7 )
, VAR2  = c( 2, 9,  3, 4,  5, 2 )
)
vars - c( 'VAR1', 'VAR2' )

fun - function( x, group=NULL ){
if( ! is.null(group) )  by( x, group, fun )
else if( ! is.vector(x) )   sapply( x, fun )
elserank( x )
}

x.ranked - fun( x[,vars], x$YEAR )


OBTAINED RESULT
I got the right values by using the function 'fun',
but the result does not have the desired structure.
Can anyone help me to get the desired structure?

 x.ranked
group: 1999
 VAR1 VAR2
[1,]21
[2,]12
--
group: 2000
 VAR1 VAR2
[1,]11
[2,]22
--
group: 2001
 VAR1 VAR2
[1,]22
[2,]11


Wolfram

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



[R] lattice: cloud: aspect ratio, labels, vertical lines

2003-01-15 Thread Wolfram Fischer
I am interested to know how to make for clouds:
- aspect ratio = 1
- labels attached to points
- vertical lines from the points to the x/y base plane

I tried:
t = c( 'A', 'B', 'C', 'D' )
x = c( 100,   0, 200, 100 )
y = c(   0, 100,   0, 100 )
z = c(  80,   0,  20,  40 )

q = data.frame( x, y, z )
rownames( q ) = t

print(cloud( z ~ x * y, data = q, type = c( 'p', 'h' )
, scales = list( arrows=FALSE )
, aspect = c( max(y)/max(x), max(z)/max(x) )
))


My questions:
- Is there an easier way to tell that aspect ratio should be 1
  on all dimensions, especially without the precalculations
  of max(...)?
- type = 'h' does not work as I expected. What to do?
- How can I get the labels of t into the graphic?

Thanks

Wolfram

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help