Re: [R] plot pch

2006-11-09 Thread Joris De Wolf
Somebody will come up with a more elagant solution, but a quick fix 
would be:

plot(df$Y[df$pch_type != "21"],df$X[df$pch_type != "21"], 
pch=df$pch_type[df$pch_type != "21"])
points(df$Y[df$pch_type == "21"],df$X[df$pch_type == "21"],pch= 21)



Marc Bernard wrote:
> Dear All,
>
>   I  have a data as follows:
>
>   ID <- 1:100
>   Y <- rnorm(100)
>   X <- rnorm(100)
>   type <- as.factor(rep(1:3,100,time=1))
>   df <- as.data.frame(cbind(ID, Y,X,type))
>
>   I want to plot Y versus X  by specifying the pch to be as follows:
>
>   Subjects having type = 1 must be plotted with a character pch =  "A"
>   Subjects having type = 2 must be plotted with a pch =  "B"
>   Subjects having type = 3 must be plotted with a pch =  21
>
>   I used the follwomg:
>
>   df$pch_type = recode(df$type, "1 = 'A'; 2 = 'B'; else = '21' " )
>   plot(df$Y,df$X,pch= df$pch_type)
>   This  plots subjects for type 1 and 2 with  symbols A and B (this is what 
> expected) however subjects with type = 3 are plotted with a charcater 2 
> instead of a pch=21. I understand that this is due to the fact that the 
> created vector "type_pch" cannot be a mixture between characters and numerics 
> ... I tried to use a list for that purpsoe but fail...
>
>   Any suggestions would be grateful,
>
>   Many thanks,
>
>   Bernard 
>
> 
> 
> 
>   
> -
> 
>   [[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
> and provide commented, minimal, self-contained, reproducible code.

-- 

==
Joris De Wolf
CropDesign N.V.
Biometrician Plant Evaluation
Technologiepark 3
B-9052 Zwijnaarde
Belgium
Tel. : +32 9 242 91 55
Fax  : +32 9 241 91 73
==


confidentiality notice:
The information contained in this e-mail is confidential and...{{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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] continuation lines in R script files

2006-09-06 Thread Joris De Wolf
Are your sure your second solution does not work? Try again...

Evan Cooch wrote:
> When I have to enter a very large matrix into the R console, I can make 
> use of the continuation feature in the console to enter the matrix in 
> pieces (e.g.,  on a row by row basis). So, for example, the console 
> would show the "+" sign for continuation lines - something like what 
> I've written below:
> 
> a=matrix(c(0,20,50,
> +  0.05,0,0,
> + 0,0.1,0),
> + 3,3,byrow=T)
> 
> (obviously, for a matrix this small - 3x3 - I could enter it all on a 
> single line, this is just to demonstrate)
> 
> My question is - how do you accomplish the same thing in an R script 
> file? I've tried literally copying the preceding - syntax error at the 
> second line. I've also tried
> 
> 
> a=matrix(c(0,20,50,
> 0.05,0,0,
> 0,0.1,0),
> 3,3,byrow=T)
> 
> Again, syntax error, at the second line...
> 
> After multiple searches for 'continuation line', with no luck 
> (everything I found refers to the R console, no a script file), I'll ask 
> here. Basically, I want to know how to get an R script to handle a 
> structure entered over multiple lines (e.g., a matrix). This is default 
> behaviour in .m files in Matlab, and most other environments I've ever 
> worked in (e.g., SAS looks for the ; to indicate end of a line).
> 
> Thanks in advance...
> 
> __
> 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.


confidentiality notice:
The information contained in this e-mail is confidential and...{{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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] newbie question about index

2006-09-01 Thread Joris De Wolf
what about:
b <- rbind(1*(a==1),1*(a==2),1*(a==3))


z s wrote:
> Hi,
> 
>   I am trying to convert a variable a = sample(1:3,100,rep = T) represents 
> choices into a 3X100 dummy varible b with corresponding element set to 1 
> otherwise 0.
> eg.
> 
> a: 1 3 2 1 2 3 1 1
> 
> b: 1 0 0 1 0 0 1 1..
> 0 0 1 0 1 0 0 0...
> 0 1 0 0 0 1 0 0...
> 
>  Is there something like b[a] =1 existing? I could not figure this out myself.
> 
>   
> -
>  Mp3·è¿ñËÑ-иèÈȸè¸ßËÙÏ   
>   [[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
> and provide commented, minimal, self-contained, reproducible code.


confidentiality notice:
The information contained in this e-mail is confidential and...{{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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting a stepwise increasing function

2006-08-31 Thread Joris De Wolf
see
plot(y~x,type="s")

Öhagen Patrik wrote:
> Dear All, Sorry for spamming you with something trivial. I would like to plot 
> a "stepwise increasing function" (if that makes sense? See crude ASCHII art 
> below). I think there is some clever paramter for solving the problem but I 
> just cannot find it.
> 
> 
> ___|
> |
> |
> |
> |
> |
> |
> 
> 
> Thank you in advance!
> 
> 
> Cheers, Patrik
> 
> __
> 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.


confidentiality notice:
The information contained in this e-mail is confidential and...{{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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Overlay Boxplot with scatter plot

2006-08-01 Thread Joris De Wolf
boxplot does not use the actual values of aa as x-value, but considers 
aa as a factor having three levels.

Try

bxp <- boxplot(bb~aa, data=nn)
bxp

to see what the boxplot actually is.
For your lines you should also use three levels.

aa2<-c(1,1,1,1,2,2,2,2,3,3,3,3,3,3,3)
points(cc~aa2)

(after you have been correcting your example code...)
Joris


Lanre Okusanya wrote:
> I am trying to make a box plot and overlay it with a scatter plot from
> another data.frame. I was able to successfully create the boxplot, but
> when i tried using points(x~y...) the dots did not show up.
> 
> example code
> 
> aa<-(300,300,300,300,600,600,600,600,900,900,900,900)
> bb<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56)
> cc<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56)
> nn<-data.frame(aa,bb)
> mm<-data.frame(aa,cc)
> boxplot(bb~aa, data=nn)
> lines(cc~aa, data=cc)
> 
> Any help with example code is appreciated.
> 
> Thank you.
> 
> Lanre
> 
> __
> 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.


confidentiality notice:
The information contained in this e-mail is confidential and...{{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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] legend outside plotting area

2006-07-12 Thread Joris De Wolf
see
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/68585.html

Georg Otto wrote:
> Hi,
> 
> I would like to place a legend outside a plotting area. Could anybody
> give me a hint how this is done?
> 
> Cheers,
> 
> Georg
> 
> __
> 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


confidentiality notice:
The information contained in this e-mail is confidential and...{{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] Questions to RDCOMClient

2006-04-25 Thread Dr. Michael Wolf
Dear list members,

I'm using R in connection with the RDCOMClient and Excel. The more I use the
package, the more I'm fascinated of it. The possibilities of R can be
brought together with the necessities of outputing my socio-economical
research results in MS Office!

But I have some special questions concering the use of RDCOMClient and
perhaps you can help me solving them:

1. Problems with closing the COM-applications
=

My R procedure structure looks as follows:

# loading the packages
library(RDCOMClient)
source(system.file("examples", "excelUtils.r", package="RDCOMClient"))

# opening the Excel file
dnXls <- paste(pfArb, "/RVP#StO-Analyse_VersVerw.xls", sep="")  #
Xls-Dateiname + Pfad
xls <- COMCreate("Excel.Application")
xls[["Workbooks"]]$Open("c:\tmp\test.xls)

sh <- xls$Sheets("Tab.1")
sh$Select()

::: [ here is comming R code in order to produce output like tables,
thematical map charts and
:::   transfering them to Excel via RDCOMClient / everything is working
fine!!! ... ]

# 'shutting down' Excel

xls[["Visible"]] <- TRUE
xls[["Workbooks"]]$Close()
xls$Quit()
rm(list=c("xls", "sh"))
gc()


The same way is used by serveral examples in the package.  So far so fine!
But sometimes when I try to open the Excel file afterwards from the MS
Explorer, Excel seems to open but didn't show the file I clicked to open.
When opening the task manager I offen can find a Excel process running -
even if I closed Excel with the procedure above and didn't try to reopen
Excel via MS Explorer. What's going wrong in my procedure? Why the Excel
process isn't finished?


2. RDCOMCLient and Windows 98
=

At home I'm sometimes using my old computer with Windows 98 and Excel 2000
(that may seem funny to manny of yours but I use my old "babe" for Internet
surfing and sometimes I have to run some R  procedure!). When trying to use
this operating system in connection with RDCOMCLient I get a warning message
that the DLL tries to change a FPU control word from 8001f to 9001f (this is
the English translation of the German message!). I set the path to %R_HOME%
and also the variable R_HOME to the bin dicertory of R in the autoexec.bat
file. So why doesn't RDCOMCLient run? Does this package work together with
Windows 98 or did I forget some steps when installing the RDCOMClient
package? (Please don't send any answers that I should use a computer with a
new OS. I still do - mostly!)


3. RDCOMCLient and Excel Manual
===

Do you know a good overview of using Excel VBA code via RDCOMClient (e. g.
sh$Select())? Are there people interesting in working out such a paper? I
could contribute some experiences of my work to such a project (e. g.
deleting Excel shapes from R and copying new charts made by R to a special
position in a Excel sheet.


Thanks to you and your hints in advance!

Greetings from Germany

Dr. Michael Wolf
Von-Schonebeck-Ring 1848161 Münster
Tel.:   02533/2466
E-Mail: [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] dataframe (matrix) multiplication

2005-10-14 Thread Peter Wolf
where is the problem?

input:
A<-c(2,3,2); B<-c(1,2,1); C<-c(4,4,5); D<-c(3,5,4)
df<-data.frame(A,B,C,D)
c1<-1:2; c2<-3:4
df[,c1]*df[,c2]

output:
   A  B
1  8  3
2 12 10
3 10  4

Peter Wolf


Christoph Scherber wrote:
>Dear R users,
>
>Suppose I have 2 parts of a dataframe, say
>
>ABCD
>2143
>3245
>2154
>
>(the real dataframe is 160 columns with each 120 rows)
>
>and I want to multiply every element in [,A:B] with every element in [,C:D];
>What is the most elegant way to do this?
>
>I´ve been thinking of converting [,A:B] to a matrix, and then 
>multiplying it with the inverse of [,C:D]; would that be correct?
>
>The result should look like
>
>E;F
>8;3
>12;10
>10;4
>
>Thanks very much for any suggestions
>Christoph
>
>__
>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] questions about boxplots

2005-09-27 Thread Peter Wolf
concerning question 1:  -- labeling of outliers --

you can get the outliers by boxplot(...)$out

try:

set.seed(17)
x<-rexp(99)
names(x)<-paste("x",1:99)
out<-boxplot(x)$out
text(rep(1.1,length(out)), out, names(out))

Peter Wolf

Stephen D. Weigand wrote:
>Dear Yulei,
>
>On Sep 26, 2005, at 6:56 PM, Yulei He wrote:
>
>  
>>Hi, there.
>>
>>I have two questions about using R to create boxplots.
>>
>>1. The function boxplot() plots the outliers. How can I label the exact
>>values arount these outlier points? Does R have an option allow me to
>>do that?
>>
>
>You can use identify(). Here's a toy example
>
>set.seed(1)
>y <- rt(30, 3)
>boxplot(y)
>identify(x = rep(1,30), y = y, label = format(y, digits = 2))
>### now click on the outlier in the plot and you should see "-7.398"
>### beside the outlier
>
>  
>>2. How can I put two boxplots in one x-y axis?
>>
>
>x <- rnorm(10)
>y <- rnorm(20, 3, 5)
>z <- runif(30)
>
>boxplot(x, y, z, labels = c("x", "y", "z"))
>### - or -
>boxplot(list(x = x, y = y, z = z))
>
>
>  
>>Thanks.
>>
>>Yulei
>>
>>
>
>Stephen Weigand
>Rochester, Minnesota, USA
>
>__
>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] hist(x, ...) with normal distribution curve

2005-09-27 Thread Peter Wolf
Knut Krueger wrote:
>.
>I am looking for a histogram or box plot with the adding  normal 
>distribution  curve
>I think that must be possible, but I am not able to find out how to do.
>
>
>
>Regards Knut
>
>__
>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
>  
*There are a lot of answers to add a histogram.
Here is a simple way to add a tiny boxplot to a plot / histogram

x<-rexp(100)
hist(x)
boxplot(x,axes=F,add=T,horizontal=T,
 at=par()$usr[3]+diff(par()$usr[3:4])*.017,
 boxwex=0.02*diff(par()$usr[3:4]),pch=8)

Peter Wolf


*

__
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] bagplot - a rough R function

2005-09-22 Thread Peter Wolf
Martin Maechler wrote:
>>>>>>"Peter" == Peter Wolf <[EMAIL PROTECTED]>
>>>>>>on Wed, 21 Sep 2005 16:49:10 +0200 writes:
>>>>>>
>
>Peter> In the moment I am writing an R function for drawing
>Peter> bagplots (two dimensional boxplots).
>Peter> For some elements of the plot are found numerically
>Peter> the resulting plots differs a little bit from the correct bagplots.
>
>    Peter> Here is the link to the actual version:
>
>Peter> 
> http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/bagplot/bagplot.R 
>Peter> ( R code )
>
>Peter> 
> http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/bagplot/bagplot.pdf 
>Peter> (examples and description)
>
>Peter> Now I am looking for examples to test / to improve my function.
>Peter> Where can I get data sets and the corresponding correct bagplots?
>
>I'll send you my (unpublished) version of my package 'bagplot'
>{{the one I've never released because of segmentation fault bugs
>  somewhere in Fortran}} in a private E-mail.
>
>In my version I had started make a function
>   bag() 
>which *computes* all the information needed and then returns an
>(S3) object "bag".  Then, the plotting happens via
>the 
>plot.bag <- function(.) {..}
>method.
>
>So you can say
>
>   plot(bag(.), )
>
>if you want both (computing and plotting) at once, but can also
>separate the two --- following very much the modern "S" way
>"whole object ..".
>
>
>Martin
>
>  
Hello Martin,

you are right. Separating computing and plotting is a better way for
a public version and I think that I will split my function. But
during testing algorithmic problems it is nice to have only one function.

Peter

__
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: extracting elements in a matrix

2005-09-22 Thread Peter Wolf
... you can, for example

set.seed(13)
x<-matrix(rnorm(100),20,5)
lapply(split(x,col(x)),
   function(x){
 limit<-diff(quantile(x,c(.25,.75)))
 x[x>limit]
   })
output:
$"1"
[1] 1.775163 1.142526 1.229507 1.105144 1.396432
$"2"
[1] 1.836163
$"3"
[1] 1.590034 1.614479 1.408354 1.483691
$"4"
[1] 1.745427
$"5"
[1] 1.602120

Peter Wolf

Frank Schmid wrote:
>Dear R-users
> 
>For a given matrix of dimension, say (n,p), I'd like to extract for every
>column those elements that are bigger than twice the interquartile range of
>the corresponding column. 
> 
>Can I get these elements without using a loop?
> 
> 
>Thank you for your help
> 
> 
>Frank
> 
> 
> 
>
>   
>   
> 
>
>   [[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


[R] bagplot - a rough R function

2005-09-21 Thread Peter Wolf
In the moment I am writing an R function for drawing
bagplots (two dimensional boxplots).
For some elements of the plot are found numerically
the resulting plots differs a little bit from the correct bagplots.

Here is the link to the actual version:

http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/bagplot/bagplot.R 
( R code )

http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/bagplot/bagplot.pdf 
(examples and description)

Now I am looking for examples to test / to improve my function.
Where can I get data sets and the corresponding correct bagplots?

Thanks

Peter Wolf

([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] Add function to histogram?

2005-09-21 Thread Peter Wolf
Robert Lundqvist wrote:
>Is there any neat way to add a curve (frequency function or the like) to a
>histogram or other plots? I haven't found one yet...
>
>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
>  
???

dat<-rnorm(100)
hist(dat,prob=TRUE)
x<-seq(-3.5,3.5,length=100)
y<-dnorm(x)
lines(x,y)

have a look at:  http://cran.at.r-project.org/doc/manuals/R-intro.pdf

Peter Wolf

__
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 mimic pdMat of lme under lmer?

2005-09-19 Thread Joris De Wolf
Dear members,

I would like to switch from nlme to lme4 and try to translate some of my 
models that worked fine with lme.
I have problems with the pdMat classes.

Below a toy dataset with a fixed effect F and a random effect R. I gave 
also 2 similar lme models.
The one containing pdLogChol (lme1) is easy to translate (as it is an 
explicit notation of the default model)
The more parsimonious model with pdDiag replacing pdLogChol I cannot 
reproduce with lmer. The obvious choice for me would be my model lmer2, 
but this is yielding different result.

Somebody any idea?
Thanks,
Joris

I am using R version 2.1.0 for Linux
and the most recent downloads of Matrix and  nlme

#dataset from McLean, Sanders and Stroup
F <- factor(c(1,1,1,1,1,1,2,2,2,2,2,2))
R <- factor(c(1,1,2,2,3,3,1,1,2,2,3,3))
s <- 
c(51.43,51.28,50.93,50.75,50.47,50.83,51.91,52.43,52.26,52.33,51.58,51.23)
DS <- data.frame(F,R,s)
DS$F <- as.factor(DS$F)
DS$R <- as.factor(DS$R)

library(nlme)
lme1 <- lme(data = DS,s ~ F,random = list(R = pdLogChol(~F)))
lme2 <- lme(data = DS,s ~ F,random = list(R = pdDiag(~F)))
summary(lme1)
summary(lme2)

library(lme4)
lmer1 <- lmer(data = DS,s ~ F + (F|R))
lmer2 <- lmer(data = DS,s ~ F + (1|R) + (1|F))
summary(lmer1)
summary(lmer2)



confidentiality notice:
The information contained in this e-mail is confidential and...{{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] Converting characters to numbers in data frames

2005-08-25 Thread Peter Wolf
Try:

NAMES=c("NRes.1.2.", "NRes.1.3.", "NRes.1.4.", "NRes.1.5.", "NRes.1.6.")
pattern<-"NRes\.([0-9]*)\.([0-9]*)\."
data.frame(x=sub(pattern,"\\1",NAMES),y=sub(pattern,"\\2",NAMES))

@
output-start
Thu Aug 25 14:08:50 2005
  x y
1 1 2
2 1 3
3 1 4
4 1 5
5 1 6
output-end

Peter Wolf

Anon. wrote:
>I'm sure I'm missing something obvious here, but I can't find the 
>solution (including in the FAQ etc.).
>
>I have a vector of names of variables like this: NRes.x.y. where x and y 
>are numbers.  I want to extract these numbers as numbers to use 
>elsewhere.  I can extract the numbers as a list of characters using 
>strsplit(), and convert that to a data frame, e.g.:
>
>NAMES=c("NRes.1.2.", "NRes.1.3.", "NRes.1.4.", "NRes.1.5.", "NRes.1.6.")
>NUMBERS=strsplit(gsub("NRes.","", NAMES, perl =T), '.', fixed = TRUE)
>NUMBERS.df=t(data.frame(NUMBERS))
>
>But I now want to convert the characters to be numeric.  Using 
>as.numeric(NUMBERS.df) converts them, but to a vector.  How can I 
>convert and keep as a data frame?  I could use this:
>
>matrix(as.numeric(NUMBERS.df), ncol=dim(NUMBERS.df)[2])
>
>but I seem to be jumping through far too many hoops: there must be an 
>easier way.  An suggestions?
>
>Bob
>
>

__
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] 'splice' two data frames

2005-08-25 Thread Peter Wolf
what about:

@
<<*>>=
z<-data.frame(matrix(rbind(x,y),nrow(x),2*ncol(x)))
rownames(z)<-rownames(x)
z
@
output-start
Thu Aug 25 11:24:29 2005
  X1   X2 X3   X4 X5   X6 X7   X8
a  2 0.02  1 0.01  2 0.02  2 0.02
b  3 0.03  0 0.00  4 0.04  3 0.03
c  3 0.03  2 0.02  1 0.01  6 0.06
d  3 0.03  4 0.04  2 0.02  3 0.03
e  4 0.04  1 0.01  4 0.04  2 0.02
f  2 0.02  5 0.05  2 0.02  2 0.02
g  4 0.04  5 0.05  3 0.03  3 0.03
h  3 0.03  3 0.03  5 0.05  4 0.04
i  1 0.01  0 0.00  3 0.03  3 0.03
output-end

Peter Wolf


David Whiting wrote:
>Hi,
>
>I often need to take columns from two data.frames and 'splice' them
>together (alternately taking a column from the first data frame, then
>from the second). For example:
>
>x <- table(sample(letters[1:9], 100, replace=TRUE),
>   sample(letters[1:4], 100, replace=TRUE))
>y <- prop.table(x)
>
>splice <- function (x, y) {
>  z <- matrix(rep(NA, (ncol(x) * 2) * nrow(x)), nrow = nrow(x))
>  j <- 1
>  for (i in seq(1, ncol(z), by = 2)) {
>z[, i] <- x[, j]
>z[, (i + 1)] <- y[, j]
>j <- j + 1
>  }
>  z <- data.frame(z)
>  rownames(z) <- rownames(x)
>  z
>}
>
>splice(x, y)
>
>
>Manually using indexing I can do this:
>
>zz <- data.frame(x[, 1], y[, 1], x[, 2], y[, 2], x[, 3], y[, 3], x[, 4],
>y[, 4])
>
>
>I *feel* that it should be possible in R to generate the sequence of
>column indexes automatically. I can get close with this:
>
>i <- paste("x[,", 1:ncol(x), "], ",
>  "y[,", 1:ncol(y), "]",
>  collapse=", ")
>
>which creates a string version of what I want, but I am not sure how to
>use that with data.frame. FAQ 7.21 ("How can I turn a string into a
>variable?") looked promising but I have not been able to apply any of
>the suggestions to this problem. I also tried using do.call:
>
>i <- paste("x[,", 1:4, "],", "y[,", 1:4, "]", collapse=",")
>i <- gsub("],", "]@", i)  # Create a marker for
>i <- strsplit(i, "@") # strsplit to create a list
>do.call(data.frame, i)
>
>and with lapply:
>
>lappy(i, data.frame)
>
>These "did not work" (i.e. they worked as they were designed to and did
>not give me the results I am after).
>
>I think I need a nudge or two in the right direction.
>
>Thanks.
>
>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


Re: [R] Plotting a simple subset

2005-07-08 Thread Peter Wolf
Michael Hopkins wrote:

>Hi all
>
>Just converting from Stata to R and struggling a little to come to terms
>with the new philosophy/command line.
>
>E.g. I want to plot x against y if x < 5
>
>In Stata: graph x y, if( x < 5 )
>
>How do I do this in R?  Have tried most of the obvious options without
>success.
>
>Can I have multiple subsets? I.e. In Stata: if( x < 5 && y > 3 )
>

Try:

x<-rnorm(20,0,5)
y<-2*x+rnorm(20)
# plot without condition
plot(x,y)
# some conditions on x and y
index<- x<5 & y>3
plot(x[index],y[index])

Peter Wolf

>
>TIA 
>
>Michael
>
>
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>
>_/_/   _/_/_/ Hopkins Research Ltd
>   _/_/   _/_/
>  _/_/_/_/   _/_/_/  http://www.hopkins-research.com/
> _/_/   _/   _/
>_/_/   _/ _/   'touch the future'
>   
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>
>__
>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] [R-pkgs] New CRAN package "relax": R Editor for Literate Analysis and lateX

2005-07-01 Thread Peter Wolf
Now package relax is on CRAN.

The name relax is short for
 
R Editor for Literate Analysis and lateX

The main element of package relax is the function relax() which starts an
all-in-one editor for data analysis and easy creation of LaTeX based 
documents
with R.

After calling relax() it creates a tcl/tk widget with a report field. 
 The report field
enables you to enter R expressions as well as pieces of text to document 
your ideas.
Computations and plots can be included quickly. After finishing your work
the sequence of text chunks, code chunks and integrated graphics and/or 
R-output
will constitute the basis of your work. To achieve a higher quality 
relax integrates
LaTeX compilation for professional formatting and pretty printing.

Dependencies:

* R (>= 2.1.0), tcltk
* relax runs on windows systems, LaTeX / ghostscript has to be installed
* on Linux systems you have to install the img-package for tcltk

For further info see: 
http://www.wiwi.uni-bielefeld.de/~wolf/software/relax/relax.html

maintainer:

Hans Peter Wolf
Department of Economics
University of Bielefeld
[EMAIL PROTECTED]



R Editor for Literate Analysis and lateX

--- the all-in-one editor for data analysis
and easy creation of LaTeX based documents with R

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

2005-06-28 Thread Peter Wolf
Federico Calboli wrote:

>Hi All,
>
>I am currently preparing some form of slideshow introducing R and its
>capabilities for some colleagues. The thing will be about 30 mins, and
>I'd like to have some "pretty pictures" and some "amazing facts" (I'm
>trying to sell, obviously :)).
>
>Can I ask if it's possible to easily retrieve a gross figure of the
>number of functions in R considering the "base" install and all the
>libraries available?
>
>Apart from graphics and lattice, are there any more packages producing
>eye catching graphics (possibly with a survival analysis/epidemiological
>bend)?
>
>Cheers,
>
>Federico Calboli
>
>  
>
In the package relax you find the function slider().
The help page of slider shows a nice application: R.veil.in.the.wind()
Here are the definitions of slider and R.veil.in.the.wind:

# definition of slider
slider<-function (sl.functions, sl.names, sl.mins, sl.maxs, sl.deltas,
sl.defaults, but.functions, but.names, no, set.no.value,
obj.name, obj.value, reset.function, title)
{
if (!missing(no))
return(as.numeric(tclvalue(get(paste("slider", no, sep = ""),
env = slider.env
if (!missing(set.no.value)) {
try(eval(parse(text = paste("tclvalue(slider", set.no.value[1],
")<-", set.no.value[2], sep = "")), env = slider.env))
return(set.no.value[2])
}
if (!exists("slider.env"))
slider.env <<- new.env()
if (!missing(obj.name)) {
if (!missing(obj.value))
assign(obj.name, obj.value, env = slider.env)
else obj.value <- get(obj.name, env = slider.env)
return(obj.value)
}
if (missing(title))
title <- "slider control widget"
require(tcltk)
nt <- tktoplevel()
tkwm.title(nt, title)
tkwm.geometry(nt, "+0+0")
if (missing(sl.names))
sl.names <- NULL
if (missing(sl.functions))
sl.functions <- function(...) {
}
for (i in seq(sl.names)) {
eval(parse(text = paste("assign('slider", i, 
"',tclVar(sl.defaults[i]),env=slider.env)",
sep = "")))
tkpack(fr <- tkframe(nt))
lab <- tklabel(fr, text = sl.names[i], width = "25")
sc <- tkscale(fr, from = sl.mins[i], to = sl.maxs[i],
showvalue = T, resolution = sl.deltas[i], orient = "horiz")
tkpack(lab, sc, side = "right")
assign("sc", sc, env = slider.env)
eval(parse(text = paste("tkconfigure(sc,variable=slider",
i, ")", sep = "")), env = slider.env)
sl.fun <- if (length(sl.functions) > 1)
sl.functions[[i]]
else sl.functions
if (!is.function(sl.fun))
sl.fun <- eval(parse(text = paste("function(...){",
sl.fun, "}")))
tkconfigure(sc, command = sl.fun)
}
assign("slider.values.old", sl.defaults, env = slider.env)
tkpack(f.but <- tkframe(nt), fill = "x")
tkpack(tkbutton(f.but, text = "Exit", command = function() 
tkdestroy(nt)),
side = "right")
if (missing(reset.function))
reset.function <- function(...) print("relax")
if (!is.function(reset.function))
reset.function <- eval(parse(text = paste("function(...){",
reset.function, "}")))
tkpack(tkbutton(f.but, text = "Reset", command = function() {
for (i in seq(sl.names)) eval(parse(text = paste("tclvalue(slider",
i, ")<-", sl.defaults[i], sep = "")), env = slider.env)
reset.function()
}), side = "right")
if (missing(but.names))
but.names <- NULL
for (i in seq(but.names)) {
but.fun <- if (length(but.functions) > 1)
but.functions[[i]]
else but.functions
if (!is.function(but.fun))
but.fun <- eval(parse(text = paste("function(...){",
but.fun, "}")))
tkpack(tkbutton(f.but, text = but.names[i], command = but.fun),
side = "left")
}
invisible(nt)
}
# definition of R.veil.in.the.wind
 R.veil.in.the.wind<-function(){
   # Mark Hempelmann / Peter Wolf
   par(bg="blue4", col="white", col.main="white",
   col.sub="white", font.sub=2, fg="white") # set colors and fonts
   samp  <- function(N,D) N*(1/4+D)/(1/4+D*N)
   z<-outer(seq(1, 800, by=10), seq(.0025, 0.2, .0025)^2/1.96^2, 
samp) # create 3d matrix
   h<-100
   z[10:70,20:25]<-z[10:70,20:25]+h; z[65:70,26:4

Re: [R] r programming help

2005-06-22 Thread Peter Wolf
Try:

 > DRY<-c(2,5,3,7,11)
 > WET<-(1:5)*10
 > print(filter(c(rep(0,length(WET)),DRY),WET))

Time Series:
Start = 1
End = 10
Frequency = 1
[1]  NA  NA   0  20  90 190 360 640  NA  NA

 > CYCLE.n<-c(NA,
 > WET[1]*DRY[1],
 > WET[1]*DRY[2]+WET[2]*DRY[1],
 > WET[1]*DRY[3]+WET[2]*DRY[2]+WET[3]*DRY[1],
 > WET[1]*DRY[4]+WET[2]*DRY[3]+WET[3]*DRY[2]+WET[4]*DRY[1],
 > WET[1]*DRY[5]+WET[2]*DRY[4]+WET[3]*DRY[3]+WET[4]*DRY[2]+WET[5]*DRY[1])
 > print(CYCLE.n)
[1]  NA  20  90 190 360 640

Peter Wolf

Mohammad Ehsanul Karim wrote:

>Dear list,
>
>Is there anyway i can make the following formula short
>by r-programming?
>
>CYCLE.n<-c(NA,
>WET[1]*DRY[1],
>WET[1]*DRY[2]+WET[2]*DRY[1],
>WET[1]*DRY[3]+WET[2]*DRY[2]+WET[3]*DRY[1],
>WET[1]*DRY[4]+WET[2]*DRY[3]+WET[3]*DRY[2]+WET[4]*DRY[1],
>WET[1]*DRY[5]+WET[2]*DRY[4]+WET[3]*DRY[3]+WET[4]*DRY[2]+WET[5]*DRY[1],
>WET[1]*DRY[6]+WET[2]*DRY[5]+WET[3]*DRY[4]+WET[4]*DRY[3]+WET[5]*DRY[2]+WET[6]*DRY[1],
>WET[1]*DRY[7]+WET[2]*DRY[6]+WET[3]*DRY[5]+WET[4]*DRY[4]+WET[5]*DRY[3]+WET[6]*DRY[2]+WET[7]*DRY[1],
>WET[1]*DRY[8]+WET[2]*DRY[7]+WET[3]*DRY[6]+WET[4]*DRY[5]+WET[5]*DRY[4]+WET[6]*DRY[3]+WET[7]*DRY[2]+WET[8]*DRY[1],
>WET[1]*DRY[9]+WET[2]*DRY[8]+WET[3]*DRY[7]+WET[4]*DRY[6]+WET[5]*DRY[5]+WET[6]*DRY[4]+WET[7]*DRY[3]+WET[8]*DRY[2]+WET[9]*DRY[1],
>WET[1]*DRY[10]+WET[2]*DRY[9]+WET[3]*DRY[8]+WET[4]*DRY[7]+WET[5]*DRY[6]+WET[6]*DRY[5]+WET[7]*DRY[4]+WET[8]*DRY[3]+WET[9]*DRY[2]+WET[10]*DRY[1],
>WET[1]*DRY[11]+WET[2]*DRY[10]+WET[3]*DRY[9]+WET[4]*DRY[8]+WET[5]*DRY[7]+WET[6]*DRY[6]+WET[7]*DRY[5]+WET[8]*DRY[4]+WET[9]*DRY[3]+WET[10]*DRY[2]+WET[11]*DRY[1],
>WET[1]*DRY[12]+WET[2]*DRY[11]+WET[3]*DRY[10]+WET[4]*DRY[9]+WET[5]*DRY[8]+WET[6]*DRY[7]+WET[7]*DRY[6]+WET[8]*DRY[5]+WET[9]*DRY[4]+WET[10]*DRY[3]+WET[11]*DRY[2]+WET[12]*DRY[1],
>WET[1]*DRY[13]+WET[2]*DRY[12]+WET[3]*DRY[11]+WET[4]*DRY[10]+WET[5]*DRY[9]+WET[6]*DRY[8]+WET[7]*DRY[7]+WET[8]*DRY[6]+WET[9]*DRY[5]+WET[10]*DRY[4]+WET[11]*DRY[3]+WET[12]*DRY[2]+WET[13]*DRY[1],
>WET[1]*DRY[14]+WET[2]*DRY[13]+WET[3]*DRY[12]+WET[4]*DRY[11]+WET[5]*DRY[10]+WET[6]*DRY[9]+WET[7]*DRY[8]+WET[8]*DRY[7]+WET[9]*DRY[6]+WET[10]*DRY[5]+WET[11]*DRY[4]+WET[12]*DRY[3]+WET[13]*DRY[2]+WET[14]*DRY[1],
>WET[1]*DRY[15]+WET[2]*DRY[14]+WET[3]*DRY[13]+WET[4]*DRY[12]+WET[5]*DRY[11]+WET[6]*DRY[10]+WET[7]*DRY[9]+WET[8]*DRY[8]+WET[9]*DRY[7]+WET[10]*DRY[6]+WET[11]*DRY[5]+WET[12]*DRY[4]+WET[13]*DRY[3]+WET[14]*DRY[2]+WET[15]*DRY[1],
>WET[1]*DRY[16]+WET[2]*DRY[15]+WET[3]*DRY[14]+WET[4]*DRY[13]+WET[5]*DRY[12]+WET[6]*DRY[11]+WET[7]*DRY[10]+WET[8]*DRY[9]+WET[9]*DRY[8]+WET[10]*DRY[7]+WET[11]*DRY[6]+WET[12]*DRY[5]+WET[13]*DRY[4]+WET[14]*DRY[3]+WET[15]*DRY[2]+WET[16]*DRY[1],
>WET[1]*DRY[17]+WET[2]*DRY[16]+WET[3]*DRY[15]+WET[4]*DRY[14]+WET[5]*DRY[13]+WET[6]*DRY[12]+WET[7]*DRY[11]+WET[8]*DRY[10]+WET[9]*DRY[9]+WET[10]*DRY[8]+WET[11]*DRY[7]+WET[12]*DRY[6]+WET[13]*DRY[5]+WET[14]*DRY[4]+WET[15]*DRY[3]+WET[16]*DRY[2]+WET[17]*DRY[1],
>WET[1]*DRY[18]+WET[2]*DRY[17]+WET[3]*DRY[16]+WET[4]*DRY[15]+WET[5]*DRY[14]+WET[6]*DRY[13]+WET[7]*DRY[12]+WET[8]*DRY[11]+WET[9]*DRY[10]+WET[10]*DRY[9]+WET[11]*DRY[8]+WET[12]*DRY[7]+WET[13]*DRY[6]+WET[14]*DRY[5]+WET[15]*DRY[4]+WET[16]*DRY[3]+WET[17]*DRY[2]+WET[18]*DRY[1],
>WET[1]*DRY[19]+WET[2]*DRY[18]+WET[3]*DRY[17]+WET[4]*DRY[16]+WET[5]*DRY[15]+WET[6]*DRY[15]+WET[7]*DRY[13]+WET[8]*DRY[12]+WET[9]*DRY[11]+WET[10]*DRY[10]+WET[11]*DRY[9]+WET[12]*DRY[8]+WET[13]*DRY[7]+WET[14]*DRY[6]+WET[15]*DRY[5]+WET[16]*DRY[4]+WET[17]*DRY[3]+WET[18]*DRY[2]+WET[19]*DRY[1],
>WET[1]*DRY[20]+WET[2]*DRY[19]+WET[3]*DRY[18]+WET[4]*DRY[17]+WET[5]*DRY[16]+WET[6]*DRY[15]+WET[7]*DRY[14]+WET[8]*DRY[13]+WET[9]*DRY[12]+WET[10]*DRY[11]+WET[11]*DRY[10]+WET[12]*DRY[9]+WET[13]*DRY[8]+WET[14]*DRY[7]+WET[15]*DRY[6]+WET[16]*DRY[5]+WET[17]*DRY[4]+WET[18]*DRY[3]+WET[19]*DRY[2]+WET[20]*DRY[1],
>WET[1]*DRY[21]+WET[2]*DRY[20]+WET[3]*DRY[19]+WET[4]*DRY[18]+WET[5]*DRY[17]+WET[6]*DRY[16]+WET[7]*DRY[15]+WET[8]*DRY[14]+WET[9]*DRY[13]+WET[10]*DRY[12]+WET[11]*DRY[11]+WET[12]*DRY[10]+WET[13]*DRY[9]+WET[14]*DRY[8]+WET[15]*DRY[7]+WET[16]*DRY[6]+WET[17]*DRY[5]+WET[18]*DRY[4]+WET[19]*DRY[3]+WET[20]*DRY[2]+WET[21]*DRY[1],
>WET[1]*DRY[22]+WET[2]*DRY[21]+WET[3]*DRY[20]+WET[4]*DRY[19]+WET[5]*DRY[18]+WET[6]*DRY[17]+WET[7]*DRY[16]+WET[8]*DRY[15]+WET[9]*DRY[14]+WET[10]*DRY[13]+WET[11]*DRY[12]+WET[12]*DRY[11]+WET[13]*DRY[10]+WET[14]*DRY[9]+WET[15]*DRY[8]+WET[16]*DRY[7]+WET[17]*DRY[6]+WET[18]*DRY[5]+WET[19]*DRY[4]+WET[20]*DRY[3]+WET[21]*DRY[2]+WET[22]*DRY[1],
>WET[1]*DRY[23]+WET[2]*DRY[22]+WET[3]*DRY[21]+WET[4]*DRY[20]+WET[5]*DRY[19]+WET[6]*DRY[18]+WET[7]*DRY[17]+WET[8]*DRY[16]+WET[9]*DRY[15]+WET[10]*DRY[14]+WET[11]*DRY[13]+WET[12]*DRY[12]+WET[13]*DRY[11]+WET[14]*DRY[10]+WET[15]*DRY[9]+WET[16]*DRY[8]+WET[17]*DRY[7]+WET[18]*DRY[6]+WET[19]*DRY[5]+WET[20]*DRY[4]+WET[21]*DRY[3]+WET[22]*DRY[2]+WET[23]*DRY[1],
>WET[1]*DRY[24]+WET[2]*DRY[23]+WET[3]*DRY[22]+WET[4]*DRY[21]+WET[5]*DRY[20]+WET[6]*DRY[19]+WET[7]*DRY[18]+WET[8]*

Re: [R] Testing for warning inside functions

2005-05-18 Thread Peter Wolf
Prof Brian Ripley wrote:
On Wed, 18 May 2005, Peter Wolf wrote:
I am looking for a way to get a warning message
immediately after an evaluation within a function.
To get error messages you can use geterrmessage().

Well, only in an error handler, as an error normally throws you out of 
the function.  (That is the point of geterrmessage(), to enable error 
handlers to be written.)

To print the message immediately, look up options("warn").
options(warn=1) prints the message immediately,
but I cannot store it in a variable to analyse it or to show the message 
it in a message box, for example.

  We don't have a general warnings handler mechanism, but you can make 
use of condition objects. 
Thank you, I will have a look at condition objects.
But I found no function that allows me to check for
warnings.
Five years ago this questions has been posted
but I haven't found any answer.

What exactly is `this question'?  I see several assertions but no 
question.  (It would have been helpful to give an exact reference to 
the archives.)
link to the old mail: R-help archive Jan - June 2000:
* [R] Testing for warning inside functions -- V/idhyanath Rao (Sun 07 
May 2000 - 12:46:38 EST)/
Message-ID: <[EMAIL PROTECTED]>
"This is probably a newbie question: How do I test, inside a function, is
a call I made from inside that function produced a warning? ..."


Thanks for any help.
Peter Wolf

For illustration purpose a simple example follows:
you can get warnings after an error occured or after
exiting from the function but not at once after
"x<-matrix(1:3,2,2)":
options(warn=0)
f<-function(x){
 x<-matrix(1:3,2,2)
 print(0)
 warnings()  # no warning is shown
 print(1)
 try({xxx})
 print(2)
 print(geterrmessage())
 print(3)
 warnings()
 print(4)
}
f()
[1] 0
[1] 1
Fehler in try({ : Objekt "xxx" nicht gefunden
Zusätzlich: Warnmeldung:
Datenlänge [3] ist kein Teiler oder Vielfaches der Anzahl der Zeilen 
[2] in matrix
[1] 2
[1] "Fehler in try({ : Objekt \"xxx\" nicht gefunden\n"
[1] 3
Warning message:
Datenlänge [3] ist kein Teiler oder Vielfaches der Anzahl der Zeilen 
[2] in matrix
[1] 4

__
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] Testing for warning inside functions

2005-05-18 Thread Peter Wolf
I am looking for a way to get a warning message
immediately after an evaluation within a function.
To get error messages you can use geterrmessage().
But I found no function that allows me to check for
warnings.
Five years ago this questions has been posted
but I haven't found any answer.
Thanks for any help.
Peter Wolf

For illustration purpose a simple example follows:
you can get warnings after an error occured or after
exiting from the function but not at once after
"x<-matrix(1:3,2,2)":
> options(warn=0)
> f<-function(x){
  x<-matrix(1:3,2,2)
  print(0)
  warnings()  # no warning is shown
  print(1)
  try({xxx})
  print(2)
  print(geterrmessage())
  print(3)
  warnings()
  print(4)
}
> f()
[1] 0
[1] 1
Fehler in try({ : Objekt "xxx" nicht gefunden
Zusätzlich: Warnmeldung:
Datenlänge [3] ist kein Teiler oder Vielfaches der Anzahl der Zeilen [2] 
in matrix
[1] 2
[1] "Fehler in try({ : Objekt \"xxx\" nicht gefunden\n"
[1] 3
Warning message:
Datenlänge [3] ist kein Teiler oder Vielfaches der Anzahl der Zeilen [2] 
in matrix
[1] 4
> 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

__
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] Error in La.chol2inv(x, size) : lapack routines cannot be loaded

2005-04-29 Thread Joris De Wolf
Dear all,
OS: x86_64-suse-linux 9.2
CPU: Intel(R) Xeon(TM) CPU 3.20GHz
R-version: R-2.1.0
I've started using a new Linux server, upgraded at the same time to 
R-2.1.0 (see above) and have problems with some elementary analysis that 
ran without a problem on my previous configuration.

anova.glm gives the following error:
Error in La.chol2inv(x, size) : lapack routines cannot be loaded
This was with the after the following configure
./configure --with-readline --prefix=/opt/R-2.1.0 --with-libpng 
--with-jpeglib --with-pcre --without-x

The obvious thing to try next was:
./configure --with-readline --prefix=/opt/R-2.1.0 --with-libpng 
--with-jpeglib --with-pcre --without-x --with-lapack

but this gave errors at the make:
make[3]: Entering directory `/usr/local/src/R-2.1.0/src/modules/lapack'
make[4]: Entering directory `/usr/local/src/R-2.1.0/src/modules/lapack'
make[4]: `Makedeps' is up to date.
make[4]: Leaving directory `/usr/local/src/R-2.1.0/src/modules/lapack'
make[4]: Entering directory `/usr/local/src/R-2.1.0/src/modules/lapack'
gcc -shared -L/usr/local/lib -o lapack.so  Lapack.lo   -llapack -lblas 
-lg2c -lm -lgcc_s
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.4/../../../../x86_64-suse-linux/bin/ld: 
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.4/../../../../lib64/liblapack.a(dgecon.i): 
relocation R_X86_64_32 against `a local symbol' can not be used when 
making a shared object; recompile with -fPIC
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.4/../../../../lib64/liblapack.a: 
could not read symbols: Bad value
collect2: ld returned 1 exit status
make[4]: *** [lapack.so] Error 1

I've found some similar postings  about Debian, but without a soluition.
Any idea how I could proceed?
Joris




confidentiality notice:
The information contained in this e-mail is confidential and...{{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] hex format

2005-04-07 Thread Peter Wolf
Steve Vejcik wrote:
Thanks for your advice.  Unfortunately, your answers are inconsistent:
as.numeric("0x1AF0") returns a decimal value for a hex string. I'd like
to do the opposite-use hex notation to represent a decimal.
e.g.
   x<-0x000A
   y<-0x0001
   x+y=0x00B

Cheers.

you can use chcode() to define hex.to.dec(), dec.to.hex() and sum.hex()
to operate with hex numbers.
Peter Wolf
--
<>=
chcode <- function(b, base.in=2, base.out=10, digits="0123456789ABCDEF"){
  # change of number systems, pwolf 10/02
  # e.g.: from 2 2 2 2 ...  ->  16 16 16 ...
  digits<-substring(digits,1:nchar(digits),1:nchar(digits))
  if(length(base.in)==1) base.in <- rep(base.in, max(nchar(b)-1))
  if(is.numeric(b)) b <- as.character(as.integer(b))
  b.num <- lapply(strsplit(b,""), function(x) match(x,digits)-1  )
  result <- lapply(b.num, function(x){
   cumprod(rev(c(base.in,1))[ 1:length(x) ] ) %*% rev(x)
} )
  number<-unlist(result)
  cat("decimal representation:",number,"\n")
  if(length(base.out)==1){
 base.out<-rep(base.out,1+ceiling(log( max(number), base=base.out ) ) )
  }
  n.base <- length(base.out); result <- NULL
  for(i in n.base:1){
result <- rbind(number %% base.out[i], result)
number <- floor(number/base.out[i])
  }
  result[]<-digits[result+1]
  apply(result, 2, paste, collapse="")
}
@
<>=
hex.to.dec<-function(x) as.numeric(chcode(x, base.in=16, base.out=10))
dec.to.hex<-function(x) chcode(x, base.in=10, base.out=16)
sum.hex<-function(x,y) dec.to.hex(hex.to.dec(x) + hex.to.dec(y))
@
quick test:
<>=
a<-dec.to.hex(10); print(a)
b<-dec.to.hex(3);print(b)
@
output-start
decimal representation: 10
[1] "0A"
decimal representation: 3
[1] "03"
output-end
@
<>=
sum.hex(a,b)
@
output-start
decimal representation: 10
decimal representation: 3
decimal representation: 13
Thu Apr  7 17:31:42 2005
[1] "0D"
output-end
 

__
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] problem (bug?) with prelim.norm (package norm)

2005-02-24 Thread Andreas Wolf
dear list members,
there seems to be a problem with the prelim.norm function (package norm)
as number of items in the dataset increases.

the output of prelim.norm() is a list with different summary statistics,
one of them is the missingness indicator matrix "r". it lists all
patterns of missing data and a count of how often each pattern occured
in the dataset. as the number of items and number of patterns increases,
it seems to malfunction, as it stops after less than 200 patterns and
the count for the last row/pattern equals the number of subjects minus
the number of patterns listed before.

let's give an example: i generate multivariate normal data for 40
variables and 500 observations. i randomly delete 10 percent of the
values for each person (i.e. set them to NA). as the number of possible
patterns of missings (combinations without repetition: 4 over 40) is
91390, you'd expect to have (almost) as many different patterns of
missings as subjects in the dataset (~ 500). however, running
prelim.norm, the "r" matrix indicates some 170 patterns (it varies in
multiple runs !!), the last pattern to be some 320 times in the dataset
(which is, of course, not true if you check).

any ideas? 


INPUT:
x <- matrix(rnorm(2),500,40)   # generate 50 variables with 500
observations

for (tmp in 1:500) {
  draw <- sample(1:40, 4, replace=F)
  x[tmp, draw] <- NA
}   # set (random) 10 percent of values per observation to NA

library(norm)
s <- prelim.norm(x)   # run prelim.norm from package norm
s$r   # missingness indicator matrix (0-missing, 1-observed)
dimnames(s$r)[[1]][length(s$r[,1])]   # count for (supposedly) last
pattern

tmp <- which(s$r[length(s$r[,1]),] == 0)   # vector of items
(supposedly) missing in last pattern
which(is.na(x[,tmp[1]]) & is.na(x[,tmp[2]]) & is.na(x[,tmp[3]]) &
is.na(x[,tmp[4]]))   # list cases with last pattern




p.s. it works fine up to 30 items ... hence, it's not due to the
absolute number of patterns, as there're almost as many patterns as
subjects with 3 out of 30 items missing (possible patterns: 3 over 30 =
4060)

p.p.s. i first thought of the recursion limit in R, but it doesn't help
( options(expressions = 10) )

__
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] Barplot - Can't figure it out

2005-02-18 Thread Peter Wolf
Try:
x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4,1:5)
y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2,1:5)
barplot(rbind(table(x)-1, table(y)-1), beside=T)
P. Wolf
T Petersen wrote:
Wow, I'm getting confused...The syntax Petr suggested does what I 
wanted, but things are stille wrong...Maybe a bug? Let me explain.

I got two vectors:
x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4)
y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2)
then I do the barplot you suggest
barplot(rbind(table(x), table(y)), beside=T)
but things are wrong(there is no bar for catagory "3") and I get an 
error message:
Warning message: number of columns of result
   not a multiple of vector length (arg 1) in: 
rbind(table(Quest1), table(Quest2))

Any ideas?
Petr Pikal wrote:
Hi
If I understand correctly
barplot(rbind(table(x), table(y)), beside=T)
does what you want.
Cheers
Petr

On 18 Feb 2005 at 7:51, T Petersen wrote:
 

Almost. Catagories aren't stacked - I would like to see that x has 2
instances of "1" while y has 1 instance of "1". What's more, there are
now TWO distinct barplots - the left one shows x, while the right one
shows y. I could live with that, but what I'd ideally want is to have
x and y beside each other for EACH catagory - so for catagory "1" you
could see taht there are more x's than y's (two x's versus one y). But
thanks for the help
Mulholland, Tom wrote:
  

barplot(matrix(c(x,y),ncol = 2),beside=T)
Does this help
?barplot notes
height: either a vector or matrix of values describing the bars which
make up the plot.  If 'height' is a vector, the plot
consists of a sequence of rectangular bars with heights
given by the values in the vector.  If 'height' is a matrix
and 'beside' is 'FALSE' then each bar of the plot
corresponds to a column of 'height', with the values in the
column giving the heights of stacked "sub-bars" making up
the bar.  If 'height' is a matrix and 'beside' is 'TRUE',
then the values in each column are juxtaposed rather than
stacked.



-Original Message-
From: T Petersen [mailto:[EMAIL PROTECTED]
Sent: Friday, 18 February 2005 1:35 PM
To: Kevin Wang
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Barplot - Can't figure it out
Ups, it should of course be barplot() in my mail, not boxplot:-)
Kevin Wang wrote:
 
  

Hi,
T Petersen wrote:
   


Hi,
I have two catagorical vectors like this;
x = c(1, 2, 4, 2, 1)
y = c(2, 4, 2 ,4, 1)
I want to set up a barplot with the catagories 1-4  
  

horizontally  and  
  

number of occurances vertically for each vector x,y. I've tried
boxplot(table(x,y), beside=T)
and
boxplot(c(x,y), beside=T)
 
  
Have you tried barplot(), instead of boxplot()???
Cheers,
Kev
   

__
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
  

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

 

__
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] splitting items into groups according to correlations

2005-02-16 Thread Andreas Wolf
hi,
i'm looking for a smart way of distributing items to different groups
according to their correlation(s). the correlation of items within one
group should be minimal, whereas (canonical) correlation between the
blocks should be maximal.
example: you have 20 items, which are to be split into 4 blocks with 5
items in each block. (of course, the numbers are to be interchangable).

so far, 2 (problematic) solutions were thought of: 
1) try all different combinations of blocks of items and look for the
maximum canonical correlation between the blocks. problems are, that the
correlation of items within one block are only regarded implicitely and,
more sadly, this approach is very time-consuming as the number of items
increases.
2) an approximation could be to use the results of a factor analysis to
distribute items from one factor to different blocks. however, this is a
rather quick and dirty solution.

has anybody else encountered a similar problem before or can think of an
approach to handle this?
any help is more than welcome.

best regards
andreas


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


AW: [R] Problem with German special characters

2004-12-15 Thread Wolf, Michael
Dear Prof. Ripley,

thanks for your help. Everything is working fine!

With best regards

Michael Wolf 

-Ursprüngliche Nachricht-
Von: Brian D Ripley [mailto:[EMAIL PROTECTED] 
Gesendet: Mittwoch, 15. Dezember 2004 09:01
An: Wolf, Michael
Betreff: Re: [R] Problem with German special characters

Please do look in the list archives: this is a Windows bug worked around a 
while back. You need to get the R-patched version of R.


On Wed, 15 Dec 2004, Wolf, Michael wrote:

> Dear list!
>
> When using the German special characters I didn't see all characters 
> in the correct way. Let's take the command
>
> ff <- "äöüßÄÖÜ"   # (for those ones who can't see this in the correct way 
> \"a, \"ö, \"ü
>   # \ss (?), \"A, \"O and \"U in LaTeX commands
>
> 'ff' will show the output text "\344\366üß\304\326\334" on Rconsole. So only 
> "ü" ("\u) and "ß" (\ss) are shown in the correct way. The other characters 
> are coded in the "\" form.
>
> I found out that this problem doesn't occur when exporting 'ff' to a text 
> file with 'writeLines'. When opening this file with a text editor you can see 
> all characters in the correct way.
>
> What can I do to get the correct output of the special characters?
>
> Thanks for your help in advance!
>
> Mit freundlichen Grüßen
>
> Dr. Michael Wolf
> Bezirksregierung Münster
> Dezernat 61
> Domplatz 1-348161 Münster
> Tel.:   ++ 49 (02 51) / 4 11 - 17 95
> Fax.:   ++ 49 (02 51) / 4 11 - 8 17 95
> E-Mail: [EMAIL PROTECTED]
>
> __
> [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
>

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


[R] Problem with German special characters

2004-12-14 Thread Wolf, Michael
Dear list!

When using the German special characters I didn't see all characters in the 
correct way. Let's take the command

ff <- "äöüßÄÖÜ"   # (for those ones who can't see this in the correct way \"a, 
\"ö, \"ü
  # \ss (?), \"A, \"O and \"U in LaTeX commands

'ff' will show the output text "\344\366üß\304\326\334" on Rconsole. So only 
"ü" ("\u) and "ß" (\ss) are shown in the correct way. The other characters are 
coded in the "\" form.

I found out that this problem doesn't occur when exporting 'ff' to a text file 
with 'writeLines'. When opening this file with a text editor you can see all 
characters in the correct way.

What can I do to get the correct output of the special characters?

Thanks for your help in advance!

Mit freundlichen Grüßen

Dr. Michael Wolf
Bezirksregierung Münster
Dezernat 61
Domplatz 1-348161 Münster
Tel.:   ++ 49 (02 51) / 4 11 - 17 95
Fax.:   ++ 49 (02 51) / 4 11 - 8 17 95
E-Mail: [EMAIL PROTECTED]

__
[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] Hexidecimal conversion

2004-12-02 Thread Peter Wolf
Some years ago I wrote a function to convert a number
from number system "base.in" to number system "base.out".
Here is the code:
<<*>>=
chcode <- function(b, base.in=2, base.out=10, digits="0123456789ABCDEF"){
  # change of number systems, pw 10/02
  # e.g.: from 2 2 2 2 ...  ->  16 16 16 ...
  digits<-substring(digits,1:nchar(digits),1:nchar(digits))
  if(length(base.in)==1) base.in <- rep(base.in, max(nchar(b)-1))
  if(is.numeric(b)) b <- as.character(as.integer(b))
  b.num <- lapply(strsplit(b,""), function(x) match(x,digits)-1  )
  result <- lapply(b.num, function(x){
   cumprod(rev(c(base.in,1))[ 1:length(x) ] ) %*% rev(x)
} )
  number<-unlist(result)
  cat("decimal representation:",number,"\n")
  if(length(base.out)==1){
 base.out<-rep(base.out,1+ceiling(log( max(number), base=base.out ) ) )
  }
  n.base <- length(base.out); result <- NULL
  for(i in n.base:1){
result <- rbind(number %% base.out[i], result)
number <- floor(number/base.out[i])
  }
  result[]<-digits[result+1]
  apply(result, 2, paste, collapse="")
}
@
... a short check:
<<*>>=
chcode("9F",16,10)
@
output-start
decimal representation: 159
[1] "0159"
output-end
@
... conversion backwards:
<<*>>=
chcode("159",10,16)
@
output-start
decimal representation: 159
[1] "09F"
output-end
Is chcode the function you are looking for?
Peter Wolf
Hanke, Alex wrote:
Help
I can produce the hexidecimal equivalent of a decimal number but I am having
a hard time reversing the operation. I'm good for hex representations to 159
and am close to extending to 2559. The archives are not clear on the
existence of a function for this task. Is there one?
Here is what I have got so far:
#Good for hex values to "9F"
as.decmode<-function(as.character(x)){
 hexDigit<-c(0:9,LETTERS[1:6])
 z<-matrix(c(strsplit(x, NULL),recursive=T),
 length(x),2,byrow=T)
 z.1<-as.numeric(z[,1])
 z.2<- match(z[,2],hexDigit)-1
 dec<-16*z.1+z.2
 return(dec)
 }
Alex Hanke
Department of Fisheries and Oceans
St. Andrews Biological Station
531 Brandy Cove Road
St. Andrews, NB
Canada
E5B 2L9

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

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


[R] number of pairwise present data in matrix with missings

2004-11-23 Thread Andreas Wolf
is there a smart way of determining the number of pairwise present data
in a data matrix with missings (maybe as a by-product of some
statistical function?)

so far, i used several loops like:

for (column1 in 1:99) {
  for (column2 in 2:100) {
for (row in 1:500) {
  if (!is.na(matrix[row,column1]) & !is.na(matrix[row,column2])) {
pairs[col1,col2] <- pairs[col1,col2]+1
  }
}
  }
}

but this seems neither the most elegant nor an utterly fast solution.

thanks for suggestions.
andreas wolf

__
[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] how to get to interesting part of pattern match

2004-11-19 Thread Peter Wolf
Vadim Ogranovich wrote:
Hi,
I am looking for a way to extract an "interesting" part of the match to
a regular expression. For example the pattern "[./](*.)" matches a
substring that begins with either "." or "/" followed by anything. I am
interested in this "anything" w/o the "." or "/" prefix. If say I match
the pattern against "abc/foo" I want to get "foo", not "/foo". In Perl
one can simply wrap the "interesting" part in () and get it out of the
match. Is it possible to do a similar thing in R?
There seems to be a way to refer to the match, see below, but I couldn't
figure out how to make gsub return it.
 

gsub("[./](*.)", "\\1", "abc/foo")
   

[1] "abcfoo"
Thanks,
Vadim
__
[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
 

what about:
gsub(".*[./](*.)", "\\1", "abc/foo")
output-start
[1] "foo"
output-end
or try:
strsplit("abc/foo","/")[[1]][2]
output-start
[1] "foo"
output-end
Peter Wolf
__
[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] Filling polygons with points

2004-10-14 Thread Wolf, Michael
Dear list,

are there any possibilities to fill a polygon with a point pattern or with a symbol 
pattern like '+' oder '-' instead of shading lines?

Thanks in advance

Dr. Michael Wolf
Bezirksregierung Münster
Dezernat 61
Domplatz 1-348161 Münster
Tel.:   ++ 49 (02 51) / 4 11 - 17 95
Fax.:   ++ 49 (02 51) / 4 11 - 8 17 95
E-Mail: [EMAIL PROTECTED]

__
[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] crossprod vs %*% timing

2004-10-06 Thread Peter Wolf
You can study that the order of the operation has an effect on
the times of the computations.
<<*>>=
f1 <- function(a,X){ ignore <- t(a) %*% X %*% a   }
f2 <- function(a,X){ ignore <- crossprod(t(crossprod(a,X)),a) }
f3 <- function(a,X){ ignore <- crossprod(a,X) %*% a   }
f4 <- function(a,X){ ignore <- (t(a) %*% X) %*% a   }
f5 <- function(a,X){ ignore <- t(a) %*% (X %*% a)   }
f6 <- function(a,X){ ignore <- crossprod(a,crossprod(X,a)) }
a <- rnorm(100); X <- matrix(rnorm(1),100,100)
print(system.time( for(i in 1:1){ a1<-f1(a,X)}))
print(system.time( for(i in 1:1){ a2<-f2(a,X)}))
print(system.time( for(i in 1:1){ a3<-f3(a,X)}))
print(system.time( for(i in 1:1){ a4<-f4(a,X)}))
print(system.time( for(i in 1:1){ a5<-f5(a,X)}))
print(system.time( for(i in 1:1){ a6<-f6(a,X)}))
c(a1,a2,a3,a4,a5,a6)
@
output-start
[1] 4.06 0.04 4.11 0.00 0.00
[1] 1.48 0.00 1.53 0.00 0.00
[1] 1.17 0.00 1.22 0.00 0.00
[1] 4.10 0.01 4.39 0.00 0.00
[1] 2.58 0.01 3.24 0.00 0.00
[1] 1.10 0.00 1.29 0.00 0.00
Wed Oct  6 11:26:38 2004
[1] -79.34809 -79.34809 -79.34809 -79.34809 -79.34809 -79.34809
output-end
Peter Wolf

Robin Hankin wrote:
Hi
the manpage says that crossprod(x,y) is formally equivalent to, but
faster than, the call 't(x) %*% y'.
I have a vector 'a' and a matrix 'A', and need to evaluate 't(a) %*% A
%*% a' many many times, and performance is becoming crucial.  With
f1 <- function(a,X){ ignore <- t(a) %*% X %*% a   }
f2 <- function(a,X){ ignore <- crossprod(t(crossprod(a,X)),a) }
f3 <- function(a,X){ ignore <- crossprod(a,X) %*% a   }
a <- rnorm(100)
X <- matrix(rnorm(1),100,100)
print(system.time( for(i in 1:1){ f1(a,X)}))
print(system.time( for(i in 1:1){ f2(a,X)}))
print(system.time( for(i in 1:1){ f3(a,X)}))
I get something like:
[1] 2.68 0.05 2.66 0.00 0.00
[1] 0.48 0.00 0.49 0.00 0.00
[1] 0.29 0.00 0.31 0.00 0.00
with quite low variability from run to run.  What surprises me is the
third figure: about 40% faster than the second one, the extra time
possibly related to the call to t() (and Rprof shows about 35% of
total time in t() for my application).
So it looks like f3() is the winner hands down, at least for this
task.  What is a good way of thinking about such issues?  Anyone got
any performance tips?
I quite often need things like 'a %*% X %*% t(Y) %*% Z %*% t(b)' which
would be something like
crossprod(t(crossprod(t(crossprod(t(crossprod(a,X)),t(Y))),Z)),t(b))
(I think).
(R-1.9.1, 2GHz G5 PowerPC, MacOSX10.3.5)
__
[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] multiple dimensional diag()

2004-10-05 Thread Peter Wolf
Robin Hankin wrote:
hi again Peter
thanks for this.  Now we've got the legal stuff sorted,  on to business!
One of the reasons I wanted the function was to to multidimensional 
moving-
window averaging, and for this I needed to be able to call 
a.block.diag(a,b) when a and b might
have one or more dimensions of zero extent.

I also figure that a scalar argument should be interpreted as having 
dimensions
rep(1,d) where d=length(dim()), and that a.block.diag(n,m)
should return plain old diag(n,m) if both n and m are scalars.

I've modified your function do to this, and added a padding value 
argument (function
and a couple of calls pasted  below)

what do you think? 

perfect!
... and if you want to combine more than two arrays you can add a 
function like   mbd

mbd<-function(...,pad=0){
 result<-(args<-list(...))[[1]]
 for(li in args[-1]) result<-a.block.diag(result,li,pad=pad)
 return(result)
}
a <- matrix(1:4,2,2)
mbd(a,a,a,a,pad=10)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]13   10   10   10   10   10   10
[2,]24   10   10   10   10   10   10
[3,]   10   1013   10   10   10   10
[4,]   10   1024   10   10   10   10
[5,]   10   10   10   1013   10   10
[6,]   10   10   10   1024   10   10
[7,]   10   10   10   10   10   1013
[8,]   10   10   10   10   10   1024
... or integrate the loop into a.block.diag
Peter Wolf


best wishes
Robin

a.block.diag" <- function(a,b,pad=0) {
  ## a.block.daig combines arrays a and b and builds a new array which 
has
  ## a and b as blocks on its diagonal. pw 10/2004

  if( (length(a)==1) & (length(b)==1) ){return(diag(c(a,b)))}
  if(length(a)==1){dim(a) <- rep(1,length(dim(b)))}
  if(length(b)==1){dim(b) <- rep(1,length(dim(a)))}
  if(length(dim.a <- dim(a)) != length(dim.b <- dim(b))){
stop("a and b must have identical number of dimensions")
  }
  seq.new <- function(i){if(i==0){return(NULL)} else {return(1:i)}}
  s <- array(pad, dim.a+dim.b)
  s <- do.call("[<-",c(list(s),lapply(dim.a,seq.new),list(a)))
  ind <- lapply(seq(dim.b),function(i)seq.new(dim.b[[i]])+dim.a[[i]])
  do.call("[<-",c(list(s),ind,list(b)))
}
 a <- matrix(1:4,2,2)
 a
 [,1] [,2]
[1,]13
[2,]24
 b <- array(1e44,c(0,3))
 b
 [,1] [,2] [,3]
 a.block.diag(a,b)
 [,1] [,2] [,3] [,4] [,5]
[1,]13000
[2,]24000



Before I go any further, I need to check that it's OK with you for 
me to put this
function (or modifications of it) into my package, which is GPL. 
Full authorship credit given.
Is this OK?

Hallo Robin,
you are welcome to put  a.block.diag()  in your package.
The function is free software; you can redistribute it and/or modify 
it under the terms of the GNU...

Peter Wolf


__
[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] multiple dimensional diag()

2004-10-01 Thread Peter Wolf
Here is a function that does what you want (perhaps):
<<*>>=
a.block.diag <- function(a,b) {
 # a.block.daig combines arrays a and b and builds a new array which has
 # a and b as blocks on its diagonal. pw 10/2004
 if(length(dim.a<-dim(a))!= length(dim.b<-dim(b))){
   stop("a and b must have identical number of dimensions")}
 s<-array(0,dim.a+dim.b)
 s<-do.call("[<-",c(list(s),lapply(dim.a,seq),list(a)))
 ind<-lapply(seq(dim.b),function(i)seq(dim.b[[i]])+dim.a[[i]])
 do.call("[<-",c(list(s),ind,list(b)))
}
@
Try:
<<*>>=
a=matrix(1,3,4); b=matrix(2,2,2)
a.block.diag(a,b)
@
output-start
Fri Oct  1 17:20:26 2004
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]111100
[2,]111100
[3,]111100
[4,]000022
[5,]000022
output-end
and an another example:
<<*>>=
xx<-array(1:8,c(2,rep(2,2))); yy<-array(-1*(1:9),c(2,rep(3,2)))
a.block.diag(xx,yy)
@
output-start
Fri Oct  1 17:21:38 2004
, , 1
[,1] [,2] [,3] [,4] [,5]
[1,]13000
[2,]24000
[3,]00000
[4,]00000
, , 2
[,1] [,2] [,3] [,4] [,5]
[1,]57000
[2,]68000
[3,]00000
[4,]00000
, , 3
[,1] [,2] [,3] [,4] [,5]
[1,]00000
[2,]00000
[3,]00   -1   -3   -5
[4,]00   -2   -4   -6
, , 4
[,1] [,2] [,3] [,4] [,5]
[1,]00000
[2,]00000
[3,]00   -7   -9   -2
[4,]00   -8   -1   -3
, , 5
[,1] [,2] [,3] [,4] [,5]
[1,]00000
[2,]00000
[3,]00   -4   -6   -8
[4,]00   -5   -7   -9
output-end
a.block.diag is not always the best solution. In case of
x<-array(1:8,rep(2,3)); y<-array(-1,rep(2,3))
the function adiag will be a little bit faster.
Peter Wolf

Robin Hankin wrote:
Hi
I have two arbitrarily dimensioned arrays, "a" and "b", with
length(dim(a))==length(dim(b)).  I want to form a sort of
"corner-to-corner" version of abind(), or a multidimensional version
of blockdiag().
In the case of matrices, the function is easy to write and if
a=matrix(1,3,4) and b=matrix(2,2,2), then adiag(a,b) would return:
 [,1] [,2] [,3] [,4] [,5] [,6]
[1,]111100
[2,]111100
[3,]111100
[4,]000022
[5,]000022
I am trying to generalize this to two higher dimensional arrays.
If x <- adiag(a,b) then I want all(dim(x)==dim(a)+dim(b)); and if
dim(a)=c(a_1, a_2,...a_d) then x[1:a_1,1:a_2,...,1:a_d]=a, and
x[(a_1+1):(a_1+b_1),...,(a_d+1):(a_d+b_d)]=b.  Other elements of x are
zero.
The fact that I'm having difficulty expressing this succinctly makes
me think I'm missing something basic.
If a and b have identical dimensions [ie all(dim(a)==dim(b)) ], the
following ghastly kludge (which is one of many) works:
adiag <- function(a,b) {
  if(any(dim(a) != dim(b))){stop("a and b must have identical 
dimensions")}
  jj <- array(0,rep(2,length(dim(a
  jj[1] <- 1
  jj[length(jj)] <- 1
  jj <- kronecker(jj,b)
  f <- function(i){1:i}
  do.call("[<-",c(list(jj),sapply(dim(a),f,simplify=FALSE),list(a)))
}

Then "adiag(array(1:8,rep(2,3)),array(-1,rep(2,3)))" is OK.  What is
the best way to bind arbitrarily dimensioned arrays together
corner-to-corner?

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


AW: AW: [R] How to improve the quality of curve/line plots?

2004-09-24 Thread Wolf, Michael
Thanks for your help. 

When testing your examples and hints I saw that printing the graph
results in a better (optimal) appearance of the line. Consequently, the
postscript command will lead to "clean" line appearances using a high
resolution/quality printer. At least, that's the decisive point in order
to get an optimal output!

Best wishes,

Michael Wolf

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


AW: [R] How to improve the quality of curve/line plots?

2004-09-24 Thread Wolf, Michael
Thanks for the tip using a smoothing technique before plotiing in order to get a curve 
instead of a line connecting the observations.

But that's not the solution for my main problem with the "unclean" line plot. In order 
to show my problem let's take this simple example:

> xval <- c(1, 2, 3, 4, 5, 6, 7, 8)
> yval <- c(10, 30, 40, 50, 70, 90, 100, 110)
> plot (xval, yval, type="l")

If you look to the result in the graphic window you will see that the line seems to 
exist of many points between the observations; e. g. between xval=1 and xval=2 the 
line contains 8 or more sublines. Perhaps, you can also observe a break of the line at 
xval=4. That's what I call an "unclean line". 

Even if you try to export the plot with the png command you can observe the same 
phenomenon. The line has not an exact appearance like Excel diagram plots. If there 
are no other techniques to get better line plots it seems to be a problem of the 
graphic output!? 

Michael Wolf

-Ursprüngliche Nachricht-
Von: Uwe Ligges [mailto:[EMAIL PROTECTED] 
Gesendet: Freitag, 24. September 2004 09:00
An: Wolf, Michael
Cc: [EMAIL PROTECTED]
Betreff: Re: [R] How to improve the quality of curve/line plots?

Wolf, Michael wrote:

> Dear list,
> 
> I'm using the windows version of R. When plotting a curve or a line for time series 
> with annual data , e. g. GDP growth 1991-2003, the line seems to exist of a lot of 
> smaller lines. Printing the results the curves and lines seems to be "unclean" 
> (because of using small resolution bitmaps?). Comparing the result of R with the 
> same results of Excel the lines in excel seems to havve a higher qualitiy. In Excel 
> you also can produce curves instead of lines.
> 
> Are there any possibilities how to improve the quality of the plots in R? How can R 
> be influenced to plot "clean" lines with a higher resolution on the screen (I think 
> it's not a question of the pdf- or png command.). Perhaps, it's a problem of the 
> graphical possibilites of R because the most line plots which can be seen on the web 
> have these problems.

Can you specify an example please? I cannot remember any "unclean" plot. 
In particular, no bitmaps are used to render graphics in R.

What I guess is that you have a line plot and each observation is connected with the 
subsequent one by a line. If you want to smooth it (and you think smoothing is 
appropriate here), you have to apply a smoothing technique before plotting.

Uwe Ligges


> Thanks,
> 
> Dr. Michael Wolf
> Bezirksregierung Münster
> Dezernat 61
> Domplatz 1-348161 Münster
> Tel.:   ++ 49 (02 51) / 4 11 - 17 95
> Fax.:   ++ 49 (02 51) / 4 11 - 8 17 95
> E-Mail: [EMAIL PROTECTED]
> 
> __
> [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

__
[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] How to improve the quality of curve/line plots?

2004-09-23 Thread Wolf, Michael
Dear list,

I'm using the windows version of R. When plotting a curve or a line for time series 
with annual data , e. g. GDP growth 1991-2003, the line seems to exist of a lot of 
smaller lines. Printing the results the curves and lines seems to be "unclean" 
(because of using small resolution bitmaps?). Comparing the result of R with the same 
results of Excel the lines in excel seems to havve a higher qualitiy. In Excel you 
also can produce curves instead of lines.

Are there any possibilities how to improve the quality of the plots in R? How can R be 
influenced to plot "clean" lines with a higher resolution on the screen (I think it's 
not a question of the pdf- or png command.). Perhaps, it's a problem of the graphical 
possibilites of R because the most line plots which can be seen on the web have these 
problems.

Thanks,

Dr. Michael Wolf
Bezirksregierung Münster
Dezernat 61
Domplatz 1-348161 Münster
Tel.:   ++ 49 (02 51) / 4 11 - 17 95
Fax.:   ++ 49 (02 51) / 4 11 - 8 17 95
E-Mail: [EMAIL PROTECTED]

__
[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] loops: pasting indexes in variables names

2004-09-22 Thread Peter Wolf
Umberto Maggiore wrote:
I cannot figure out how, using R, I can paste indexes or characters to 
the variable
names which are used within loops. I will explain this with a simple 
example:
Immagine I have a huge series of variables, each one taken two times, say
x1 x2 y1 y2 z1 z2.
Now, immagine that I want to compute a variable from the difference of
each couple, say dx=x1-x2, dy=y1-y2, dz=z1-z2...
In Stata, for example,  this wold be straightforward:
foreach i in x y z   {
gen  d`i'= `i'1-`i'2
}
With R I tried to use paste( ) but I found that it applies to objects,
not to variable names.
best regards,
Umberto

__
[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
Try:
x1<-10
x2<-20
y1<-5
y2<-22
z1<-4
z2<-7
for(i in c("x","y","z")){
 eval(parse(text=paste("d",i,"<-",i,"1 - ",i,"2",sep="")))
}
ls(pattern="d")
output-start
Wed Sep 22 14:38:28 2004
[1] "dx" "dy" "dz"
output-end
but why don't  you  store x1,y1,z1  and x2,y2,z2  in a list:
a<-list(x=1:4, y=1:7, z=1:5)
b<-list(x=(1:4)*10, y=1:7, z=(1:5)-20)
d<-sapply(1:3, function(i) a[[i]]-b[[i]] )
@
output-start
Wed Sep 22 14:43:09 2004
[[1]]
[1]  -9 -18 -27 -36
[[2]]
[1] 0 0 0 0 0 0 0
[[3]]
[1] 20 20 20 20 20
output-end
Peter Wolf
__
[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] persiting complex R objects

2004-09-20 Thread Peter Wolf
Richard Mott wrote:
Is there a method to save a large and complex R object (either as a 
binary or text file) so that it can be loaded and reused at a later 
time? Specifically, I am creating large lists (several thousand 
elements), each element of which is either a vector or a matrix (with 
~ 2000 rows). The dimensions of the matrices are not all the same. My 
ideal would be a set of functions of the form

obj <- create() # computes  the object
save(obj,filename)
obj <- load(filename)
Have a look at
? dump
? source
Peter Wolf
__
[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] efficient submatrix extraction

2004-09-16 Thread Peter Wolf
there are two main ideas to improve the efficiency:
1. the comparison with the limit can be done at first
2. a matrix with boxsize*boxsize rows can be defined so that
  you can apply function "apply" without using inner loops
<<*>>=
# parameters
size<-1024; limit<-0.7
# some data
set.seed(17); data<-runif(size^2)
m<-matrix(data,size,size)
bcount.vec<-NULL
m<-m>limit
for (boxsize in 2^(1:8)) {
 # inner loop:
 m<-array(m,c(boxsize,size/boxsize,size))
 m<-aperm(m,c(1,3,2))
 m<-matrix(m,nrow=boxsize*boxsize)
 bcount.vec<-c(bcount.vec,sum(apply(m,2,max)))
}
bcount<-sum(bcount.vec)
print(bcount.vec)
print(bcount)
@
output-start
[1] 199099  65306  16384   4096   1024256 64 16
[1] 286245
output-end
Some remarks on your code:
The first expression in your outer loop is setting bcount to 0.
In the inner loops bcount is incremented.
But the outer loop sets bcount to the value 0 again!?
What do you want to count?
Peter
Rajarshi Guha wrote:
Hi,
 I have a matrix of say 1024x1024 and I want to look at it in chunks.
That is I'd like to divide into a series of submatrices of order 2x2.
| 1 2 3 4 5 6 7 8 ... |
| 1 2 3 4 5 6 7 8 ... |
| 1 2 3 4 5 6 7 8 ... |
| 1 2 3 4 5 6 7 8 ... |
...
So the first submatrix would be
| 1 2 |
| 1 2 |
the second one would be
| 3 4 |
| 3 4 |
and so on. That is I want the matrix to be evenly divided into 2x2
submatrices. Now I'm also doing this subdivision into 4x4, 8x8 ...
256x256 submatrices.
Currently I'm using loops and I'm sure there is a mroe efficient way to
do it:
   m <- matrix(runif(1024*1024), nrow=1024)
   boxsize <- 2^(1:8)
   for (b in boxsize) {
   bcount <- 0
   bstart <- seq(1,1024, by=b)
   for (x in bstart) {
   for (y in bstart) {
   xend <- x + b - 1
   yend <- y + b - 1
   if (length(which( m[ x:xend, y:yend ] > 0.7)) > 0) {
   bcount <- bcount + 1
   }
   }
   }
   }
Is there any way to vectorize the two inner loops?
Thanks,
---
Rajarshi Guha <[EMAIL PROTECTED]> 
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
---
The way to love anything is to realize that it might be lost.
__
[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
 

__
[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] reshaping some data

2004-09-14 Thread Peter Wolf
Try:
x <- data.frame(x1 =  1: 5, y11 =  1: 5,
   x2 =  6:10, y21 =  6:10, y22 = 11:15,
   x3 = 11:15, y31 = 16:20,
   x4 = 16:20, y41 = 21:25, y42 = 26:30, y43 = 31:35)
df.names<-names(x)
ynames<-df.names[grep("y",df.names)]
xnames<-substring(sub("y","x",ynames),1,2)
cbind(unlist(x[,xnames]),unlist(x[,ynames]))
Peter
Sundar Dorai-Raj wrote:
Hi all,
  I have a data.frame with the following colnames pattern:
x1 y11 x2 y21 y22 y23 x3 y31 y32 ...
I.e. I have an x followed by a few y's. What I would like to do is 
turn this wide format into a tall format with two columns: "x", "y". 
The structure is that xi needs to be associated with yij (e.g. x1 
should next to y11 and y12, x2 should be next to y21, y22, and y23, 
etc.).

 x   y
x1 y11
x2 y21
x2 y22
x2 y23
x3 y31
x3 y32
...
I have looked at ?reshape but I didn't see how it could work with this 
structure. I have a solution using nested for loops (see below), but 
it's slow and not very efficient. I would like to find a vectorised 
solution that would achieve the same thing.

Now, for an example:
x <- data.frame(x1 =  1: 5, y11 =  1: 5,
x2 =  6:10, y21 =  6:10, y22 = 11:15,
x3 = 11:15, y31 = 16:20,
x4 = 16:20, y41 = 21:25, y42 = 26:30, y43 = 31:35)
# which are the x columns
nmx <- grep("^x", names(x))
# which are the y columns
nmy <- grep("^y", names(x))
# grab y values
y <- unlist(x[nmy])
# reserve some space for the x's
z <- vector("numeric", length(y))
# a loop counter
k <- 0
n <- nrow(x)
seq.n <- seq(n)
# determine how many times to repeat the x's
repy <- diff(c(nmx, length(names(x)) + 1)) - 1
for(i in seq(along = nmx)) {
  for(j in seq(repy[i])) {
# store the x values in the appropriate z indices
z[seq.n + k * n] <- x[, nmx[i]]
# move to next block in z
k <- k + 1
  }
}
data.frame(x = z, y = y, row.names = NULL)
__
[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
__
[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] Making a ranking algorithm more efficient

2004-06-02 Thread Peter Wolf
let's start by defining x and y matching the properties of the points in 
the picture
<<*>>=
x<-c(1,2,4,5,9,3,7,6); y<-c(10,8,5,3,2,9,4,7)
plot(x,y,pch=letters[1:8])

@
along each dimension we have to compare the coordinates of the points:
<<*>>=
outer(x,x,"<")
@
we get a logical matrix:
output-start
Wed Jun  2 10:36:52 2004
 [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]
[1,] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[2,] FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[3,] FALSE FALSE FALSE  TRUE  TRUE FALSE  TRUE  TRUE
[4,] FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE
[5,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[6,] FALSE FALSE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
[7,] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
[8,] FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE
output-end
results of dimension x and of dimension y have to be aggregated by "&"
<<*>>=
outer(x,x,"<")&outer(y,y,"<")
@
and we get:
output-start
Wed Jun  2 10:44:56 2004
 [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]
[1,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2,] FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
[3,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
[4,] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
[5,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[6,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[7,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[8,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
output-end
TRUE in position (i,j) indicates that x- and y-coordinates of point i 
are smaller
than those of point j. The sum of row i shows the number of
points that dominate point i. The sum of col j shows the number of points
that are dominated by point j.

@
so we can compute the the number of dominated points by applying 
function sum on the cols:
<<*>>=
apply(outer(x,x,"<")&outer(y,y,"<"),2,sum)

@
at last some polishing
<<*>>=
result<-apply(outer(x,x,"<")&outer(y,y,"<"),2,sum)+1
names(result)<-letters[1:8]
result
@
output-start
Wed Jun  2 10:59:03 2004
a b c d e f g h
1 1 1 1 1 2 2 3
output-end
in the case of more than 2 dimensions you have to add further 
outer-operations

Peter Wolf

Waichler, Scott R wrote:
I would like to make a ranking operation more efficient if possible.
The goal is to rank a set of points representing objective 
function values such that points which are "dominated" by no 
others have rank 1, those which are dominated by one other point 
have rank 2, etc.  In the example with two dimensions below, objective
functions 1 and 2 are to be minimized.  Points a-e are non-dominated,
rank 1 points.  Point f is rank 2 because point b is superior, and 
point g is rank 2 because point d is superior.  Point h is rank 3 
because points c and d are both superior.

  | a 
  |f
  |  b
  |   h  (figure requires monospaced, plain-text
display)
Obj 1  | c
  | g 
  |  d 
  |e
  |

 Obj 2
I need to compute the ranks of the rows of a matrix, where each row
represents a point in objective space and the columns
contain the objective function values to be minimized.  
Rank is defined as the number of points with objective function 
values less than or equal to the current point (including the current 
point).  I've written the following function with two loops:

 PARETO.RANK <- function(obj.array) {
   obj.array <- unique(obj.array)
   
   ind.row <- 1:nrow(obj.array)
   ind.col <- 1:ncol(obj.array)

   rank.vec <- rep(NA, length(ind.row)) # initialize
   # Loop thru rows (points in objective function space)
   for(i in ind.row) { 
 set <- ind.row
 for (j in ind.col) {  # Loop thru objective functions
   set <- set[ obj.array[set,j] <= obj.array[i,j] ]
 }
 rank.vec[i] <- length(set)
   }
   return(rank.vec)
 } # end PARETO.RANK3()

Can anyone think of a way to do this more efficiently, for example by
vectorizing further?  

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

__
[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] advanced dist

2004-06-02 Thread Peter Wolf
Martin Klaffenboeck wrote:
Hi there.
I have now found that dist() does what I want in a specific case.
But I have (out of many fields) in my Fragebogen.data file:
VpnCodeFamilyTest
1X1m45
2X1t58
3X2m44
4X2t43
...
When I now do:
Fbg <- read.table("Fragebogen.data", header=TRUE)
dist(Fbg['Test'])
I have the distances between everyone to everyone.
Now I want to have the mothers (m in Family) at the y axis and the  
daugthers (t) on the x axis, so I have half the size of my distance  
matrix.

Is that possible somehow?
And if possible, I would have the 'Code' at the top to know which  
mother and wich daugther are compared.

Thanks,
Martin
__
[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
what about:
>  mtdist<- as.matrix(dist(Fbg['Test']))
   dimnames(mtdist) <- list( Fbg[ 'Family' ], Fbg[ 'Family' ] )
   mtdist [ Fbg['Code']=="m" ,Fbg['Code']=="t" ]
Peter Wolf
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] syntax error in function 'for'

2004-05-05 Thread Peter Wolf
Ulrich Leopold wrote:
On Wed, 2004-05-05 at 17:11, Peter Dalgaard wrote:
 

Ulrich Leopold <[EMAIL PROTECTED]> writes:
   

Dear list,
I get a syntax error for the following function:
for(na.omit(sqrt(D))>2) {na.omit(A)-(na.omit(B)+(na.omit(sqrt(C}
Any idea what is wrong?
 

Yes, that's not the syntax for a for loop. I have no idea what your
intention might have been, though.
   

Ok thanks. I think I misunderstood the example in the help. I think, I
rather need an if function.
I would like to calculate the right hand side if the condition on the
left hand side is met. I am afraid I do not quite understand the syntax.
if(na.omit(sqrt(D))>2) {na.omit(A)-(na.omit(B)+(na.omit(sqrt(C}
Now I get the following warning:
the condition has length > 1 and only the first element will be used in:
if(na.omit(sqrt(D))>2) {
What is the result of the "condition"   (1:10) >2 ? What should be done?
Read the text of the warning again.
Peter Wolf
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] syntax error in function 'for'

2004-05-05 Thread Peter Wolf
Ulrich Leopold wrote:
Dear list,
I get a syntax error for the following function:
for(na.omit(sqrt(D))>2) {na.omit(A)-(na.omit(B)+(na.omit(sqrt(C}
Any idea what is wrong?
I am using R 1.8.1 on Linux, Kernel 2.4.21-i686.
Regards, Ulrich
 

have a look at help("for"):
Control package:base R Documentation
Control Flow
Description:
...
Usage:
if(cond) expr
if(cond) cons.expr  else  alt.expr
for(var in seq) expr
   ...
Examples:
for(i in 1:5) print(1:i)
for(n in c(2,5,10,20,50)) {
   x <- rnorm(n)
   cat(n,":", sum(x^2),"\n")
}
Peter Wolf
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Superposing data on boxplot

2004-05-04 Thread Peter Wolf
What about:
y<-rnorm(100);z<-sample(1:7,100,T);boxplot(y~z);points(y~z)
Peter Wolf
Ted Harding wrote:
Hi folks,
I have a vaiable Y and an associated factor Z at several (13)
levels.
 boxplot(Y~Z)
produces a nice array of boxplots, one for each level of Z,
and each duly labaelled with its level of Z.
I would like to superpose on each boxplot the actual data
points which it represents, i.e. do something conceptually
(though not in real R) expressed as
 points(Y~Z)
or
 points(Z,Y)
It can be done "with bare hands" along the lines of
 B<-boxplot(Y~Z)
 x<-bxp(B)
 X<-rep(x,ngroups)
 points(X,Y)
where ngroups is the number of data at each level of Z,
*provided* the data are pre-sorted by level of Z and in the
same order as these levels occurr in the boxplot. But of course
they're not!
OK, I could do this by hand as well, but now it's getting a bit
tedious, and I'm wondering if there's a better way.
Thanks for any suggestions,
Ted.

E-Mail: (Ted Harding) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 167 1972
Date: 04-May-04   Time: 15:48:23
-- XFMail --
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

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


Re: [R] rbind with missing columns

2004-04-30 Thread Peter Wolf
here is another solution:
A <- data.frame(a = c(1,2,3), b = c(4,5,6))
B <- data.frame(a = c(1,2,3))
C <- data.frame(b=4:6)
rbind.data.frame.NA<-function(...){
 N<-unique(unlist(lapply(list(...),names)))
 result<-NULL
 for(DF in list(...)){
   x<-as.data.frame(lapply(N,function(x)if(x %in% names(DF)) DF[,x] 
else NA))
   names(x)<-N
   result<-rbind(result,x)
 }
 result
}

rbind.data.frame.NA(B,A,C)
@
output-start
Fri Apr 30 15:21:21 2004
   a  b
1   1 NA
2   2 NA
3   3 NA
11  1  4
21  2  5
31  3  6
12 NA  4
22 NA  5
32 NA  6
output-end
Peter Wolf
Duncan Murdoch wrote:
On Fri, 30 Apr 2004 13:47:35 +0200, <[EMAIL PROTECTED]> wrote :
 

Hello,
I have several data sets, which I want to combine column-by-column using
"rbind" (the data sets have ~100 columns). The problem is, that in some
data sets some of the columns are missing.
Simply using rbind gives me:
"Error in match.names(clabs, names(xi)) : names don't match previous
names"
Is there a simple way to make R do the rbind despite the missing columns
and to fill out the missing data with NA's? (I could program this
somehow, but probably there is one very simple solution available)
   

It's not there already as far as I know, but it's not too hard to
write a new rbind that does this:
newrbind <- function(A,B) {
 anames <- names(A)
 bnames <- names(B)
 notinb <- anames[!(anames %in% bnames)]
 if (length(notinb)) B[[notinb]] <- rep(NA, nrow(B))
 notina <- bnames[!(bnames %in% anames)]
 if (length(notina)) A[[notina]] <- rep(NA, nrow(A))
 rbind(A, B)
}
This only works on data.frames; if you want it to work as generally as
the real rbind, you'll need to add some extra conversions at the
start.
Duncan Murdoch
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

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


Re: [R] GUI checkbox linked to entry

2004-04-29 Thread Peter Wolf
Julien Glenat wrote:
Hi , i am using R 1.8 and tcltk library in order to make a GUI and i would 
like to know if it is possible to link a check box to one or more entry 
dynamically (and eventually other widgets) .
( in concrete terms : if the check box is ticked the entry is avaible for 
input and unavaible when not ticked)

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

Are you looking for something like this?
require(tcltk)
cbValue <- tclVar("0"); info<-tclVar("initial text")
top <- tktoplevel()
cb  <- tkcheckbutton(top,variable=cbValue,text="write or not")
en  <- tkentry  (top,textvariable=info,state="disabled")
exit<- tkbutton (top, text="exit", command=function() tkdestroy(top))
tkpack(cb,en,exit)
set.entry.state<-function(){
   on.off<-tclvalue(cbValue)
   if(on.off=="1") tkconfigure(en, state="normal")
   if(on.off=="0") tkconfigure(en, state="disabled")
   print(on.off)
}
tkbind(top,"<1>",set.entry.state)
Do you know http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples?
Peter Wolf
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] accessing information in lists

2004-04-29 Thread Peter Wolf
Try:
<<*>>=
rev.matrix<-matrix(rnorm(40),10,4)
rev.acf<-apply(rev.matrix, 2, acf, na.action=na.contiguous, lag.max=12, 
plot=FALSE)
x.acf<-lapply(rev.acf,function(x) x[["acf"]][,,1])
matrix(unlist(x.acf),ncol=4)

output-start
Thu Apr 29 09:56:22 2004
[,1] [,2][,3][,4]
[1,]  1.  1.0  1.  1.
[2,] -0.18009242 -0.066131687 -0.19268167 -0.25340270
[3,] -0.15442666 -0.342732543 -0.30959136 -0.11987720
[4,]  0.14785268  0.074751553  0.16748753 -0.16495692
[5,] -0.34024505  0.210414077 -0.03338385  0.25205651
[6,] -0.05562243  0.044047730  0.02971677 -0.05640866
[7,]  0.09955468 -0.358754179 -0.02301302 -0.11177397
[8,]  0.01609530  0.072731988 -0.16732203 -0.25562259
[9,] -0.04621386 -0.005510738 -0.13049985  0.23890998
[10,]  0.01309776 -0.128816203  0.15928749 -0.02892446
output-end
BTW -- do not use  the name  t  for a variable, parameter, etc. because
there is a function  t().
Peter Wolf
Murray Keir wrote:
I've created a dataframe containing multiple ACF lists through the command
rev.acf<-apply(rev.matrix, 2, acf, na.action=na.contiguous, lag.max=12, plot=FALSE)
where rev.matrix is an n by t matrix containing n time series in columns.  I'd now like to pull out only the ACF information and store it in a seperate n by 12 matrix.  So far the only way I can work out to access this is 

rev.acf[["series1"]][["acf"]]
rev.acf[["series2"]][["acf"]]
etc
Is there some way I can do this automatically?
Thanks
Murray


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

__
[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] Tcl Tk table

2004-04-23 Thread Peter Wolf
[EMAIL PROTECTED] wrote:

Hi 

I've a problem with the following example:

library(tcltk)
.Tcl("array unset tclArray")
myRarray <- matrix(1:1000, ncol=20)

for (i in (0:49))
 for (j in (0:19))
.Tcl(paste("set tclArray(",i,",",j,") ",myRarray[i+1,j+1],sep=""))

tt<-tktoplevel()

table1 <- tkwidget(tt,"table",variable="tclArray", rows="50", cols="50")

tkpack(table1)

#Old version which worked in R 1.6 but it doesn't work with R 1.9 (and also not with 
1.8), why??
.
Under R version 1.6 I had no problem. Now I installed R 1.9 (with ActiveTcl) and my 
program doesn't work. ...
Thomas
__
[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
 

Are you sure?

> library(tcltk)
> .Tcl("array unset tclArray")

>
> myRarray <- matrix(1:1000, ncol=20)
>
> for (i in (0:49))
+   for (j in (0:19))
+  .Tcl(paste("set tclArray(",i,",",j,") ",myRarray[i+1,j+1],sep=""))
>
> tt<-tktoplevel()
>
> table1 <- tkwidget(tt,"table",variable="tclArray", rows="50", cols="50")
Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class = 
"tclObj") :
   [tcl] invalid command name "table".
>
> version
_
platform i686-pc-linux-gnu
arch i686
os   linux-gnu
system   i686, linux-gnu
status
major1
minor6.2
year 2003
month01
day  10
language R

the error occurs with version 1.6.2, too.

Some debugging shows: the error message comes from tcl/tk and
you need some additional features to be allowed to use the table-widget!
you have to include:
tclRequire("Tktable")

... and all is ok for 1.8.1 and I also hope for 1.9.0.

see: http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/tktable.html

Peter Wolf

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


[R] how to add legend to time series plot

2004-04-14 Thread michael . wolf
Dear all,

I would like to add a legend to a time series plot, but 
cannot get it done. I have searched the archive about this,
but to no avail ...

I have three sets of time series data stored in a matrix
wMat. The following code plots the the data with
a legend, but it does not put the time on the x-axis:


matplot(y = wMat, type = "l",
ylab = "Allocation", main = "GARCH")
legend(1, -0.3, c("Stocks", "Bonds", "Cash"), col = 1:3, lty = 1:3)


The following code puts the time on the x-axis but now the
legend does not show up:


wMat = ts(wMat, frequency = 12, start = c(1968, 2))
ts.plot(wMat[,1], wMat[,2], wMat[,3], col = 1:3, lty = 1:3,
ylab = "Allocation", main = "GARCH")
legend(1, -0.3, c("Stocks", "Bonds", "Cash"), col = 1:3, lty = 1:3)


Can anybody help with this? If needed, I can send along postscript files
of the resulting plots.

I do not subscribe to the list, so please (also) reply directly to me.

Thanks very much,
Michael

__
[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] x-only zoom and pan?

2004-04-05 Thread Peter Wolf
Hallo here is a simple proposal using tcltk-sliders.

Peter Wolf

# step 1:   define general slider function

slider<-function(refresh.code,names,minima,maxima,resolutions,starts,title="control",no=0,
  set.no.value=0){
# pw 03/2004
  if(no!=0) 
return(as.numeric(tclvalue(get(paste("slider",no,sep=""),env=slider.env
  if(set.no.value[1]!=0){ 
try(eval(parse(text=paste("tclvalue(slider",set.no.value[1],")<-",
   set.no.value[2],sep="")),env=slider.env)); 
return(set.no.value[2]) }
  if(!exists("slider.env")) slider.env<<-new.env()
  library(tcltk); nt<-tktoplevel(); tkwm.title(nt,title); 
tkwm.geometry(nt,"+0+0")
  for(i in seq(names))
 
eval(parse(text=paste("assign(\"slider",i,"\",tclVar(starts[i]),env=slider.env)",sep="")))
  for(i in seq(names)){
 tkpack(fr<-tkframe(nt));  lab<-tklabel(fr, text=names[i], width="25")
 sc<-tkscale(fr, command=refresh.code, from=minima[i], to=maxima[i],
showvalue=T, resolution=resolutions[i], orient="horiz")
 assign("sc",sc,env=slider.env); tkpack(lab,sc,side="right")
 
eval(parse(text=paste("tkconfigure(sc,variable=slider",i,")",sep="")),env=slider.env)
  }
  tkpack(fr<-tkframe(nt),fill="x")
  tkpack(tkbutton(fr, text="Exit",
command=function()tkdestroy(nt)),side="right")
  tkpack(tkbutton(fr, text="Reset", command=function(){
 for(i in seq(starts)) 
eval(parse(text=paste("tclvalue(slider",i,")<-",starts[i],sep="")),env=slider.env)
 refresh.code()}  ),side="left")
}

# step 2: define function for zooming

ts.zoom<-function(x,y,z){
# pw 05042004
 library(tcltk)
 n.ts<-1; if(!missing(y)) n.ts<-2; if(!missing(z)) n.ts<-3
 refresh.code<-function(...){
 # initialization
   start<-slider(no=1)*100; delta<-slider(no=2)*100
   if(start+delta>length(x))
 start<-slider(set.no.value=c(1,(length(x)-delta)/100))*100
 # plot
   par(mfrow=c(n.ts,1))
   plot(x,type="l",xlim=c(start,start+delta))
   if(n.ts>=2)  plot(y,type="l",xlim=c(start,start+delta))
   if(n.ts>=3) plot(z,type="l",xlim=c(start,start+delta))
   par(mfrow=c(1,1))
}
 slider(refresh.code,
 # names of sliders
  c("begin index (unit=100)",  "window width (unit=100)"),
 # min of sliders
  c(0,1),
 # max of sliders
  c(floor(length(x)/100),length(x)/100),
 # step of sliders
  c(1,1),
 # initial values
  c(1,1))
}
# step 3: test it.

ts.zoom(runif(1), rexp(1), rnorm(1))



Randy Zelick wrote:

Hello list,

Could the following be done without too much grief...?

Lets say I have two or three time series objects that I want to inspect
visually. Each I would plot with a y-offset so they stack up. They share
the same X scaling. The problem is that each is perhaps 100K values. Due
to the large number of values, features of the data sets cannot be seen
when all values are plotted.
What would be nice is to plot a fraction of the X range (say 10%). This
would be equivalent to zooming in the X direction. Then using a key
(ideally an arrow key), shift the viewing frame right or left to
effectively scroll through the data. So first you view 0-10%, then 10-20%
and so forth.
If necessary I can fabricate a vector with X values in it and plot(x,y)
instead of as time series, if this makes it any easier.
I am using a Windows version of R.

Thanks,

=Randy=

R. Zelick   email: [EMAIL PROTECTED]
Department of Biology   voice: 503-725-3086
Portland State University   fax:   503-725-3888
mailing:
P.O. Box 751
Portland, OR 97207
shipping:
1719 SW 10th Ave, Room 246
Portland, OR 97201
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

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


Re: [R] Zero Index Origin?

2004-04-02 Thread Peter Wolf
Sorting is a wonderful topic! Especially because you can discuss different
fundamental ideas like brute force, divide and conquer, and questions of
efficiency, tradeoffs of space and time, etc. In this way  sort.6  is 
one of a
sequence of sorting algorithms. Each of them demonstrates a specific point
for teaching purposes. You are right: in sort.6 a[0] plays the role of a 
sentinel.
So the main points are:

 1) What is the new idea found in sort.6 (compared to sort.5 -- a 
solution without sentinel)?
 2) Are there other ideas for improvements concerning space and time 
(this leads to sort.7, etc.)?
 3) What about readability: what is the best notation for human readers?
 4) What should be considered and changed in the light of a specific 
computer language?

Your remarks show that often an example initiates a desire  to start  a 
discussion
of one of the four questions. That's what we want to have in the 
classroom, too.
In case of sort.6 my situation was that I have a lot of nice slides with 
algorithms
in pseudo code and I wanted to get them running for demonstration. For APL
is a little bit out of fashion I used my favorite computer language: R.

Thank you for your comments -- which increase the set of R programming 
pearls
and will enrich the discussion in my lectures

Peter Wolf

Richard A. O'Keefe wrote:

I asked where index origin 0 would help.
(I am familiar with Dijkstra's article on why counting should start
at 0 and agree whole-heartedly.  I am also convinced that "kicking
against the goads" is not helpful.)
Peter Wolf <[EMAIL PROTECTED]>
has provided two examples.
(1) Converting pseudo-code which assumes index origin 0.

   I've done this myself, although not yet in R.  I've also done it
   the other way, converting index origin 1 code to C.
   A good method, I've found, is to to start by converting to
   index-free form.  This applies whatever the source and target
   languages are.
(2) A sorting algorithm.

   sort.6 <- function (a) {
  n <- length(a)
  adapt <- function (i) {i+1}
  a <- c(0,a)
  for (i in 2:n) {
  j <- i-1
  a[adapt(0)] <- a[adapt(i)]
  while (a[adapt(j)] > a[adapt(0)]) {
 a[adapt(j+1)] <- a[adapt(j)]
 j <- j-1
  }
  a[adapt(j+1)] <- a[adapt(0)]
  }
  a[-1]
   }
   The really interesting thing here is that this basically is an
   index origin 1 algorithm.  The original array and the final result
   start at 1, not 0, and position 0 is used for a "sentinel".
   Let's convert it to 1-origin.  I'll skip the details of how I
   did it because that's not the point I want to make.
   sort.VI <- function (a) {
  a <- c(0, a)
  for (i in 3:length(a)) {
  j <- i-1
  a[1] <- a[i]
  while (a[j] > a[1]) {
 a[j+1] <- a[j]
 j <- j-1
  }
  a[j+1] <- a[1]
  }
  a[-1]
   }
   What do you get if you move up to index-free form?

   sort.six <- function (a) {
s <- c()
for (x in a) {
f <- s <= x
s <- c(s[f], x, s[!f])# insert x stably into s
}
s
   }
   It's clear that sort.six is shorter, clearer, and easier to get
   right than sort.VI.  But how much do we have to pay for this?
   How much efficiency do we lose?
   > a <- runif(400)
   > system.time(sort.VI(a))
   [1]  3.64  0.02 12.56  0.00  0.00
   > system.time(sort.six(a))
   [1] 0.15 0.01 0.16 0.00 0.00
   We don't lose any efficiency at all.  We gain, considerably.
   (Not as much as we'd gain by using the built-in sort(), of course.)
I expect that this will happen fairly often:  rewriting the code to be
index-free will *usually* make it shorter and clearer, and will *always*
make it easier to adapt to a language with a different index origin.
When the target language is R or S, the result is likely to be faster
than a direct conversion.
 

-

Gabor Grothendieck wrote:

..

and Prof Brian Ripley wrote:

: since you can shift whole blocks at a time rather than use a while loop.

In words the algorithm runs from 2 through length(a) inserting
the current element into the subarray to its left, so to follow up
Prof Riley's suggestion to replace the while loop with code that
copies whole blocks at a time we have the following which does
not seem to suffer from lack of 0-origin and is clearer than
the double loop approach:
sort.6a <- function(a) {
for(i in 2:length(a)){ # insert a[i] into subvector to left of it
left <- a[1:(i-1)]
sel <- left < a[i]
a[1:i] <- c( left[sel], a[i], left[!sel] )
}
a
}
-

Prof Brian Ripley wrote:

I think that is an excellent illustration

Re: [R] Zero Index Origin?

2004-03-31 Thread Peter Wolf
Richard A. O'Keefe wrote:

It would be interesting to see some sample code where origin 0 is supposed
to make life easier, ...
An application is the implementation of algorithms which use origin 0 
and are written in pseudo code.
Write down the statements in R syntax, include some print or browser 
statements and
you are able to demonstrate the working of different approaches. Here is 
an example for sorting
-- I know   sort(x)   is a better solution ...

sort.6<-function(a){
  n<-length(a)
  adapt<-function(i){i+1}  # local function to perform the index correction
  a<-c(0,a)
  for(i in 2:n){
 j<-i-1
 a[adapt(0)]<-a[adapt(i)]
 while(a[adapt(j)]>a[adapt(0)]){
a[adapt(j+1)]<-a[adapt(j)]
j<-j-1
 }
 a[adapt(j+1)]<-a[adapt(0)]
  }
  return(a[-1])
}
Peter Wolf

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


Re: [R] Zero Index Origin?

2004-03-31 Thread Peter Wolf
Bob Cain wrote:

I'm very new to R and utterly blown away by not only the language but 
the unbelievable set of packages and the documentation and the 
documentation standards and...

I was an early APL user and never lost my love for it and in R I find 
most of the essential things I loved about APL except for one thing.  
At this early stage of my learning I can't yet determine if there is a 
way to effect what in APL was zero index origin, the ordinality of 
indexes starts with 0 instead of 1.  Is it possible to effect that in 
R without a lot of difficulty?

I come here today from the world of DSP research and development where 
Matlab has a near hegemony.  I see no reason whatsoever that R 
couldn't replace it with a _far_ better and _far_ less idiosyncratic 
framework.  I'd be interested in working on a Matlab equivalent DSP 
package for R (if that isn't being done by someone) and one of the 
things most criticized about Matlab from the standpoint of the DSP 
programmer is its insistence on 1 origin indexing. Any feedback 
greatly appreciated.

Thanks,

Bob
Hallo Bob,

in APL we control index origin by "QUAD.IO" and  QUAD.IO \in {0,1}.
Suppose within a function index origin is unknown:
a) If we want to work with origin 0 we write   x[ i  + QUAD.IO ]
b) ... with origin 1 ...  x[ i - !QUAD.IO ]  .
So set:   QUAD.IO <- 1 and use a)   ---  apl-like.

Or define an index shift function:

io.0<-function(ind) ind+1

to be able to type  x[io.0(0:5)]

I am shure that your first experiments have been to implement APL functions
like take, drop, rotate, ... and now you are looking for a more elegant way
to manage origin 0 than "+QUAD.IO".
Peter Wolf

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


Re: [R] squashing some numbers

2004-03-22 Thread Peter Wolf
are you looking for s.th. like this?

# some data
m<-c(3,1,2,4,4,4,4,0,5,4,4,5,6,1,1,1)
m<-as.data.frame(matrix(m,4,4))
print(m)
# sort m -- if necessary
m<-m[order(m[,3]),]
m<-m[order(m[,2]),]
# compute sums
cum<-cumsum(m[,4])
# find rows
ind<-c(T,0!=diff(m[,2] )| 0!=diff(m[,3]))
ind<-c(ind[-1],T)
# combine result
mneu<-cbind(m[ind,-4],V4=diff(c(0,cum[ind])))
print(mneu)
initial matrix:
 V1 V2 V3 V4
1  3  4  5  6
2  1  4  4  1
3  2  4  4  1
4  4  0  5  1
result:
 V1 V2 V3 V4
4  4  0  5  1
3  2  4  4  2
1  3  4  5  6
result without sorting

 V1 V2 V3 V4
1  3  4  5  6
3  2  4  4  2
4  4  0  5  1
Peter Wolf

Fred J. wrote:

Hello
I have a data frame with many col.s and rows
V4 V5 V6 V7
3  4   5  6
1  4   4  1
2  4   4  1
4  0   5  1
since the data has the middle 2 rows with V5 and V6
are equal, I need to produce
V4 V5 V6 V7
3  4   5  6
   this line removed and the value V7 = 1 is 

   added to the next row V7 valuve making it
2
2  4   4  2
4  0   5  1

thanks a lot

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

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


Re: [R] expanding some values in logical vector

2004-03-15 Thread Peter Wolf
Try:

> x<-rep(FALSE,20); x[c(4,10,15)]<-TRUE
> x
[1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
[13] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE
> x[outer(which(x),-1:1,"+")]<-T
> x
[1] FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
[13] FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
> x<-rep(FALSE,20); x[c(4,10,15)]<-TRUE
> x[outer(which(x),-2:2,"+")]<-T
> x
[1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
[13]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE
# now we definie
> expand.true<-function(x,span=1){
 m<-floor(span/2)
 ind<-outer(which(x),(-m):m,"+")
 ind<-ind[ind>0 & ind <= length(x)]
 x[ind]<-TRUE
 x
}
> x<-rep(FALSE,20); x[c(4,10,19)]<-TRUE
> expand.true(x,span=5)
[1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
[13] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE


Peter Wolf

Petr Pikal wrote:

Dear all

In automatic dropout evaluation function I construct an index (pointer), which 
will be TRUE at "unusual" values. Then I need to expand these TRUE values a 
little bit forward and backward.

Example:

having span=5, from vector

idx<-rep(F,10)
idx[4]<-T
 

idx
   

[1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE 
FALSE

I need

 

idx
   

[1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE 
FALSE

I was using embed() for this task (myfun1):

idx <- rep(F,20)
idx[c(4,11,13)] <- T
 

idx
   

[1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE 
FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE 
FALSE

iii <- myfun1(idx)

 

iii
   

[1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  
TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE 
FALSE

It is close to what I want, but it is slow and when idx vector is long enough it 
goes short of memory. Then I tried to accomplish it with rle() and some fiddling 
with $values and $lengths (myfun2), which works as long as the true values are 
completely separated.

idx <- rep(F,20)
idx[c(4,12)] <- T
 

idx
   

[1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE 
FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE 
FALSE

iii <- myfun2(idx)
 

iii
   

[1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE  
TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE 
FALSE
	
But when using previous idx

idx <- rep(F,20)
idx[c(4,11,13)] <- T
iii <- myfun2(idx)
Error in rep.default(kody$values, opak) : invalid number of copies in "rep"
Problem is, if TRUE values are closer than span allows. Then some values in 
"opak" for FALSE kody$values are negative, what is not allowed. Setting them 
to zero will expand the length of index vector. Instead number of repetitions of 
neighbour TRUE values should be decreased accordingly. 

I greatly appreciated, if somebody could give me a hint if there is some another 
built in function which can help me or what to do with myfun2 or how to get 
properly expanded index values by some another way.

Sorry for the long post but I was not able to explain my problem and what I have 
done yet to solve it in shorter.

Thank you and best regards.

Petr Pikal



# Here are functions used #



myfun1 <- function(idx,span=5)

{
n <- length(idx)
s <- span%/%2
z <- embed(idx,span)
sumy <- rowSums(z)>0
index <- c(rep(sumy[1],s),sumy,rep(sumy[n-span+1],s))
}


myfun2 <- function(idx,span=5)

{
n <- length(idx)
kody <- rle(idx)
test <- letters[sum(cumsum(c(kody$values[1],idx[n])))+1] is some of true 
values at the end of vector idx?
opak <- kody$values*(span-1)*2-(span-1)+kody$lengths  enlarge number of 
TRUE repetitions according to the span
delka <- length(opak)

 some ifs to ensure the end points will have correct number of repetitions

opak[c(1,delka)] <- opak[c(1,delka)]+span%/%2
if (sum(kody$values)==0) opak <- n
if (opak[1]<0) {opak[2] <- opak[2]+opak[1]; opak[1] <- 0}
if (opak[delka]<0) {opak[delka-1] <- opak[delka-1]+opak[delka]; opak[delka] <- 
0}

switch(test,

a = opak<-opak,
b = opak[delka]<-opak[delka]-(span-1), 
c = opak[1]<-opak[1]-(span-1), 
d = opak[c(1,delka)]<-opak[c(1,delka)]-(span-1),

)

 here should opak contain correct number of repetitions but does not

index<-rep(kody$values,opak)

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

__
[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] Changingvalues in data frame

2004-03-11 Thread Peter Wolf
Frank Gerrit Zoellner wrote:

Hi!

I have a question concerning data frames and changing particular values in it.

I have set up a data frame containing n rows of observations od dimension m, so in each row there is a vector of size m. Now I want to introduce a cut off to tha data. Therfore I caluclated the mean and variance within each column using apply:

me<-apply(daten[1:72],2,mean)
st<-apply(daten[1:72],2,var) 
Now I want use the mean and the var to form a cut off value, and apply it to each row of the data frame.

I tried the following

cutoff<-function(x){
 if(x>me+2*st){
   x<-me+2*st
 }
   }
cutd<-apply(daten[1:72],1,cutoff)

but I have to supply somehow the column index to me and st.
Any Ideas ?
Thanks,
Frank
 

what about:

x<-as.data.frame(matrix(rnorm(100),20,5))
apply(x,2,function(x){limit<-mean(x)+1*sqrt(var(x)); 
ifelse(x>limit,1000*limit,x)})

or

apply(x,2,function(x){limit<-mean(x)+2*sqrt(var(x)); 
ifelse(x>limit,limit,x)})



Peter

__
[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] locator(n=0)

2004-02-27 Thread Peter Wolf
locator(n=1) returns the coordinates of the position of the mouse.
But you have to click the left button of the mouse.
How can I determine the mouse position without any click?
Is it possible to extend locator in a way that  
locator(n=0) outputs the coordinates at once, without any click event?

TclTk allows us to define very nice animations and demonstrations,
see for example:  demo(tkdensity). But sometimes it is much better
to have output and control in one window and to be able to respond
to changes of the cursor position (e.g. to that a bandwidth).
Thanks!

---
Peter Wolf,  [EMAIL PROTECTED]
Department of economics, University of Bielefeld, Germany
__
[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] circular filter

2004-02-25 Thread Peter Wolf
filter.matrix.center  implements Manhattan or L 1 distance.
If you want to define neighbor points
by Euklidean distances (L 2) use filter.matrix.center(p=2):
filter.matrix.center.p <- function(n=9,size=5,p=2){
  x<-matrix(1,n,n)
  center<-(n+1)/2
  (abs(row(x)-center)^p+abs(col(x)-center)^p)^(1/p) < size
}
example:

> 0+filter.matrix.center.p(9,4.1)
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,]000010000
[2,]001111100
[3,]011111110
[4,]011111110
[5,]111111111
[6,]011111110
[7,]011111110
[8,]001111100
[9,]0000100    0    0
Peter Wolf



------

Peter Wolf wrote:

try:

filter.matrix.center<-function(n=9,size=5){
 x<-matrix(1,n,n)
 center<-(n+1)/2
 (abs(row(x)-center)+abs(col(x)-center)) < size
}
filter.matrix.center()
some tests:

> 0+filter.matrix.center(5,2)
[,1] [,2] [,3] [,4] [,5]
[1,]00000
[2,]00100
[3,]01110
[4,]00100
[5,]00000
> 0+filter.matrix.center()
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,]000010000
[2,]000111000
[3,]001111100
[4,]011111110
[5,]111111111
[6,]011111110
[7,]001111100
[8,]000111000
[9,]0000    10000
Peter Wolf

 

Christof Bigler wrote:
I try to find a circular filter that I can export to be used in a 
spatial software.
Assuming, we have a matrix, representing 9x9 regularly spaced points  
with the center point 'filter[5, 5]'. In this example, I want to find 
a function that weighs all neighbor points within a distance of d=4 
units with 1:

> filter <- matrix(0, 9, 9)
> filter <- function() ...
> filter
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,]000010000
[2,]001111100
[3,]011111110
[4,]011111110
[5,]111111111
[6,]011111110
[7,]011111110
[8,]001111100
[9,]000010000
Finally, I want to use a larger matrix, e.g. with 61x61 points. Is 
there a simple function around that I could use to this end?

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

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

2004-02-24 Thread Peter Wolf
try:

filter.matrix.center<-function(n=9,size=5){
 x<-matrix(1,n,n)
 center<-(n+1)/2
 (abs(row(x)-center)+abs(col(x)-center)) < size
}
filter.matrix.center()
some tests:

> 0+filter.matrix.center(5,2)
[,1] [,2] [,3] [,4] [,5]
[1,]00000
[2,]00100
[3,]01110
[4,]00100
[5,]00000
> 0+filter.matrix.center()
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,]000010000
[2,]000111000
[3,]001111100
[4,]011111110
[5,]111111111
[6,]011111110
[7,]001111100
[8,]000111000
[9,]0000100    00
Peter Wolf



Christof Bigler wrote:
I try to find a circular filter that I can export to be used in a 
spatial software.
Assuming, we have a matrix, representing 9x9 regularly spaced points  
with the center point 'filter[5, 5]'. In this example, I want to find a 
function that weighs all neighbor points within a distance of d=4 units 
with 1:

> filter <- matrix(0, 9, 9)
> filter <- function() ...
> filter
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,]000010000
[2,]001111100
[3,]011111110
[4,]011111110
[5,]111111111
[6,]011111110
[7,]011111110
[8,]001111100
[9,]000010000
Finally, I want to use a larger matrix, e.g. with 61x61 points. Is there 
a simple function around that I could use to this end?

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

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


Re: [R] How to repeat a procedure

2004-02-18 Thread Peter Wolf
Haiyan Chen wrote:

Hello,

1. After I generate a 100x50 matrix by x3<-matrix(0,100,50);for (i in
1:100) {x1<-rpois(50, mu[i]);x2<-x1; x2[runif(50)<.01]<-0; x3[i,]<-x2},
2. I want to calculate means and sample variances of each row and create a
new matrix 100x2;
Try:

mean.var<-function(n=10, m=5){
mu<-(1:n)^2
x<-matrix(rpois(n*m,mu),n,m)
stat<-t(apply(x,1,function(x)c(mean(x),var(x
}
to set some elements of x to zero you can add an additional line in mean.var

3. I then want to repeat above procedure 500 times so that eventually I
will have 500 100x2 matrices.
n<-100; m<-50
n.comp<-500
for(i in 1:n.comp) 
eval(parse(text=paste("result",i,"<-mean.var(n,m)",sep="")))

Peter

Would someone mind helping me to code 2 & 3?

Thanks ahead of time.

Heyen

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

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


Re: [R] (no subject) -- integer to binary

2004-02-05 Thread Peter Wolf
[EMAIL PROTECTED] wrote:

Hello,
Splus contains the function intbin(x,l).
This function allows to make a conversion from an integer x to a binary of 
length l.

for example

intbin(3,2) returns 11

intbin(3,3) returns 011

Do you know how to do it in R ?

Thank you meriema

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

you can use the following function

encode <- function(number, base) {
  # simple version of APL-encode / APL-representation "T", pw 10/02
  # "encode" converts the numbers "number" using the radix vector "base"
  n.base <- length(base); result <- matrix(0, length(base), length(number))
  for(i in n.base:1){
result[i,] <- if(base[i]>0) number %% base[i] else number
number <- ifelse(rep(base[i]>0,length(number)),
 floor(number/base[i]), 0)
  }
  return( if(length(number)==1) result[,1] else result )
}
paste(encode(c(13), c(2,2, 2, 2, 2)),collapse="")
[1] "01101"
encode(c(13), c(2,2, 2, 2, 2))
[1] 0 1 1 0 1
See also:

http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/decodeencode/decodeencode.rev

Peter

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


Re: [R] R: plotting multiple functions

2004-02-03 Thread Peter Wolf
allan clark wrote:

Hi all

Another simple question.

I would like to plot three graphs one the same plot with different
colours. Say red, blue and black. Here are the functions.
r1<-1+5*cos(2*pi*seq(1:100)/20)+rnorm(100)
r2<-1+7*sin(2*pi*seq(1:100)/20)+rnorm(100)
r3<-1+7*sin(2*pi*seq(1:100)/20)+5*cos(2*pi*seq(1:100)/20)+rnorm(100)
Regards
Allan
Try:

r1<-1+5*cos(2*pi*seq(1:100)/20)+rnorm(100)
r2<-1+7*sin(2*pi*seq(1:100)/20)+rnorm(100)
r3<-1+7*sin(2*pi*seq(1:100)/20)+5*cos(2*pi*seq(1:100)/20)+rnorm(100)
x <- 1:100
y.min<-min(r1,r2,r3)
y.max<-max(r1,r2,r3)
plot(x,type="n",main="3 graphs", xlab="x",ylab="",ylim=c(y.min,y.max))
lines(x,r1,col="red")
lines(x,r2,col="blue")
lines(x,r3,col="black")
vp<-par()$usr
legend(vp[1]+0.85*(vp[2]-vp[1]),
 vp[3]+0.9*(vp[4]-vp[3]),
 legend=c("graph1","graph2","graph3"), 
 col=c("red","blue","black"),
 lty=rep(1,3),
 bty="n")

Peter

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


Re: [R] How to generate a report with graphics and tables?

2004-01-29 Thread Peter Wolf
Liaw, Andy wrote:

If you don't mind pdf report generated from LaTeX, Sweave would probably
work nicely for you.  See the two articles on it in R News, which you can
find on the R web site.
One other possibility is to use the R2HTML package (and maybe the xtable
package, too) to write the `report' in HTML.
HTH,
Andy
 

From: Olaf Bürger

Hello R-Users,

I have some data sets which change on a daily bases. So far I have 
imported  these sets into R, done all my evaluations resulting in a 
couple of plots, charts and tables of numbers which I copy&pasted via 
clipboard into Powerpoint.
The procedure is always the same and I wonder, whether there is no 
easier way for doing so. Is there some type of "report generator" 
available or some HowTo on this.

Can anybody give me a hint on where to look for?

Regards,

Olaf Bürger
   

A third way is to use the R function ff:

Step 1: define a raw latex-report with R expressions (e.g. report.tex)
Step 2: modify some expressions in the raw report according the local 
situation (data sets, etc.)
Step 3: start R and evaluate ff("report.tex")
Step 4: latex report
Step 5: repeat 2-4 for the different data sets

Here is the link to the rd file:

See: 
http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/formfill/ff.html
or http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/formfill/ff.rd

Peter Wolf

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


Re: [R] subset select within a function

2004-01-21 Thread Peter Wolf
juli g. pausas wrote:

Dear all,
I'd like to subset a df within a function, and use select for choosing 
the variable. Something like (simplified example):

mydf <- data.frame(a= 0:9, b= 10:19)

ttt <- function(vv) {
 tmpdf <- subset(mydf, select= vv)
 mean(tmpdf$vv)
}
ttt(mydf$b)

But this is not the correct way. Any help?
Thanks in advance
Juli

__
[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
are you looking for something like:

mydf <- data.frame(a= 0:9, b= 10:19)
ttt <- function(vv) {
tmpdf <- subset(mydf, select= vv)
lapply(tmpdf,mean)
}
ttt("b") $b
[1] 14.5
> ttt(c("a","b"))
$a
[1] 4.5
$b
[1] 14.5
??

Peter

__
[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] 3-dimensional looping Q.

2004-01-08 Thread Peter Wolf
You can compute cor by hand without loops but the code is not much 
faster (dim(slp)[1]==3):

<<*>>=
set.seed(13)
n<-3
y<-1:n
slp<-array(rnorm(n*73*144),c(3,73,144))
n.1<-length(y)-1
print(system.time({
rData <- array(0,c(73,144))   # array to store results
  for (i in 1:73) {
   for (j in 1:144) {
 rData[i,j] <- cor(slp[,i,j],y)
   }
   }
}))
print(system.time({
n.1<-length(y)-1
mean.slp<-apply(slp,c(2,3),mean)
mean.y<-mean(y); sy<-var(y)^0.5
sqslp<-apply(slp*slp,c(2,3),sum)/n.1-mean.slp^2*n/n.1
sslpy<-apply(slp*y,c(2,3),sum)/n.1-mean.slp*mean.y*n/n.1
rslpy<-sslpy/(sqslp^0.5*sy)
}))
print(all(round(100*rslpy)==round(100*rData)))

@
output-start
[1] 1.49 0.00 1.49 0.00 0.00
[1] 0.92 0.00 0.92 0.00 0.00
[1] TRUE
output-end
Peter Wolf

Uwe Ligges wrote:

Maurice McHugh wrote:

Hello everyone-

I have a 3-d array with the 1st dimension being monthly mean data that
I would like to correlate with some time series index, for example, 
and save the coefficients in an array.

The code I am currently running is

   rData <- array(0,c(73,144))   # array to store results
   for (i in 1:73) {
for (j in 1:144) {
  rData[i,j] <- cor(slp[,i,j],y)
}
}
Rather than running this analysis embedded with two outer loops, 
are =
there any more efficient ways of doing this?
Many thanks!


Don't know whether it's more efficient:
You can try to apply() the function rcorr() in package "Hmisc" to your 
problem...

Uwe Ligges




   
Maurice

Maurice McHugh
Department of Geography and Anthropology
Louisiana State University
Baton Rouge, LA
[[alternative HTML version deleted]]
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html


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


Re: [R] assign

2004-01-07 Thread Peter Wolf
Perez Martin, Agustin wrote:

DeaR useRs:

I would like to assign a values in an object using a loop 'for'.
This is a reduce example of my problem, my real problem is a few
complicated:
for (j in 1:10) {
x.j<-rnorm(100)
}
I want to create 10 objects as "x.1, x.2, ... , x.9, x.10" with values in
it.
I used the "assign" function but nothing happens.
Thank you very much
__
[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
 

Use eval or assign:

> for(j in 1:10) eval(parse(text=paste("x",j,"<-",j,sep="")))
> x1
[1] 1
> x8
[1] 8
> for(j in 1:10) eval(parse(text=paste("x",j,"<-rnorm(10)",sep="")))
> x1
[1]  0.49045324  0.44842510 -1.18015351 -0.04325187 -0.75345939 -0.99181309
[7]  0.62517301 -0.68466635  0.33383560 -0.62189500
> x2
[1] -0.4344948  2.0276137  1.2783173  1.1170551  0.3546490 -0.0748969
[7] -0.8817247 -1.4649175 -1.5461995 -0.6575016
> for(j in 1:10) assign(paste("y",j,sep=""),rnorm(10))
> y1
[1] 1.7255925 0.4993323 1.8846513 0.2058971 0.2284036  -3.1971553
[7]  -0.2629365 0.2724788  -0.9911388  -0.6341857
> y2
[1] 0.11301503  -1.28497666 0.40670853 0.08479014 1.05818411  -1.10843908
[7] 1.30441911  -0.49050833  -1.21438645 0.03923849
ls()
[1] "j"   "x1"  "x10" "x2"  "x3"  "x4"  "x5"  "x6"  "x7"  "x8"  "x9"  "y1"
[13] "y10" "y2"  "y3"  "y4"  "y5"  "y6"  "y7"  "y8"  "y9"
pw

__
[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] for loop over dataframe without indices

2003-12-19 Thread Peter Wolf
Try:

> data(iris); df<-as.data.frame(t(iris[1:3,]))
> for(i in df) print(i)
[1] 5.13.51.40.2setosa
Levels: 0.2 1.4 3.5 5.1 setosa
[1] 4.93.01.40.2setosa
Levels: 0.2 1.4 3.0 4.9 setosa
[1] 4.73.21.30.2setosa
Levels: 0.2 1.3 3.2 4.7 setosa
... however, not very nice

Peter Wolf

Gabor Grothendieck wrote:

Based on an off list email conversation, I had I am concerned that
my original email was not sufficiently clear.
Recall that I wanted to use a for loop to iterate over the rows of 
a dataframe without using indices.   Its easy to do this over
the columns (for(v in df) ...) but not for rows.

What I wanted to do is might be something like this. 
Define a function, rows, which takes a dataframe, df, as input 
and converts it to the structure: 
list(df[1,], df[2,], ..., df[n,]) where there are n rows:

rows <- function( df ) { 
 ll <- NULL
 for( i in 1:nrow(df) ) 
  ll <- append( ll, list(df[i,]) )
 ll 
}

This allows us to iterate over the rows of df without indices like this:

data( iris )
df <- iris[1:3,] # use 1st 3 rows of iris data set as df
for( v in rows(df) ) print(v)
Of course, this involves iterating over the rows of df twice --
once within rows() and once in the for loop. Perhaps this is
the price one must pay for being able to eliminate index 
computations from a for loop or is it? Have I answered my 
own question or is there a better way to use a for loop 
over the rows of a dataframe without indices?

--- 
Date: Thu, 18 Dec 2003 19:20:04 -0500 
From: Gabor Grothendieck <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]> 
Subject: for loop over dataframe without indices 



One can perform a for loop without indices over the columns
of a dataframe like this:
for( v in df ) ... some statements involving v ...

Is there some way to do this for rows other than using indices:

for( i in 1:nrow(df) ) ... some statements involving df[i,] ...

If the dataframe had only numeric entries I could transpose it
and then do it over columns but what about the general case?
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 

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


Re: [R] `bivariate apply'

2003-12-16 Thread Peter Wolf
Vito Muggeo wrote:

dear all,

Given a matrix A, say, I would like to apply a bivariate function to each
combination of its colums. That is if
myfun<-function(x,y)cor(x,y) #computes simple correlation of two vectors x
and y
then the results should be something similar to cor(A).

I tried with mapply, outer,...but without success

Can anybody help me?

many thanks in advance,
vito
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 

what about

myfun<-function(x,fun=cor){
cl<-matrix(1:ncol(x),ncol(x),ncol(x))
cl<-cbind(as.vector(cl),as.vector(t(cl)))
res<-apply(cl,1,function(xx)fun(x[,xx[1]],x[,xx[2]]))
matrix(res,ncol(x),ncol(x))
}
Peter Wolf

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


Re: [R] Flury faces.

2003-12-15 Thread Peter Wolf
Eryk Wolski wrote:

How to plot if possible flury faces in R?
/Eryk
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 

Some days ago I was looking for a function to represent multivariate data by
faces, too.  For no "faces" function could be found I constructed my own 
one.
Here is the result:

Rd-file:
http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/faces/faces.Rd
Definition: 
http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/faces/faces.sch
Documentation:
http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/faces/faces.pdf
Some random faces:   
http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/faces/p20618291De3NA.jpg

Peter Wolf

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


Re: [R] GUI's for R

2003-12-05 Thread Peter Wolf
[EMAIL PROTECTED] wrote:

Hello,

...

All I said so far has little to do with the title of this email.  I am
getting to it.  While I am pretty happy with a CLI I was asked to evaluate
a few statistical packages to be used by casual users in my group.  One of
the main requirements is ease of use, hence the GUI, furthermore, it will
be a lot easier for me to support them in their analyses if we use the same
software.
 

One idea to archive easy use is to construct an editor from which you 
can start
R-commands. If you have saved frequently used R-expressions in a text file
you can load this file into such an editor,  locate the correct formula 
and eval it.
For this task I am developing an editor that uses the tcltk package of 
R: rwined().

Here is a screen shot:

  http://www.wiwi.uni-bielefeld.de/~wolf/software/revweb/rwinedwin.jpg

For experimentation you can download the code (window and linux)  from

  http://www.wiwi.uni-bielefeld.de/~wolf/software/revweb/rtrevive.exe

after installation the package, you have to type:

> library(rtrevive)
> rwined()
Peter Wolf

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


Re: [R] convert data

2003-12-05 Thread Peter Wolf
> y  <- c( "OLDa", "ALL",  "OLDc", "OLDa", "OLDb", "NEW", "OLDb", 
"OLDa", "ALL","...")
> el <- c("OLDa", "OLDb", "OLDc", "NEW", "ALL")
> match(y,el)
[1]  1  5  3  1  2  4  2  1  5 NA

Peter Wolf

---

Peter Dalgaard wrote:

Muhammad Subianto <[EMAIL PROTECTED]> writes:

 

Dear R-helper,
I have a data set like:
OLDa
ALL
OLDc
OLDa
OLDb
NEW
OLDb
OLDa
ALL
. . .
ALL
OLDc
NEW
I want to convert that data as OLDa=1, OLDb=2, OLDc=3, NEW=4 and ALL=5
or the result like:
1
5
3
1
2
4
2
1
5
. . .
5
3
4
How can I do it. Thanks you for your help.
   



I'd do it like this:

 

x <- scan(what="")
   

1: OLDa
2: ALL
3: OLDc
4: OLDa
5: OLDb
6: NEW
7: OLDb
8: OLDa
9: ALL
10:
Read 9 items
 

f <- factor(x,levels=c("OLDa", "OLDb", "OLDc", "NEW", "ALL") )
as.integer(f)
   

[1] 1 5 3 1 2 4 2 1 5

 

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


Re: [R] report generator a la epiinfo

2003-10-21 Thread Peter Wolf
Lucas Gonzalez Santa Cruz wrote:

Hi

I'd like to use R in epidemiology and disease surveillance.

In EpiInfo you can have a script (.pgm) which calls a predefined report
(.rpt), where a table is calculated and values picked from that table
and placed where the author of the report wants them, with text around
those values. (Please see example below.)
I've looked at manuals, faq, mail-search and google. The closest is an
"R Report Generator" email that looked as if it wasn't followed after a
couple of years.
##The script might have something like this:
read.epiinfo("oswego.rec")
report("oswego.rpt", output="oswego.txt")
##The predefined report might have this:
#{ill}
Exactly {"YES"} people fell ill, and {"NO"} people didn't.
We don't know about the remaining [({}-{"YES"}-{"NO"})*100/{}] percent.
#{icecream ill}
We are specifically interested in the number of people who chose vanilla
and didn't fall ill (all {"VANILLA", "YES"} of them).
Is there anyway to do this with R? Any direction I should look into?

Thanks in advance.

Lucas

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

One way is to use Sweave, another one is given by my R function ff.
ff allows you to substitute expressions by evaluated results in a raw 
report.

See: 
http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/formfill/ff.html
or http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/formfill/ff.rd

Peter Wolf

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


Re: [R] BEGINNER: please help me to write my VERY simple function

2003-10-21 Thread Peter Wolf
Michele Grassi wrote:

Hi.
1)I have two variables: call a<-c(e.g.0,3,6,7...)
  b<-c(e.g.6,8,3,4...)
I want to create a third vector z wich contain the 
pairs values z<-c(0,6,3,8,6,3,7,4and so on for each 
pairs (a,b)).
There is a specific function?
How can i write my own function?

2)When i try to write a function and then i save it 
like "function.R" file, i try to retrieve it with 
source comand. As result i obtain an error 
message "error in parse: sintax error on line...". I 
apply deparse() and i see an incorrect parsing: how 
avoid unwanted parsing?
Thanks.
Michele.

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

1) a simple solution to the problem:
define (for example):
gen.pairs <- function(x,y){
 z<-as.vector(rbind(x,y))
 z
}
   try:
 >   x<-1:10
 >   y<-11:20
 >  gen.pairs(x,y)
[1]  1 11  2 12  3 13  4 14  5 15  6 16  7 17  8 18  9 19 10 20
2) a) you can write the definition to a file and then use  source this file.
 If the file name is   myfun.R  
 > source("myfun.R")
  will work. But only if there are no errors in the definition
b) you can type in the code of the definition after the R prompt ">"
c) you can type in :
 > gen.pairs <- function(x,y) { z }
 and complete the definition by using edit:
 > edit(gen.pairs)
 However, syntax errors are not allowed!   

Peter

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


Re: [R] extracting columns with NA's

2003-09-19 Thread Peter Wolf
antonio rodriguez wrote:

Hi All,

How do I can delete from a matrix (or array) only those columns which have
all their values set to NA?
Cheers

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

Try:

> x<-matrix(1:16,4,4)
> x[col(x)>=row(x)]<-NA
> x[,! apply(x,2,function(x) all(is.na(x))) ]
[,1] [,2] [,3]
[1,]   NA   NA   NA
[2,]2   NA   NA
[3,]37   NA
[4,]4    8   12
Peter Wolf

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


Re: [R] Save object R with tkgetSaveFile

2003-09-19 Thread Peter Wolf
[EMAIL PROTECTED] wrote:

HI, my question is about the function tkgetSavefile not save any file, for 
example the next script run OK but
not save the file who i like to save, how i cant to save and object R with 
tkgetSaveFile, how i use the
function save(objet, file="foo.R") with tkgetSaveFile ¿What is the error?. 
I'm work with R 1.7.1

library(tcltk)
x<-1
filetypes <- list("{Texto {.txt}} {Word {.doc}} {Pdf {.pdf}} {Postscript 
{.ps}} {fuente C{.C}} {Eps {.eps}} {Latex {.tex}} {Todos 
*}") 
fileD <- tkgetSaveFile
(filetypes=filetypes,initialdir="c:\\temp",defaultextension=".txt")
save(x,file="foo.R") #how i cant merge tkgetSaveFile with function "save" 
for to save the object "x"?
thanks Ruben

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

Try:

x<-1:3
a<-tkgetSaveFile()
if(0
Peter Wolf

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


Re: [R] Convert decimal to binary data

2003-09-15 Thread Peter Wolf
Paul Delmar wrote:

Hi,

I would like to convert a decimal into a binary number, for instance :
2->(1,0)
Any one knows how to do that ?

Thanks a lot 

paul
 

see chcode or encode that are defined in:

http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/decodeencode/decodeencode.rev

peter

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


Re: [R] subscripts in lists

2003-08-14 Thread Peter Wolf
What about ...

> unlist(lis)[which(unlist(lis)=="next")+1]
[1] "want1" "want2"
... to avoid the loop in sapply?

Richard A. O'Keefe wrote:

Chris Knight <[EMAIL PROTECTED]> has

lis<-list(c("a","b","next","want1","c"),c("d", "next", "want2", "a"))

and wants c("want1","want2")
Step 1:
   inx <- sapply(lis, function(x) which(x == "next")) + 1
==> 4 3
Step 2:
   sapply(1:length(lis), function(i) lis[[i]][inx[i]])
==> "want1" "want2"
Think about this for a bit and restructure it:

   sapply(1:length(lis), function (i) {v <- lis[[i]]; v[which(v=="next")+1]})

Wrap it up:

   after <- function(lis, what="next") {
sapply(1:length(lis), function (i) {
v <- lis[[i]]
v[which(v == what)+1]
})
   }
Of course, from my point of view, a call to sapply() *is* a loop, just
packaged slightly differently.  I think this is reasonably clear.

Peter Wolf
Department of economics
University of Bielefeld
[EMAIL PROTECTED]
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] reverse array indexing

2003-08-03 Thread Peter Wolf
Richard A. O'Keefe wrote:

Jerome Asselin <[EMAIL PROTECTED]> suggests this:
arr <- array(rnorm(27),c(3,3,3))
dimarr <- dim(arr)
tmparr <- array(1:prod(dimarr),dimarr)
sapply(c(3),function(x,tmparr) which(tmparr==x,T),tmparr=tmparr)
sapply(c(3,17,13,5),function(x,tmparr) which(tmparr==x,T),tmparr=tmparr)

Of course, in R we can simplify the last two lines to
   sapply(<>, function(x) which(tmparr==x,T))
However, wearing my "computer scientist" hat, I have to wonder about costs.
This is basically the equivalent of the APL "decode" operator.
Let's define

   index.decode <- function (index, array) {
dimarr <- dim(arr)
tmparr <- array(1:prod(dimarr), dimarr)
sapply(index, function(x) which(tmparr == x, T))
   }
The result is a matrix with C=length(index) columns
and R=length(dim(array)) rows.  ...
 

I think you mean the APL encode operator?

> index<-1:8
> encode(index-1,c(2,2,2))+1
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]11112222
[2,]11221122
[3,]1212121    2
download code of encode from:  
http://www.wiwi.uni-bielefeld.de/~wolf/software/R-wtools/decodeencode.rev

Peter Wolf

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


Re: [R] Stem and leaf display?

2003-07-17 Thread Peter Wolf
Some weeks ago I wrote a function to  construct a stem-and-leaf-display
because we want to have some more parameters to control the result.
D.Trenkler remind me of
/Velleman/Hoaglin: ABC of EDA, page 15: "It is easy to construct a 
Stem-and-Leaf-Display by hand...
It is not nearly as easy to write a general computer program to produce 
Stem-and-Leaf-Displays./"

so the programming was a great challange also.

Here is the link to the code:

  http://www.wiwi.uni-bielefeld.de/~wolf/software/mystem/ms.sch

German documentation:

  http://www.wiwi.uni-bielefeld.de/~wolf/software/mystem/ms.ps
  http://www.wiwi.uni-bielefeld.de/~wolf/software/mystem/ms.html
Syntax of stem.leaf

##

#Description:#
#   stem.leaf  produces a stem-and-leaf-display of a data set#
##
#Usage:  #
#   stem.leaf(data)  #
#   stem.leaf(data,unit=100,m=5,Min=50,Max=1000,rule.line="Dixon"#
##
#Arguments:  #
#   data:  vector of input data  #
#   unit:  unit of leafs in:  { ...,100,10,1,.1,.01,... }#
#   m: 1, 2 or 5 -- 10/m=number of possible leaf digits  #
#   Min:   minimum of stem   #
#   Max:   maximum of stem   #
#   rule.line: = "Dixon"=> number of lines <- 10*log(n,10)   #
#  = "Velleman" => number of lines <- 2*sqrt(n)  #
#  = "Sturges"  => number of lines <- 1 + log(n,2)   #
#   style: = "UREDA"=> UREDA like stem ( m = 2, 5 )  #
#    #
#Author: #
#   Peter Wolf 05/2003   #
######
Hope it helps

Peter Wolf

Richard A. O'Keefe wrote:

I would like to do some fairly basic stem-and-leaf displays in R.
I am aware (I might even say painfully aware) of stem(base) and
have tried it.  That's why I'm hoping someone has a usable stem-
and-leaf display for R so that I don't have to write my own.
r-project.org > Search > R Site Search > "stem and leaf display"
finds nothing.
I also tried the mail archive search, but couldn't figure out how
to search the bodies of the messages.
For the record, there are some less important things that I would
like to have (like depths and outlier lines), and it is a pity that
the "atom" argument of stem() is effectively undocumented (it's a
tolerance, fine, but what _of_ and how used?), but I'd put up with
stem() the way it is if only it didn't do things like displaying
5.67 and 5.78 as
   56 | 78
which makes it effectively unusable.  What good is a stem and leaf
plot where you can't recover the leading digits of the numbers correctly?
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 

---
Peter Wolf,   Department of Economics and Business Administration,
University of Bielefeld
[EMAIL PROTECTED], 
http://www.wiwi.uni-bielefeld.de/~wolf/wolf.html

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


Re: [R] How can I do a spinning plot in R?

2003-06-23 Thread Peter Wolf
Some days ago I wrote a function for rotating
a cloud of points. To control the rotation a simple
Tcl/Tk-widget is used. Here you can find the
R code:
http://www.wiwi.uni-bielefeld.de/~wolf/software/spin3R/spin3R.sch

Peter Wolf, [EMAIL PROTECTED]

Richard A. O'Keefe wrote:

I have found XLispStat's spinning plots illuminating.
I'd like to do the same thing in R.
A dozen or so probes with help, help.search, apropos
haven't turned up anything, and I've even resorted to
grepping through the entire R source distribution
looking for 'spin.*plot', to no avail.
Either the feature is called something else in R (what?),
or it's in some other package in CRAN (which?),
or it's not yet available (I hope not, because I am very
far from being skilled enough in R programming to do it
myself).
Help?

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

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


Re:[R] Combining the components of a character vector

2003-04-04 Thread Peter Wolf
John Miyamoto wrote:

> Suppose I have a character vector.
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string:  "Bob loves Sally" .
> paste(x) yields:
> paste(x)
> [1] "Bob"   "loves" "Sally"

> 

Try:

> paste(x,collapse=" ")

and

> help(paste)

--Peter

---
 Peter Wolf,   Statistik/Informatik,   Fak.f.Wiwi,   Uni Bielefeld
 [EMAIL PROTECTED], http://www.wiwi.uni-bielefeld.de/~wolf/wolf.html
---



[[alternate HTML version deleted]]

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


[R] Is there any good tool for Hanling Data on the Net

2003-03-22 Thread wolf
Hello,

Is there any good windows-tool in the internet(shareware or Freeware) for
hanling and manipulating data. Currently I'm using excel, but there are
plenty of limetations on this program e.g. im working with svm's and I need
a lot more colums for my data. Because of this the handling of my data is
very time intensive and I'm now looking for a simple program witch can
handle my data (read data, ad data, transpond data etc.)

Thanx Andreas

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


[R] Savitzky-Golay Derivative and Smoothing

2003-03-21 Thread wolf
Hello,

Is there any libary with the algorithms of the Savitzky-Golay Derivative
and Smoothing. I found the calculation on the web site
"www.galactic.com/algorithms/" but I'm to new in R so I cant programm it in
R.
Can someone help me?

Thanx
Andreas

micro-biolytics GmbH
Andreas Wolf

Georges-Köhler-Allee 102
D - 79110 Freiburg
Fon: +49-761-2037524
Fax: +49-761-2037522

eMail: [EMAIL PROTECTED]
Web:   http://www.micro-biolytics.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CONFIDENTIALITY NOTICE

This e-mail is intended only for the addressee named above and may contain
confidential information. If you are not the intended recipient, please let
us know immediately by return e-mail and then delete this e-mail, without
disclosing or copying the contents.

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


Re: [R] dataframes (The message that once had a suspicious header)

2003-03-20 Thread Peter Wolf

Ernesto Jardim wrote:

> Hi
>
> I want to combine 2 dataframes (t1 and t2) in order to get a third one
> (t3). The dataframes are below.
>
> In SQL I would do something like:
>
> SELECT t1.f1,t1.f2,t1.f3,t2.f4 FROM t1, t2
> WHERE t1.f1=t2.f1 AND t1.f2=t2.f2
>
> How can I do it with R ?
>
> Thanks
>
> EJ
>
> > t1
>   f1 f2 f3
> 1  A  C E1
> 2  A  D E2
> 3  B  C E3
> 4  B  D E4
> > t2
>   f1 f2 f4
> 1  A  C F1
> 2  A  C F2
> 3  B  C F3
> 4  B  C F4
> 5  A  D F5
> 6  A  D F6
> > t3
>   f1 f2 f3 f4
> 1  A  C E1 F1
> 2  A  C E1 F2
> 3  B  C E3 F3
> 4  B  C E3 F4
> 5  A  D E2 F5
> 6  A  D E2 F6
>
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Try function "merge". For details see: help(merge)

> t1
 [,1] [,2] [,3]
[1,] "A"  "C"  "E1"
[2,] "A"  "D"  "E2"
[3,] "B"  "C"  "E3"
[4,] "B"  "D"  "E4"
> t2
 [,1] [,2] [,3]
[1,] "A"  "C"  "F1"
[2,] "A"  "C"  "F2"
[3,] "B"  "C"  "F3"
[4,] "B"  "C"  "F4"
[5,] "A"  "D"  "F5"
[6,] "A"  "D"  "F6"
> merge(t1,t2,1:2)
  V1 V2 V3.x V3.y
1  A  C   E1   F1
2  A  C   E1   F2
3  A  D   E2   F5
4  A  D   E2   F6
5  B  C   E3   F3
6  B  C   E3   F4

--- Peter Wolf

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


Re: [R] inserting elements in a list

2003-02-18 Thread Peter Wolf
Inserting new values into a vector requires to describe
where to insert the new values. The function "insert.values"
allows you to define the new position(s) by fractional
indices or by a logical vector.

"insert.values" <- function(x,pos.insert,x.insert){
# insert.values inserts x.insert into x at positions defined by
pos.insert
# Arguments:
#   x   input vector
#   x.insertvector of new values to be stored
#   pos.insert  defines the positions of the new values in one of two
ways:
#   a) pos.insert is a vector of fractional numbers of the
same length
#  as x.insert: x.insert[i] will be inserted between
#  x[ floor(pos.insert) ] and x[ ceiling(pos.insert) ]
#   b) pos.insert is of mode logical with length(x) values
FALSE
#  and length(x.insert) values TRUE. Then TRUE values
indicate
#  the position of the new elements and FALSE the values

#  of old ones
#
# Examples:
#   > x<-1:5
#   > insert.values(x, 2.5, 1000)
#   [1]12 1000345
#   > insert.values(x, (1:5)+.2, 1001:1005)
#   [1]1 10012 10023 10034 10045 1005
#   > insert.values(x, .9, )
#   [1] 12345
#   > insert.values(x, c(T,rep(F,5)), 1000)
#   [1] 100012345
#   > insert.values(x, c(rep(F,5),T), 1000)
#   [1]12345 1000
#   > insert.values(x, rbind(rep(F,5),T), 1001:1005)
#   [1]1 10012 10023 10034 10045 1005
# pw 02/2003
  if(is.logical(pos.insert)){
pos.insert <- pos.insert[pos.insert]/length(pos.insert) +
cumsum(!pos.insert)[pos.insert]
  }
  x<-c(x,x.insert)[order(c(seq(x),pos.insert))]
  return(x)
}

Peter Wolf
--
Dr. Agustin Lobo wrote:
> I've searched the doc for insert
> and could not find the way to do the following,
> hope someone can help:
>
> Let's say we have a vector:
> > a
> [1] "1" "2" "3" "5" "6" "3"
>
> and we want to insert a "7" after
> any given "3", i.e., we want vector a
> to become:
>
> [1] "1" "2" "3" "7" "5" "6" "3" "7"

---
 Peter Wolf,   Statistik/Informatik,   Fak.f.Wiwi,   Uni Bielefeld
 [EMAIL PROTECTED], http://www.wiwi.uni-bielefeld.de/~wolf/wolf.html
---



[[alternate HTML version deleted]]

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



[R] Tcl/Tk and mouse

2003-01-20 Thread Peter Wolf

 Within a loop I tried to draw some things in
 dependency on the position of the mouse.
 This works fine with R-1.5.1 but R-1.6.1
 requires to include some delay by
 Sys.sleep(delay)  with  delay>=0.015.
 For smaller values (e.g. 0.0001) the
 top level tcltk-window does not appear
 and so I am not able to control the elements
 to be plotted using the tcltk-widget.

 Question1: How can I force the tcltk-widget
to appear / to get the position
of the mouse within the loop?

 Question2: Why isn't it allowed to use the
locator function with n=0, with
the meaning to output the
coordinates of the mouse?
( Then my problem can be
  solved without Tcl/Tk )

 Here is an example:

# Definition of function a:
#

a<-function(delay=0.015){
  library(tcltk)
  state <-tclVar("relax")
  number<-tclVar("100")
  top   <-tktoplevel()
  show  <-tklabel (top,textvariable=number)
  up<-tkbutton(top,text="up")
  down  <-tkbutton(top,text="down")
  exit  <-tkbutton(top,text="exit",command=function()
tclvalue(state)<-"exit" )
  tkpack(show,up,down,exit)
  tkbind(up,  "",function() tclvalue(state)<-"up" )
  tkbind(up,  "",function() tclvalue(state)<-"relax" )
  tkbind(down,"",function() tclvalue(state)<-"down" )
  tkbind(down,"",function() tclvalue(state)<-"relax" )
  plot(1:400,type="n"); old<-1:2; x<-1; y<-200
  repeat{
Sys.sleep(delay)
choice <- tclvalue(state)
if((x<-x+1)>400) break
if(choice=="exit")break
if(choice=="up"  ) y<-y+1
if(choice=="down") y<-y-1
if(choice=="relax")y<-y
points(old[1],old[2],col="red")
points(x, y, col="black")
tclvalue(number) <- as.character(y)
old<-c(x,y)
  }
  tkdestroy(top)
}
#
###
# a(0.01) is ok, a(0.0001) is not ok by:
#
# version:
# platform hppa2.0-hp-hpux10.20
# arch hppa2.0
# os   hpux10.20
# system   hppa2.0, hpux10.20
# status
# major1
# minor6.1
# year 2002
# month11
# day  01
# language R
##

Peter Wolf

-

H.P. Wolf
University of Bielefeld, Germany
[EMAIL PROTECTED]

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