Re: [R] finding the most frequent row

2004-12-11 Thread Kjetil Brinchmann Halvorsen
bogdan romocea wrote:
Here's something that works. I'm sure there are better solutions (in
particular the paste part - I couldn't figure out how to avoid typing
a[i,1], ..., a[i,10]).
a - matrix(nrow=1000,ncol=10)
for (i in 1:1000)
for (j in 1:10)
a[i,j] - sample(1:0,1)
b - vector(mode=character)
for (i in 1:1000)
	b[i] - paste(a[i,1],a[i,2],a[i,3],a[i,4],a[i,5],
		a[i,6],a[i,7],a[i,8],a[i,9],a[i,10],sep=)
 

Or
b - apply(a, 1, function(x) paste(x, sep=, collapse=))
Kjetil
#the most frequent row
table(b)[table(b) == max(table(b))]
HTH,
b.
-Original Message-
From: Lisa Pappas [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 09, 2004 5:15 PM
To: [EMAIL PROTECTED]
Subject: [R] finding the most frequent row
I am bootstrapping using a function that I have defined.  The
Statistic of the function is an array of 10 numbers.  Therefore if
I use 1000 replications,  the t matrix will have 1000 rows each of
which is a bootstrap replicate of this 10 number array (10 columns). 
Is there any easy way in R to determine which row appears the most
frequently? 

Thanks,
Lisa Pappas
Huntsman Cancer Institute wishes to promote open communication while
protecting confidential and/or privileged information.  If you have
received this message in error, please inform the sender and delete
all copies.
__
[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
 


--
Kjetil Halvorsen.
Peace is the most effective weapon of mass construction.
  --  Mahdi Elmandjra
__
[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] Beginners questions on matplot and legend

2004-12-11 Thread Martin Maechler
 judith == judith baltsar [EMAIL PROTECTED]
 on Sat, 11 Dec 2004 10:35:39 +0100 writes:

judith Dear list members, I have a problem that is probably
judith simple to solve but at the moment I have no clue at
judith all:

judith I have done a simple matplot matplot(x,y,pch=symb,
judith xlab=Axis 1, ylab=Axis 2, main=PCA of plot x
judith trait matrix) x has the X-axis values, y has four
judith columns of y-values and now I want to have a simple
judith legend for the four symbols defined by symb.  Easy
judith probably, but maybe someone can give me a hint.

yes, a hint: 

  Look at the legend() call in the iris example close to the end of

help(matplot).

or try
   par(ask=TRUE)
   example(matplot)

judith Thank you very much   Judith

gern geschehen!
Martin

__
[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] cbind() and factors.

2004-12-11 Thread Frank E Harrell Jr
Gabor Grothendieck wrote:
michael watson (IAH-C michael.watson at bbsrc.ac.uk writes:
: 
: Hi
: 
: I'm seeing some odd behaviour with cbind().  My code is:
: 
:  cat - read.table(cogs_category.txt, sep=\t, header=TRUE,
: quote=NULL, colClasses=character)
:  colnames(cat)
: [1] CodeDescription
:  is.factor(cat$Code)
: [1] FALSE
:  is.factor(cat$Description)
: [1] FALSE
:  is.factor(rainbow(nrow(cat)))
: [1] FALSE
:  cat - cbind(cat,Color=rainbow(nrow(cat)))
:  is.factor(cat$Color)
: [1] TRUE
:  ?cbind
: 
: I read a text file in which has two columns, Code and Description.
: Neither of these are factors.  I want to add a column of colours to the
: data frame using rainbow().  The rainbow function also does not return a
: factor.  However, if I cbind my data frame (which has no factors in it)
: and the results of rainbow() (which is a vector, not a factor), then for
: some reason the new column is a factor...??

Others have already explained the problem and given what is likely
the best solution but here is one other idea, just in case.
You may require a data frame depending on what you want to do but
if you don't then you could alternately use a character matrix
since that won't result in any conversions to factor.
Lets call the data frame from read.table, Cat.df, and our 
matrix, Cat.m.  cat is not wrong but its confusing 
since there is a common R function called cat.  Now we can 
write the following and don't have to worry about factors:

Cat.df - read.table(...)
# create a character matrix and cbind Colors to it
Cat.m - cbind(as.matrix(Cat.df), Color = rainbow(nrow(Cat.df)))
If you do find you need a data frame later you can convert it back
like this:
Cat.df - as.data.frame(Cat.m)
Cat.df[] - Cat.m  # clobber factors with character data
For speed, the mApply function in the Hmisc package (used by the Hmisc 
summarize function) does looping for stratified statistical summaries by 
operating on matrices rather than data frames.   factors are converted 
to numerics, and service routines can save and restore the levels and 
other attributes.  Here is an example from the summarize help file, plus 
related examples:

# To run mApply on a data frame:
m - mApply(asNumericMatrix(x), race, h)
# Here assume h is a function that returns a matrix similar to x
at - subsAttr(x)  # get original attributes and storage modes
matrix2dataFrame(m, at)
# Get stratified weighted means
g - function(y) wtd.mean(y[,1],y[,2])
summarize(cbind(y, wts), llist(sex,race), g, stat.name='y')
mApply(cbind(y,wts), llist(sex,race), g)
# Compare speed of mApply vs. by for computing
d - data.frame(sex=sample(c('female','male'),10,TRUE),
country=sample(letters,10,TRUE),
y1=runif(10), y2=runif(10))
g - function(x) {
  y - c(median(x[,'y1']-x[,'y2']),
 med.sum =median(x[,'y1']+x[,'y2']))
  names(y) - c('med.diff','med.sum')
  y
}
system.time(by(d, llist(sex=d$sex,country=d$country), g))
system.time({
 x - asNumericMatrix(d)
 a - subsAttr(d)
 m - mApply(x, llist(sex=d$sex,country=d$country), g)
})
system.time({
 x - asNumericMatrix(d)
 summarize(x, llist(sex=d$sex, country=d$country), g)
})
--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University
__
[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] finding the most frequent row

2004-12-11 Thread Liaw, Andy
 From: Kjetil Brinchmann Halvorsen
 
 bogdan romocea wrote:
 
 Here's something that works. I'm sure there are better solutions (in
 particular the paste part - I couldn't figure out how to avoid typing
 a[i,1], ..., a[i,10]).
 
 a - matrix(nrow=1000,ncol=10)
 for (i in 1:1000)
  for (j in 1:10)
  a[i,j] - sample(1:0,1)
 
 b - vector(mode=character)
 for (i in 1:1000)
  b[i] - paste(a[i,1],a[i,2],a[i,3],a[i,4],a[i,5],
  a[i,6],a[i,7],a[i,8],a[i,9],a[i,10],sep=)
   
 
 Or
 
 b - apply(a, 1, function(x) paste(x, sep=, collapse=))

Or, as Peter pointed out recently:

  b - apply(a, 1, paste, sep=, collapse=)

Andy
 
 Kjetil
 
 #the most frequent row
 table(b)[table(b) == max(table(b))]
 
 HTH,
 b.
 
 
 -Original Message-
 From: Lisa Pappas [mailto:[EMAIL PROTECTED]
 Sent: Thursday, December 09, 2004 5:15 PM
 To: [EMAIL PROTECTED]
 Subject: [R] finding the most frequent row
 
 
 I am bootstrapping using a function that I have defined.  The
 Statistic of the function is an array of 10 numbers.  Therefore if
 I use 1000 replications,  the t matrix will have 1000 rows each of
 which is a bootstrap replicate of this 10 number array (10 columns). 
 Is there any easy way in R to determine which row appears the most
 frequently? 
 
 Thanks,
 Lisa Pappas
 
 Huntsman Cancer Institute wishes to promote open communication while
 protecting confidential and/or privileged information.  If you have
 received this message in error, please inform the sender and delete
 all copies.
 
 __
 [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
 
 
   
 
 
 
 -- 
 
 
 Kjetil Halvorsen.
 
 Peace is the most effective weapon of mass construction.
--  Mahdi Elmandjra
 
 __
 [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] applying var(base)

2004-12-11 Thread assuncao . senra

Hello,
I have the output of loglin, the parameters of a estimated loglinear models. 
They are in list form. How can I compute the variance of these parameters?

Thanks

__
Sabe quanto gasta com a sua ligação à Internet?
Verifique aqui: http://acesso.portugalmail.pt/contas

__
[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] Parallel computing in Splus?

2004-12-11 Thread Lun Li
Dear All,

Does anyone know if there is any function or package provides parallel computing
in splus?


Thanks in advance.


Lun

__
[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] graphs - saving and multiple

2004-12-11 Thread stephenc
Hi
 
I am doing something like this:
 
hist(maximumPitch, xlab=Maximum Pitch in Hertz)
 
which produces a nice histogram but what do I do to get two or three,
etc on one page?
 
I want to save the resulting file to an eps.  I can find:
 
 
postscript(ex.eps)
 
which I then run something like my  hist above and then 
 
dev.off()
 
but I don't get anything in my eps file!
 
Thanks.
 
Stephen 

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


[R] Paths for Shell Scripts called from R

2004-12-11 Thread Damian Betebenner
Hello list,

I suspect this is more a linux question than an R question, but I'll describe 
my situation in case
anyone here knows of an elegant solution.

I'm using Sweave and R to create thousands of customized reports. Within an R  
loop, I have R create
a table.tex file using the CAT function which, for each iteration, creates a 
unique table.tex file in
a subdirectory of the directory from which the master file is sourced. I have 
written a shell script called
latexall that pdflatexs all the files in a given directory. I want to call 
latexall from within R using the SYSTEM command after I've created all my 
table.tex files. Later, the .pdfs of these tables are read into the
document using the includegraphics command (The reason I'm creating tables this 
way is for
two reasons: 1. xtable and latextable are limited, especially when one is 
producing complicated tables
with \multicolumn headings and \raisebox commands that make the tables look 
nice; and 2. I've found
that precompiling tables and then inputing them into a .tex file using the 
\includegraphics command
takes much of the headache out of table production in LaTeX. In particular, 
tables that are too wide are
easily dealt with by changing the scale factor. Float placement also seems 
easier to me when using
\includegraphics)

My bash shell script uses a standard for loop to loop over all the .tex file in 
a directory

for f in *.tex

The problem that I'm having is that I can't seem to direct latexall to the 
correct subdirectory without placing
latexall in the subdirectory with all the table.tex files and hard coding that 
subdirectory into the the shell 
script before using the SYSTEM command to call latexall.

for f in /home/directory/subdirectory/tables/*.tex  

Does anyone have an idea of how I can pass the appropriate path to my shell 
script from within R?

I hope this makes sense. 

Any help greatly appreciated.

Damian

Damian Betebenner
Educational Research, Measurement  Evaluation
Lynch School of Education
Boston College
Chestnut Hill, MA 02467

(617) 552 4491

__
[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] Paths for Shell Scripts called from R

2004-12-11 Thread Fernando Henrique Ferraz P. da Rosa
Damian Betebenner writes:
 Hello list,
 
 I suspect this is more a linux question than an R question, but I'll describe 
 my situation in case
 anyone here knows of an elegant solution.
 
...
 My bash shell script uses a standard for loop to loop over all the .tex file 
 in a directory
 
 for f in *.tex
 
 The problem that I'm having is that I can't seem to direct latexall to the 
 correct subdirectory without placing
 latexall in the subdirectory with all the table.tex files and hard coding 
 that subdirectory into the the shell 
 script before using the SYSTEM command to call latexall.
 
 for f in /home/directory/subdirectory/tables/*.tex  
 
 Does anyone have an idea of how I can pass the appropriate path to my shell 
 script from within R?
 

You could use the $* argument in your bash script, and then pass
the argument via system(), on the call to the script. Suppose you have

$ cat pdflatexall.sh 
#!/bin/bash

for i in $1/*.tex; do
echo pdflatex $i;
done

In R you could call by using:

system('pdflatexall.sh /tmp')

Works fine here:

$ touch /tmp/bla1.tex /tmp/bla2.tex
$ R
 system('pdflatexall.sh /tmp')
pdflatex /tmp/bla1.tex
pdflatex /tmp/bla2.tex




--
Fernando Henrique Ferraz P. da Rosa
http://www.ime.usp.br/~feferraz

__
[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] Paths for Shell Scripts called from R

2004-12-11 Thread Peter Dalgaard
Damian Betebenner [EMAIL PROTECTED] writes:

 Does anyone have an idea of how I can pass the appropriate path to
 my shell script from within R?

Anything wrong with just setting the PATH variable? E.g.

 Sys.putenv(PATH=paste(Sys.getenv(PATH),/home/bs/pd/scripts,sep=:))
 system(SalesRank)
Sun Dec 12 00:10:55 CET 2004
29605


-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

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


Re: [R] graphs - saving and multiple

2004-12-11 Thread Jim Lemon
stephenc wrote:
 ...
 but I don't get anything in my eps file!

If you mean you get a blank image or nothing when you import the resulting PS 
file, you may need to set onefile=FALSE.

Jim

__
[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] Beginners questions on matplot and legend

2004-12-11 Thread judith . baltsar
Dear list members,
I have a problem that is probably simple to solve but at the moment 
I have no clue at all:

I have done a simple matplot
matplot(x,y,pch=symb, xlab=Axis 1, ylab=Axis 2, main=PCA of 
plot x trait matrix)
x has the X-axis values, y has four columns of y-values and now I 
want to have a simple legend for the four symbols defined by symb. 
Easy probably, but maybe someone can give me a hint.

Thank you very much
Judith

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