Re: [R] sapply, lattice functions

2010-03-20 Thread Sundar Dorai-Raj
You're right. It's necessary for xyplot though to prevent grouping.

On Mar 20, 2010 10:43 AM, Dieter Menne dieter.me...@menne-biomed.de
wrote:



Sundar Dorai-Raj-2 wrote:

 Or perhaps more clearly,

 histogram(~a1 + b1 + c1, data = aa, o...
Why outer=TRUE? Looks same for me without:
Dieter

library(lattice)

aa - data.frame(a1=rnorm(20),b1=rnorm(20,0.8),c1=rnorm(20,0.5))
histogram(~a1 + b1 + c1, data = aa)


--
View this message in context:
http://n4.nabble.com/sapply-lattice-functions-tp1618134p1676043.html
Sent from the R help mailing list archive at Nabble.com.


__
R-help@r-project.org mailing list
https://stat.ethz

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] sapply, lattice functions

2010-03-19 Thread Sundar Dorai-Raj
Or perhaps more clearly,

histogram(~a1 + b1 + c1, data = aa, outer = TRUE)

--sundar

On Fri, Mar 19, 2010 at 3:50 PM, Gabor Grothendieck ggrothendi...@gmail.com
 wrote:

 Try this:

 histogram(~ values | ind, stack(aa))


 On Fri, Mar 19, 2010 at 5:44 PM, Santosh santosh2...@gmail.com wrote:
  Dear R-gurus
 
  aa - data.frame(a1=rnorm(20),b1=rnorm(20,0.8),c1=rnorm(20,0.5))
  sapply(aa,function(x) histogram(x,breaks=NULL))
 
  or px - sapply(aa,function(x) histogram(x,breaks=NULL))
  print(px,split=c(1,1,1,1),more=F)
 
  The above code does not seem to work. am I missing something?
 
  Thanks,
  Santosh
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Source code for the t-distribution

2010-03-09 Thread Sundar Dorai-Raj
Here it is.

https://svn.r-project.org/R/trunk/src/nmath/pt.c

--sundar

On Tue, Mar 9, 2010 at 4:24 AM, Ravi Kulkarni ravi.k...@gmail.com wrote:


 I have tried looking for the source code for the pt() function in

 https://svn.r-project.org/R/trunk/src/library/stats/

 and am unable to find it there. Can someone please tell me where to find
 it?

 Thanks,
  Ravi Kulkarni
 --
 View this message in context:
 http://n4.nabble.com/Source-code-for-the-t-distribution-tp1585875p1585875.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] capturing errors in Sweave

2010-03-02 Thread Sundar Dorai-Raj
Thanks, Berwin. That works just great!

--sundar

On Tue, Mar 2, 2010 at 12:57 AM, Berwin A Turlach
ber...@maths.uwa.edu.auwrote:

 G'day Sundar,

 On Mon, 1 Mar 2010 23:46:55 -0800
 Sundar Dorai-Raj sdorai...@gmail.com wrote:

  Thanks for the input, but I don't want try in the Sweave output. I
  want the output to look just like it does in the console, as if an
  uncaptured error really did occur.

 I don't think that you will get around using try; and you will have
 to work moderately hard to make the output appear as it does on the
 console.  Probably somewhere along the lines:

  Sweave code start ++
 Function-4a=
 MySqrt - function(x) {
  if (missing(x)) {
stop('x' is missing with no default)
  }
  if (!is.numeric(x)) {
stop('x' should only be numeric)
  }
  if (x  0) {
stop('x' should be non-negative)
  }
  return(sqrt(x))
 }
 @

 echo=FALSE=
 tmp - try(MySqrt())
 @
 eval=FALSE=
 MySqrt()
 @
 echo=FALSE=
  cat(tmp[1])
 @

 echo=FALSE=
 tmp - try(MySqrt(a))
 @
 eval=FALSE=
 MySqrt(a)
 @
 echo=FALSE=
  cat(tmp[1])
 @

 echo=FALSE=
 tmp - try(MySqrt(-2))
 @
 eval=FALSE=
 MySqrt(-2)
 @
 echo=FALSE=
  cat(tmp[1])
 @

 =
 MySqrt(4)
 @
 +++ Sweave code end ++

 Now what I would like to know is how to include easily warning messages
 in my Sweave output without having to try whether Jean Lobry's [1] hack
 still works. :)

 HTH.

 Cheers,

Berwin

 [1]
 https://www.stat.math.ethz.ch/pipermail/r-help/2006-December/121975.html

 == Full address 
 Berwin A Turlach  Tel.: +61 (8) 6488 3338 (secr)
 School of Maths and Stats (M019)+61 (8) 6488 3383 (self)
 The University of Western Australia   FAX : +61 (8) 6488 1028
 35 Stirling Highway
 Crawley WA 6009e-mail: ber...@maths.uwa.edu.au
 Australiahttp://www.maths.uwa.edu.au/~berwin


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] capturing errors in Sweave

2010-03-02 Thread Sundar Dorai-Raj
What I ended up using was:

cat(unclass(tmp))

--sundar

On Tue, Mar 2, 2010 at 8:58 AM, Berwin A Turlach ber...@maths.uwa.edu.auwrote:

 G'day Sundar,

 On Tue, 2 Mar 2010 01:03:54 -0800
 Sundar Dorai-Raj sdorai...@gmail.com wrote:

  Thanks, Berwin. That works just great!

 You are welcome.

 I noticed by now that cat(tmp) is sufficient; the tmp[1] in
 cat(tmp[1]) was a left over from earlier attempts to get the output
 to look correct.

 Cheers,

Berwin


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] capturing errors in Sweave

2010-03-01 Thread Sundar Dorai-Raj
Hi,

I'm writing a manual using Sweave and I want to be able to print errors from
bad code. Here's an example:

Function-4a=
MySqrt - function(x) {
  if (missing(x)) {
stop('x' is missing with no default)
  }
  if (!is.numeric(x)) {
stop('x' should only be numeric)
  }
  if (x  0) {
stop('x' should be non-negative)
  }
  return(sqrt(x))
}
MySqrt()
MySqrt(a)
MySqrt(-2)
MySqrt(4)
@

And I would like the output to be:

MySqrt - function(x) {
...
}
 MySqrt()
Error in MySqrt() : 'x' is missing with no default
 MySqrt(a)
Error in MySqrt(a) : 'x' should only be numeric
 MySqrt(-2)
Error in MySqrt(-2) : 'x' should be non-negative
 MySqrt(2)
[1] 1.414214

I.e. I want the Error statements to print in the tex file and not just make
Sweave to bomb.

Thanks,

--sundar

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] capturing errors in Sweave

2010-03-01 Thread Sundar Dorai-Raj
Thanks for the input, but I don't want try in the Sweave output. I want
the output to look just like it does in the console, as if an uncaptured
error really did occur.

--sundar

On Mon, Mar 1, 2010 at 11:42 PM, Sharpie ch...@sharpsteen.net wrote:



 Sundar Dorai-Raj-2 wrote:
 
  Hi,
 
  I'm writing a manual using Sweave and I want to be able to print errors
  from
  bad code. Here's an example:
 
  Function-4a=
  MySqrt - function(x) {
if (missing(x)) {
  stop('x' is missing with no default)
}
if (!is.numeric(x)) {
  stop('x' should only be numeric)
}
if (x  0) {
  stop('x' should be non-negative)
}
return(sqrt(x))
  }
  MySqrt()
  MySqrt(a)
  MySqrt(-2)
  MySqrt(4)
  @
 
  And I would like the output to be:
 
  MySqrt - function(x) {
  ...
  }
  MySqrt()
  Error in MySqrt() : 'x' is missing with no default
  MySqrt(a)
  Error in MySqrt(a) : 'x' should only be numeric
  MySqrt(-2)
  Error in MySqrt(-2) : 'x' should be non-negative
  MySqrt(2)
  [1] 1.414214
 
  I.e. I want the Error statements to print in the tex file and not just
  make
  Sweave to bomb.
 
  Thanks,
 
  --sundar
 

 You can catch errors in R using the try() function:

  foo - try( log(A), silent = TRUE )

  if( class( foo ) == 'try-error' ){

print( unclass( foo ) )

  }

 [1] Error in log(\A\) : Non-numeric argument to mathematical function\n


 There might be a more clever way to override the default error handling
 that
 would save you from wrapping everything in try()-- but this method should
 work.

 Hope it helps!

 -Charlie

 -
 Charlie Sharpsteen
 Undergraduate-- Environmental Resources Engineering
 Humboldt State University
 --
 View this message in context:
 http://n4.nabble.com/capturing-errors-in-Sweave-tp1574642p1574686.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] How do I juxtapose two lattice graphs with common X axes such that the X axes line up?

2010-01-20 Thread Sundar Dorai-Raj
Try googling latticeExtra x.same for some examples. Here's one:

http://www.mail-archive.com/r-help@r-project.org/msg39048.html

On Wed, Jan 20, 2010 at 9:44 AM, George Chen glc...@stanford.edu wrote:

 Hello,

 I would like to juxtapose two lattice graphs with common X axes such that
 the X axes line up.  I am using plot right now but the edges are not neat
 and it would be nice if I could just draw 1 X axis and not both of them.

 Here is my code:



 upper-bwplot(SignalUsed~as.factor(AllNormalHitsNamesCount),data=NmlOverviewArray2,
xlab=,
ylab=Intensity of Individual Antibody Responses,
main=Intensity, Frequency, Distribution,  Quantity of Normal
 Antibody Responses,
box.ratio=1,
panel = function (AllNormalHitsNamesCount,...) {
panel.bwplot(...)
}
)

 lower-barchart(as.vector(table(NmlOverviewArray2$AllNormalHitsNamesCount))

  
 ~as.factor(as.numeric(names(table(NmlOverviewArray2$AllNormalHitsNamesCount,
data=NmlOverviewArray2,
ylab=Number of Individual Antibody Responses,
xlab=Occurrence of Individual Antibody Responses
 (Out of 45 Normals),
box.ratio=1)

 plot (upper, newpage=TRUE, more=TRUE, position = c(0,.15,1,1))
 plot (lower, newpage=FALSE, more=TRUE, position = c(0,0,1,.3))


 George

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] Dynamic arguments in rbind function

2010-01-04 Thread Sundar Dorai-Raj
Use a list instead of assign then do.call(rbind, thelist).

import.files - c(a.txt, b.txt,  c.txt,  d.txt,  e.txt)
imp - vector(list, length(import.files))
for (i in 1:length(import.files)) {
  imp[[i]] - read.delim(import.files[i], sep = , header = TRUE)
}

combined - do.call(rbind, imp)

HTH,

--sundar

On Mon, Jan 4, 2010 at 4:31 PM, Steven Kang stochastick...@gmail.comwrote:

 Hi, all

 Basically, I have unknown number of data that need to be imported and
 collapsed row-wisely.

 The code below works fine, however the rbind function may require 50
 arguments if there are 50 data files...

 Thus, I would like to explore whether there are any methods in using
 dynamic
 objects (i.e from the resulting objects in the for loop) as an argument in
 the *rbind* function.



 setwd(.)

 import.files - c(a.txt, b.txt,  c.txt,  d.txt,  e.txt)
 for (i in 1:length(import.files)) {
  assign(paste(imp, i, sep = .), read.delim(eval(paste(.\\,
 import.files[i], sep = )), header = TRUE))
 }

 combined - rbind(*imp.1, imp.2, imp.3, imp.4, imp.5, imp.6*)



 Your expertise in resolving this issue would be greatly appreciated.



 Steve

[[alternative HTML version deleted]]

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] makefile for sweave

2009-11-26 Thread Sundar Dorai-Raj
Is texi2dvi in your PATH? What happens if you open a CMD window and
type texi2dvi at the prompt?

--sundar

On Thu, Nov 26, 2009 at 6:14 AM, Wolfgang Raffelsberger wr...@igbmc.fr wrote:
 Dear all,

 I can't get texi2dvi working right. Basically I'd like to convert a .lex to
 .pdf without having to fiddle with the issue Sweave.sty not being in my
 current directory (as this was sugested in other posts on this list).

 When I'm in the R-Gui I can get the help via
 ?texi2dvi
 (So I conclude its installed.)

 However, when I try to use it to concert a .tex to .pdf I get trouble ...

 For example :
 A)
 The file test02.r contains :
 Sweave(Sweave_test01.rnw)
 library(tools)
 texi2dvi(Sweave_test01.tex, pdf =T)

 Now, when I run on the linux command line :
 R --vanilla -q  test02.r

 I get :
 Sweave(Sweave_test01.rnw)
 Writing to file Sweave_test01.tex
 Processing code chunks ...
 1 : term hide (label=chunk_ini)
 2 : term verbatim eps pdf (label=Fig01)
 3 : term tex (label=packageVersionInfo)
 Loading required package: xtable

 You can now run LaTeX on 'Sweave_test01.tex'
 library(tools)
 texi2dvi(Sweave_test01.tex, pdf =T)
 Error in texi2dvi(Sweave_test01.tex, pdf = T) :
  Running 'texi2dvi' on 'Sweave_test01.tex' failed.
 Messages:
 sh: texi2dvi: command not found
 Execution halted


 B)
 In a previous message on this list I found the following command line(s)
 suggested, but I my case it won't work

 star5_R_test_ R CMD texi2dvi --help
 /usr/local/lib64/R/bin/Rcmd: line 62: exec: texi2dvi: not found

 similarly, when execute (as sugested) I get the same error message

 star5_R_test_ R CMD texi2dvi -p Sweave_test01.tex
 /usr/local/lib64/R/bin/Rcmd: line 62: exec: texi2dvi: not found


 I don't understand how can a command can be present (= installed) and still
 not being found as the error messages suggest ?

 For completeness :
 sessionInfo()
 R version 2.10.0 (2009-10-26)
 x86_64-unknown-linux-gnu

 locale:
 [1] C

 attached base packages:
 [1] stats     graphics  grDevices utils     datasets  methods   base
 other attached packages:
 [1] xtable_1.5-6         mouse4302probe_2.5.0 AnnotationDbi_1.8.1
 [4] mouse4302cdf_2.5.0   MASS_7.3-3           fdrtool_1.2.5      [7]
 limma_3.2.1          affyPLM_1.22.0       preprocessCore_1.8.0
 [10] gcrma_2.18.0         affy_1.24.2          Biobase_2.6.0
 loaded via a namespace (and not attached):
 [1] Biostrings_2.14.3 DBI_0.2-4         IRanges_1.4.4     RSQLite_0.7-3
 [5] affyio_1.14.0     splines_2.10.0    tools_2.10.0



 Thank's in advance,
 Wolfgang


 Charles C. Berry a écrit :

 On Tue, 8 Sep 2009, Welma Pereira wrote:

 Hello, I have the following makefile. The problem is that the
 bibliography
 doesn t work. Any help would be appreciated! I really don t don t what to
 do..:-(



 # The sources of the report (tex, Rnw and other files (e.g. bib, idx))
 TEX_CMPS = Report problem
 RNW_CMPS = prop1 prop2 ExeExps
 OTHER =  Report.bib

 # The name of the report to produce
 all: Report.pdf

 code: $(RNW_CMPS:=.R)

 clean:
   rm -f  *.log *.dvi *~

 # On what does the report depends?
 Report.pdf: $(TEX_CMPS:=.tex) $(RNW_CMPS:=.tex) ${OTHER} makefile
   TEXINPUTS=${TPUTS} pdflatex $
   TEXINPUTS=${TPUTS} pdflatex $

 IIRC

    R CMD texi2dvi -p target.tex

 takes care of finding sweave.sty and running latex thru all the iterations
 needed to build cross-references and a usable pdf.

 Try

    R CMD texi2dvi --help

 at the shell prompt.

 HTH,

 Chuck


   rm *.log
 #    mv *.aux  $(dir $)

 # How to build the tex files from the Rnw (Sweave) files
 %.tex: %.Rnw
   echo library(utils); options(width=60);  Sweave('$') | ${R_PRG}
 --no-save --vanilla
   mv $(notdir $*.tex)  $(dir $)


 # How to build the R code files from the Rnw (Sweave) files
 %.R: %.Rnw
   echo library(utils); Stangle('$') | ${R_PRG} --no-save --vanilla

 %.bib:
   TEXINPUTS=${TPUTS} pdflatex $
   bibtex $

 %.aux:
   TEXINPUTS=${TPUTS} pdflatex $
   bibtex $

 %.idx:
   TEXINPUTS=${TPUTS} pdflatex $
   makeindex $

 cheers!

    [[alternative HTML version deleted]]

 __
 R-help@r-project.org 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.


 Charles C. Berry                            (858) 534-2098
                                            Dept of Family/Preventive
 Medicine
 E mailto:cbe...@tajo.ucsd.edu                UC San Diego
 http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

 __

 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
 Wolfgang Raffelsberger, PhD
 Laboratoire de BioInformatique et Génomique Intégratives
 IGBMC,  1 rue Laurent Fries,  67404 Illkirch  Strasbourg,  France
 Tel (+33) 388 65 3300         Fax (+33) 388 65 3276
 wolfgang.raffelsberger (at) igbmc.fr

 

Re: [R] Why F value and Pr are not show in summary() of an aov() result?

2009-11-22 Thread Sundar Dorai-Raj
It's hard to read your code, so I won't comment on your specific
example. So when all else fails read the documentation for
?summary.aov:

They have columns ‘Df’, ‘Sum Sq’, ‘Mean
 Sq’, as well as ‘F value’ and ‘Pr(F)’ if there are non-zero
 residual degrees of freedom.

So if you do df.residual(afit), is it 0?

--sundar

On Sun, Nov 22, 2009 at 7:19 AM, Peng Yu pengyu...@gmail.com wrote:
 I have the following code. I'm wondering why summary() doesn't show F
 value and Pr?

 Rscript multi_factor.R
 a=3
 b=4
 c=5
 d=6
 e=7

 A=1:a
 B=1:b
 C=1:c
 D=1:d
 E=1:e

 X=matrix(nr=a*b*c*d*e,nc=5)
 colnames(X)=LETTERS[1:5]

 for(i_a in 1:a-1) {
 +   for(i_b in 1:b-1) {
 +     for(i_c in 1:c-1) {
 +       for(i_d in 1:d-1) {
 +         for(i_e in 1:e-1) {
 +           X[(((i_a * b + i_b) * c + i_c) * d + i_d) * e + i_e + 1, ]
 = c(i_a+1, i_b+1, i_c+1, i_d+1, i_e+1)
 +         }
 +       }
 +     }
 +   }
 + }

 Y=matrix(nr=a*b*c*d*e,nc=1)
 for(i in 1:(a*b*c*d*e)) {
 +   fa=X[i,'A']
 +   fb=X[i,'B']
 +   fc=X[i,'C']
 +   fd=X[i,'D']
 +   fe=X[i,'E']
 +
 +   Y[i,1]= fa +fb +fc +fe +fa*fb +fa*fc +fb*fc +fa*fe +fc*fe
 +fa*fb*fc +fa*fc*fe + rnorm(1)
 + }

 aframe = data.frame(
 +     A=as.factor(X[,'A'])
 +     , B=as.factor(X[,'B'])
 +     , C=as.factor(X[,'C'])
 +     , D=as.factor(X[,'D'])
 +     , E=as.factor(X[,'E'])
 +     ,Y)

 afit=aov(Y ~ A * B * C * D * E, aframe)

 summary(afit)
             Df  Sum Sq Mean Sq
 A             2 1512240  756120
 B             3  453324  151108
 C             4 2549895  637474
 D             5       2  0.3693
 E             6 1451057  241843
 A:B           6   33875    5646
 A:C           8  189839   23730
 B:C          12   56024    4669
 A:D          10       7       1
 B:D          15      25       2
 C:D          20      18       1
 A:E          12  107574    8964
 B:E          18      21       1
 C:E          24  180413    7517
 D:E          30      16       1
 A:B:C        24    4167     174
 A:B:D        30      37       1
 A:C:D        40      42       1
 B:C:D        60      63       1
 A:B:E        36      30       1
 A:C:E        48   13298     277
 B:C:E        72      62       1
 A:D:E        60      79       1
 B:D:E        90      87       1
 C:D:E       120     122       1
 A:B:C:D     120     140       1
 A:B:C:E     144     131       1
 A:B:D:E     180     145       1
 A:C:D:E     240     225       1
 B:C:D:E     360     398       1
 A:B:C:D:E   720     713       1

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] denoting max value in ylim

2009-11-20 Thread Sundar Dorai-Raj
ylim = c(0, max(log10(D10$Part.P)))

Make sure you remove any 0s or NAs before computing the max though.

--sundar

On Fri, Nov 20, 2009 at 6:12 AM, helene frigstad
helenefrigs...@hotmail.com wrote:

 Hi,

 is there any way to set the ylim range from zero to whatever is the max
 value in that dataset? I am plotting many similar plots to the one below,
 and would like to avoid having to find the max value each time.


 plot (D10$Part.P ~ D10$Klorofyll,pch=16,log = xy, xlab = (Chla), ylab =
 (POP), ylim = c (0, ???))
        abline(m3, untf=TRUE, lty=1,col=blue)
        text(5, 0.05,paste(round(glm(D10$Part.P ~ D10$Klorofyll, data = D10, 
 family
 = Gamma(link =      identity))$coef, 2),collapse =  ))

 thank you very much for your time and help.

 Best regards,
 Helene Frigstad
 --
 View this message in context: 
 http://old.nabble.com/denoting-max-value-in-ylim-tp26441590p26441590.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] lapply() not converting columns to factors (no error message)

2009-11-16 Thread Sundar Dorai-Raj
Works for me:

x - 
read.csv(url(http://dc170.4shared.com/download/153147281/a5c78386/Testvcomp10.csv?tsid=20091116-075223-c3093ab0;))
names(x)
x[2:13] - lapply(x[2:13], factor)

 levels(x$P1L55)
[1] 0 1
 is.factor(x$P1L96)
[1] TRUE

 sessionInfo()
R version 2.10.0 (2009-10-26)
i386-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] lattice_0.17-26

loaded via a namespace (and not attached):
[1] grid_2.10.0  tools_2.10.0

On Mon, Nov 16, 2009 at 4:50 AM, A Singh aditi.si...@bristol.ac.uk wrote:
 Sorry, my file is at:


 http://www.4shared.com/file/153147281/a5c78386/Testvcomp10.html


 --
 A Singh
 aditi.si...@bristol.ac.uk
 School of Biological Sciences
 University of Bristol

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] lapply() not converting columns to factors (no error message)

2009-11-16 Thread Sundar Dorai-Raj
Could it be you have factor redefined in your workspace? Have you
tried it in a clean directory? I.e. a directory where no .RData
exists?

On Mon, Nov 16, 2009 at 5:07 AM, A Singh aditi.si...@bristol.ac.uk wrote:
 Oh, strange!

 I thought it might be a problem with the 'base' package installation,
 because the same thing's worked for me too before but won't do now.

 I tried to reinstall it (base), but R says its there already which I
 expected it to be anyway.

 I don't quite know where the issue is. Very odd.


 --On 16 November 2009 04:59 -0800 Sundar Dorai-Raj sdorai...@gmail.com
 wrote:

 Works for me:

 x -
 read.csv(url(http://dc170.4shared.com/download/153147281/a5c78386/Testvc
 omp10.csv?tsid=20091116-075223-c3093ab0)) names(x)
 x[2:13] - lapply(x[2:13], factor)

 levels(x$P1L55)

 [1] 0 1

 is.factor(x$P1L96)

 [1] TRUE

 sessionInfo()

 R version 2.10.0 (2009-10-26)
 i386-apple-darwin9.8.0

 locale:
 [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

 attached base packages:
 [1] stats     graphics  grDevices utils     datasets  methods   base

 other attached packages:
 [1] lattice_0.17-26

 loaded via a namespace (and not attached):
 [1] grid_2.10.0  tools_2.10.0

 On Mon, Nov 16, 2009 at 4:50 AM, A Singh aditi.si...@bristol.ac.uk
 wrote:

 Sorry, my file is at:


 http://www.4shared.com/file/153147281/a5c78386/Testvcomp10.html


 --
 A Singh
 aditi.si...@bristol.ac.uk
 School of Biological Sciences
 University of Bristol

 __
 R-help@r-project.org 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.




 --
 A Singh
 aditi.si...@bristol.ac.uk
 School of Biological Sciences
 University of Bristol






__
R-help@r-project.org 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] Trellis settings get lost when printing to pdf

2009-11-13 Thread Sundar Dorai-Raj
Did you make the changes before or after starting the device:

library(lattice)
## before doesn't change the settings on the device:
trellis.par.set(plot.symbol = list(col = red))
trellis.device(pdf, file = tmp.pdf)
xyplot(1 ~ 1)
dev.off()

## after does
trellis.device(pdf, file = tmp.pdf)
trellis.par.set(plot.symbol = list(col = red))
xyplot(1 ~ 1)
dev.off()

I never do things like this, though. I would suggest creating a theme
instead and supplying it to xyplot (or whatever plot you're using)
using par.settings:

my.theme - list(plot.symbol = list(col = red))
trellis.device(pdf, file = tmp.pdf)
xyplot(1 ~ 1, par.settings = my.theme)
dev.off()

HTH,

--sundar


2009/11/13 Joel Fürstenberg-Hägg joel_furstenberg_h...@hotmail.com:

 Hi all,



 I've got some problems when changing the trellis settings for the lattice 
 plots. The plots look exactly as I want them to when calling show.settings() 
 as well as when plotting them in the graphical window. But when printing to a 
 pdf file, none of the settings are used!? Does anyone know what might have 
 happened? Because the when changing the trellis settings, these should remain 
 in the new state until you close R right..?



 # Change settings for the boxplot appearance
 new.dot=trellis.par.get(box.dot)
 new.rectangle=trellis.par.get(box.rectangle)
 new.umbrella=trellis.par.get(box.umbrella)
 new.symbol=trellis.par.get(plot.symbol)
 new.strip.background=trellis.par.get(strip.background)
 new.strip.shingle=trellis.par.get(strip.shingle)
 new.dot$pch=|
 new.dot$col=black
 new.rectangle$col=black
 new.rectangle$fill=grey65
 new.umbrella$col=black
 new.umbrella$lty=1 # Continous line, not dotted
 new.symbol$col=black
 new.strip.background$col=grey87 # Background colour in the upper label
 new.strip.shingle$col=black # Border colour around the upper label
 trellis.par.set(box.dot=new.dot, box.rectangle=new.rectangle, 
 box.umbrella=new.umbrella, plot.symbol=new.symbol, 
 strip.background=new.strip.background, strip.shingle=new.strip.shingle)



 Best regards,



 Joel

 _
 Nya Windows 7 - Hitta en dator som passar dig! Mer information.
 http://windows.microsoft.com/shop
        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] tapply function

2009-11-03 Thread Sundar Dorai-Raj
you must have missing values in data. Try

tapply(data, group, mean, na.rm = TRUE)

If that's not the case, read the bottom of this email about the posting guide.

HTH,

--sundar

On Tue, Nov 3, 2009 at 5:28 AM, FMH kagba2...@yahoo.com wrote:
 Hi,

 I tried to use tapply function to find the mean of the data in each group as 
 the following command, but the result are NA, as there are several missing 
 values in each group.

 tapply(data,group,mean)

 Could someone please advice me the way to  ignore the missing data in order 
 for the fucntion to run successfully?

 Thanks

 Fir




 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Issue with %in% - not matching identical rows in data frames

2009-11-03 Thread Sundar Dorai-Raj
?%in% says x and table must be vectors. You supplied
data.frames. So %in% is coercing your today.sequence to a vector using

as.character(today.sequence)

Perhaps you should paste the columns together first:

x - do.call(paste, c(sequence, sep = ::))
table - do.call(paste, c(today.sequence, sep = ::))
x[7] %in% table

I'm not sure if this is what you want/need, but it does match your example.

HTH,

--sundar

On Tue, Nov 3, 2009 at 7:53 AM, Kaushik Krishnan
kaushik.s.krish...@gmail.com wrote:
 Hi folks

 I have two data frames.  I know that the nth (let's say the 7th) row
 in the first data frame (sequence) is there in the second
 (today.sequence).  When I try to check that by doing 'sequence[7,]
 %in% today.sequence', I get all FALSE when it should be all TRUE.

 I'm certain I'm making some trivial mistake.  Any solutions?

 The code to recreate the data frames and see for yourself is:
 
 sequence - structure(list(DATE = structure(c(14549, 14549, 14553, 14550,
 14557, 14550, 14551, 14550), class = Date), DATASET = c(1L,
 2L, 1L, 2L, 2L, 3L, 3L, 4L), REP = c(1L, 0L, 2L, 2L, 3L, 0L,
 1L, 0L), WRONGS_ABS = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), WRONGS_RATIO = c(0L,
 0L, 0L, 0L, 0L, 0L, 0L, 0L), DONE = c(1L, 1L, 0L, 1L, 0L, 1L,
 0L, 0L)), .Names = c(DATE, DATASET, REP, WRONGS_ABS,
 WRONGS_RATIO, DONE), class = data.frame, row.names = c(NA,
 -8L))

 today.sequence - structure(list(DATE = structure(c(14551, 14550),
 class = Date),
    DATASET = 3:4, REP = c(1L, 0L), WRONGS_ABS = c(0L, 0L),
 WRONGS_RATIO = c(0L,
    0L), DONE = c(0L, 0L)), .Names = c(DATE, DATASET, REP,
 WRONGS_ABS, WRONGS_RATIO, DONE), row.names = 7:8, class = data.frame)

 sequence[7,] #You should see '2009-11-03       3   1          0
    0    0'

 today.sequence #You can clearly see that sequence [7,] is the first
 row in today.sequence

 sequence[7,] %in% today.sequence #This should show 'TRUE TRUE TRUE
 TRUE TRUE TRUE'.  Instead
 # it shows 'FALSE FALSE FALSE FALSE FALSE FALSE'
 

 Thanks

 --
 Kaushik Krishnan
 (kaushik.s.krish...@gmail.com)

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] How can I run a function to a piece of text?

2009-10-16 Thread Sundar Dorai-Raj
Based solely on what you told us, this can be done using eval(parse(text=...))

cmd - sprintf(mean(%s), script)
eval(parse(text = cmd))

However, with more context, there may be a better solution. See, for example,

install.packages(fortunes)
library(fortunes)
fortune(parse())

HTH,

--sundar

On Fri, Oct 16, 2009 at 11:39 AM, Javier PB
j.perez-barbe...@macaulay.ac.uk wrote:

 Dear users,

 I got really stuck trying to apply a function to a piece of code that I
 created using different string functions.

 To make things really easy, this is a wee example:

 x-c(1:10)
 script-x, trim = 0, na.rm = FALSE        ##script created by a number of
 paste() and rep() steps
 mean(script)                                       ##function that I want to
 apply: doesn't work

 Is there any way to convert the script class so that the function mean()
 can read it as if it were text typed in the console?

 Thanks and have a superb day

 Javier



 --
 View this message in context: 
 http://www.nabble.com/How-can-I-run-a-function-to-a-piece-of-text--tp25930315p25930315.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Error in family$family : $ operator is invalid for atomic vectors

2009-10-11 Thread Sundar Dorai-Raj
Check to see if you have an old workspace being loaded. You might have an
object called 'family' which you might need to remove.

--sundar

On Oct 11, 2009 12:15 PM, romunov romu...@gmail.com wrote:

Thank you Jorge and Barry for your input.

I've fiddled around a bit and as a result, am even more confused. If I start
R console via Notepad++ (I use Npp2R) and execute the model1, it goes
through just fine. Here is the sessionInfo() for this working session:

 sessionInfo()
R version 2.9.2 (2009-08-24)
i386-pc-mingw32

locale:
LC_COLLATE=Slovenian_Slovenia.1250;LC_CTYPE=Slovenian_Slovenia.1250;LC_MONETARY=Slovenian_Slovenia.1250;LC_NUMERIC=C;LC_TIME=Slovenian_Slovenia.1250

attached base packages: [1] stats graphics grDevices utils datasets methods
base

loaded via a namespace (and not attached):
[1] tools_2.9.2

And if I run R normally, via an icon from the desktop (Rgui.exe) it gives
the aforementioned error. Here is the sessionInfo() for non-working
session. Is it possible that grid, reshape, plyr, ggplot2 and proto could be
causing this? If so, how can I prevent them from loading automatically or
unloading from a live session?

 sessionInfo()
R version 2.9.2 (2009-08-24)
i386-pc-mingw32

locale:
LC_COLLATE=Slovenian_Slovenia.1250;LC_CTYPE=Slovenian_Slovenia.1250;LC_MONETARY=Slovenian_Slovenia.1250;LC_NUMERIC=C;LC_TIME=Slovenian_Slovenia.1250

attached base packages:
[1] stats graphics  grDevices utils datasets  grid  methods
[8] base

other attached packages:
[1] reshape_0.8.3 plyr_0.1.9proto_0.3-8

loaded via a namespace (and not attached):
[1] ggplot2_0.8.3


Cheers,
Roman



On Sun, Oct 11, 2009 at 6:32 PM, Jorge Ivan Velez
jorgeivanve...@gmail.comwrote:

 Hi Romain,  It works for me:   model1 - glm(as.vector(x)
~dept*sex*admit,poisson)  model1  ...

[[alternative HTML version deleted]]

__
R-help@r-project.org 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] How to speed up R with version 2.9.2?

2009-10-02 Thread Sundar Dorai-Raj
Another possibility is a very large .RData file in the directory where
you're starting R. You can try

Rgui --no-restore

(I don't have windows, so I'm not sure if this an option with RGui,
though I know it is with R.)

--sundar

On Fri, Oct 2, 2009 at 8:50 AM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 Its under 5 seconds on my Vista laptop.  Do you have any startup files?  If
  Rgui --vanilla
 is much faster then your startup files are the problem.

 On Fri, Oct 2, 2009 at 11:45 AM, FMH kagba2...@yahoo.com wrote:
 Thank you for your answer. I'm using Win XP with 2GB RAM in memory.

 Cheers
 Fir



 - Original Message 
 From: stephen sefick ssef...@gmail.com
 To: FMH kagba2...@yahoo.com
 Cc: r-help@r-project.org
 Sent: Fri, October 2, 2009 4:38:10 PM
 Subject: Re: [R] How to speed up R with version 2.9.2?

 You're fine, but please do read the posting guide.  What OS etc.
 Where you doing anything else on the computer?  Is this a RAM
 limitation?  I have 2.9.2 running on two flavours of linux, mac os x
 and windows all 2.9.2 and there doesn't seem to be a problem.
 regards,

 Stephen

 On Fri, Oct 2, 2009 at 10:35 AM, FMH kagba2...@yahoo.com wrote:
 Dear All,

 I'm sorry if my question does not suit with this R group.

 I have recently installed R software with version 2.9.2, but i found the 
 program took almost 1 minute as soon as it was opened, before it can be 
 used. However, the previous version 2.9.1 only take few seconds after the 
 menu bar was clicked. This circumstance has caused me to wait for couple of 
 minutes as several R windows were opened simultaneously.

 Are there any ways to speed up on this 2.9.2 version? Could someone give 
 some hints, please?

 Thank you
 Fir




 __
 R-help@r-project.org 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.




 --
 Stephen Sefick

 Let's not spend our time and resources thinking about things that are
 so little or so large that all they really do for us is puff us up and
 make us feel like gods.  We are mammals, and have not exhausted the
 annoying little problems of being mammals.

                                 -K. Mullis





 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Skipping missing files when importing data

2009-09-20 Thread Sundar Dorai-Raj
Try ?file.exists.

if (file.exists(fxxx)) {
  read.table(fxxx)
} else {
  cat(\, fxxx, \ is missing\n, sep = )
}

HTH,

--sundar

On Sun, Sep 20, 2009 at 9:28 PM, jiangrm jian...@gmail.com wrote:
 Trying to import a bunch of data files named like f001, f002, f999. Some 
 of the files may be
 missing and the missing files vary from time to time.

 Used for loop and read.table. When it reaches the missing file (say f100), it 
 shows:

 Error in file(file, r) : cannot open the connection
 In addition: Warning message:
 In file(file, r) :
  cannot open file 'f100': No such file or directory

 and the program stops.

 How can I skip the missing ones and keep the program running? Guess either 
 checking the validity of
 filenames, or ignore the error message may work. Which functions should be 
 used or any better ideas?


 -RJ

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] xyplot: Can I identify groups but not use them for regression?

2009-09-18 Thread Sundar Dorai-Raj
I think this ought to work for you:

library(lattice)
set.seed(42)
d - data.frame(year  = c(rep(2007,12), rep(2008,12)),
treatment = rep(LETTERS[1:3], each = 4, times = 2))
d$cover - rnorm(nrow(d))
d$variable - rnorm(nrow(d))

xyplot(variable ~ cover | year, d,
   panel = function(x, y, ...) {
 panel.superpose(x, y, ...)
 panel.lmline(x, y, ...)
   },
   groups = treatment)

HTH,

--sundar

On Fri, Sep 18, 2009 at 3:42 PM, Seth W Bigelow sbige...@fs.fed.us wrote:
 I wish to identify groups representing different treatments, but to plot
 them and do a regression using a continuous variable (cover)
 ignoring the groupings.

 d$year - NA
 d$year -c(rep(2007,12), rep(2008,12))
 d$treatment - c(rep(A,4),rep(B,4),rep(C,4), rep(A,4), rep(B,4),
 rep(C,4))
 d$cover - rnorm(24)
 d$variable - rnorm(24)

 xyplot(variable ~ cover | year, d,
        type=c(p,r),
        groups=treatment
        )

 As it stands, a different regression line is plotted for each treatment.
 Oh, and how do I display the actual numeric value of year (e.g., 2007)
 in the strip, rather than the word year?

 --Seth



 Dr. Seth  W. Bigelow
 Biologist, USDA-FS Pacific Southwest Research Station
 1731 Research Park Drive, Davis California
        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Lattice graph tweaking

2009-08-25 Thread Sundar Dorai-Raj
A reproducible example would be nice.

Try grid = FALSE for the first question, though I'm unaware which
lattice plot you are using where the default is TRUE. So I can't
guarantee that will even work.

For your second question, add

par.settings = list(strip.background = list(col = white))

to your call (e.g. xyplot(..., par.settings = ...)).

To see what other parameters you can set in par.settings, try:

str(trellis.par.get())

HTH,

--sundar

On Tue, Aug 25, 2009 at 6:14 AM, Wallis,
Daviddavid.walli...@imperial.ac.uk wrote:
 To: silwood-r
 Subject: Removing lattice graph gridlines and editing label box colour

 Hi,

 Is it possible to remove the background gridlines from a lattice graph (ie 
 graph made up of multiple individual graphs with annoying blue grid in the 
 backgroun)?

 Also, Is it possible to change the colour of the individual graph label 
 boxes? - ie the default pink boxes above the individual graphs

 Thanks

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Help with nls and error messages singular gradient

2009-08-25 Thread Sundar Dorai-Raj
Hi, Michael,

I think the SPSS answer is wrong. Your starting values are way off.
Look at this plot for verification:

con - textConnection(time  bod
11 0.47
22 0.74
33 1.17
44 1.42
55 1.60
67 1.84
79 2.19
8   11 2.17)
mydata - read.table(con, header = TRUE)
close(con)

beta - c(3, -0.1) # your initial values
beta - c(2.4979, -2.02456)  # SPSS answer
mycurve - function(x) {
  beta[1]/(1 - exp(beta[1] * x))
}
curve(mycurve, from = 1, to = 11,
  ylim = range(mydata$bod, mycurve(mydata$time)))
points(mydata$time, mydata$bod)

You might want to look at package nls2 which allows a brute force grid
search to find some starting values. Or rethink the equation you're
trying to fit.

HTH,

--sundar

On Tue, Aug 25, 2009 at 9:10 AM, Michael Pearmainmpearm...@google.com wrote:
 Hi All,

 I'm trying to run nls on the data from the study by Marske (Biochemical
 Oxygen Demand Interpretation Using Sum of Squares Surface. M.S. thesis,
 University of Wisconsin, Madison, 1967) and was reported in Bates and Watts
 (1988).

 Data is as follows, (stored as mydata)

  time  bod
 1    1 0.47
 2    2 0.74
 3    3 1.17
 4    4 1.42
 5    5 1.60
 6    7 1.84
 7    9 2.19
 8   11 2.17

 I then run the following;
 #Plot initial curve
 plot(mydata$time, mydata$bod,xlab=Time (in days),ylab=biochemical oxygen
 demand (mg/l) )

 model - nls(bod ~ beta1/(1 - exp(beta2*time)), data =
 mydata, start=list(beta1 = 3, beta2 = -0.1),trace=T)

 The start values are recommended, (I have used these values in SPSS without
 any problems, SPSS returns values of Beta1 = 2.4979 and Beta2 = -2.02 456)

 but return the error message,
 Error in nls(bod ~ beta1/(1 - exp(beta2 * time)), data = mydata, start =
 list(beta1 = 3,  : singular gradient

 Can anyone offer any advice?

 Thanks in advance

 Mike









 --
 Michael Pearmain
 Senior Analytics Research Specialist

 “Statistics are like women; mirrors of purest virtue and truth, or like
 whores to use as one pleases”

 Google UK Ltd
 Belgrave House
 76 Buckingham Palace Road
 London SW1W 9TQ
 United Kingdom
 t +44 (0) 2032191684
 mpearm...@google.com

 If you received this communication by mistake, please don't forward it to
 anyone else (it may contain confidential or privileged information), please
 erase all copies of it, including all attachments, and please let the sender
 know it went to the wrong person. Thanks.

        [[alternative HTML version deleted]]


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org 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] Help with nls and error messages singular gradient

2009-08-25 Thread Sundar Dorai-Raj
Another alternative is to use SSlogis which is very similar to the
model you're fitting except with one additional parameter:

Asym - 3
xmid - 0
scal - 10
model - nls(bod ~ SSlogis(time, Asym, xmid, scal), data = mydata)
summary(model)
plot(bod ~ time, mydata)
newdata - data.frame(time = seq(1, 11, length = 100))
lines(newdata$time, predict(model, newdata))

HTH,

--sundar

On Tue, Aug 25, 2009 at 10:05 AM, Sundar Dorai-Rajsdorai...@gmail.com wrote:
 Hi, Michael,

 I think the SPSS answer is wrong. Your starting values are way off.
 Look at this plot for verification:

 con - textConnection(time  bod
 1    1 0.47
 2    2 0.74
 3    3 1.17
 4    4 1.42
 5    5 1.60
 6    7 1.84
 7    9 2.19
 8   11 2.17)
 mydata - read.table(con, header = TRUE)
 close(con)

 beta - c(3, -0.1) # your initial values
 beta - c(2.4979, -2.02456)  # SPSS answer
 mycurve - function(x) {
  beta[1]/(1 - exp(beta[1] * x))
 }
 curve(mycurve, from = 1, to = 11,
      ylim = range(mydata$bod, mycurve(mydata$time)))
 points(mydata$time, mydata$bod)

 You might want to look at package nls2 which allows a brute force grid
 search to find some starting values. Or rethink the equation you're
 trying to fit.

 HTH,

 --sundar

 On Tue, Aug 25, 2009 at 9:10 AM, Michael Pearmainmpearm...@google.com wrote:
 Hi All,

 I'm trying to run nls on the data from the study by Marske (Biochemical
 Oxygen Demand Interpretation Using Sum of Squares Surface. M.S. thesis,
 University of Wisconsin, Madison, 1967) and was reported in Bates and Watts
 (1988).

 Data is as follows, (stored as mydata)

  time  bod
 1    1 0.47
 2    2 0.74
 3    3 1.17
 4    4 1.42
 5    5 1.60
 6    7 1.84
 7    9 2.19
 8   11 2.17

 I then run the following;
 #Plot initial curve
 plot(mydata$time, mydata$bod,xlab=Time (in days),ylab=biochemical oxygen
 demand (mg/l) )

 model - nls(bod ~ beta1/(1 - exp(beta2*time)), data =
 mydata, start=list(beta1 = 3, beta2 = -0.1),trace=T)

 The start values are recommended, (I have used these values in SPSS without
 any problems, SPSS returns values of Beta1 = 2.4979 and Beta2 = -2.02 456)

 but return the error message,
 Error in nls(bod ~ beta1/(1 - exp(beta2 * time)), data = mydata, start =
 list(beta1 = 3,  : singular gradient

 Can anyone offer any advice?

 Thanks in advance

 Mike









 --
 Michael Pearmain
 Senior Analytics Research Specialist

 “Statistics are like women; mirrors of purest virtue and truth, or like
 whores to use as one pleases”

 Google UK Ltd
 Belgrave House
 76 Buckingham Palace Road
 London SW1W 9TQ
 United Kingdom
 t +44 (0) 2032191684
 mpearm...@google.com

 If you received this communication by mistake, please don't forward it to
 anyone else (it may contain confidential or privileged information), please
 erase all copies of it, including all attachments, and please let the sender
 know it went to the wrong person. Thanks.

        [[alternative HTML version deleted]]


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org 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] how to check if ... is empty

2009-07-16 Thread Sundar Dorai-Raj
Try

dots - list(...)
if (length(dots) == 0) {
  ## do something
}

On Thu, Jul 16, 2009 at 6:46 AM, Thomas Roth (geb.
Kaliwe)hamstersqu...@web.de wrote:
 Hi,

 I was wondering what would be the best way to check if the three dots
 argument contains any arguments (i.e. does ... contain any arguments or not?
 )

 #Example

 test = function(x,y, ...)
 {
   #Wanted R-Code
   # if(empty(...))
   #    do some calculation


   plot(x,y,...)

 }

 Thanks

 Thomas Roth

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Lattice group colors?

2009-06-22 Thread Sundar Dorai-Raj
Look at show.settings() and str(trellis.par.get()). This will show you
what the default settings are. The group colors are set by the
superpose.* elements (e.g. superpose.line is for group lines). To set
them, I usually create a list and pass it to par.settings. For
example,

my.theme - list(superpose.line = list(col = c(darkred, darkblue),
lty = 1:2))
xyplot(y ~ x, data = mydata, groups = g, par.settings = my.theme,
  auto.key = list(points = FALSE, lines = TRUE))

HTH,

--sundar

On Mon, Jun 22, 2009 at 6:30 AM, Fredrik Karlssondargo...@gmail.com wrote:
 Dear list,

 I have been struggling to find how I would go about changing the
 bakground colors of groups in a lattice barchart in a way so that the
 auto.key generated also does the right thing and pick it up for the
 key.
 I have used the col argument (which I guess is sent to par()) in a
 way so that the colors are like I would want them, but now I guess I
 need to know which part part of the theme I need to change in order to
 make this change permanent for all the plots, and all the keys.

 I am of course thankful for all the help I can get.

 (Also, how does one know these things about the theme variables? Is
 there some documentation somewhere?)

 /Fredrik

 --
 Life is like a trumpet - if you don't put anything into it, you don't
 get anything out of it.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] reading in multiple files

2009-06-09 Thread Sundar Dorai-Raj
You could try:

do.call(rbind, lapply(list.files(path/to/files, full = TRUE), read.csv))

And add more arguments to lapply if the files are not csv, have no header, etc.

--sundar

On Tue, Jun 9, 2009 at 11:18 AM, Erin Hodgesserinm.hodg...@gmail.com wrote:
 Dear R People:

 I have about 6000 files to be read in that I'd like to go to one
 matrix.  There are two columns, 1 line in each file.

 Is there a way to bring them in to produce one matrix or data frame, please?

 Thanks,
 Erin


 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: erinm.hodg...@gmail.com

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] find a sequence of characters in a vector

2009-06-05 Thread Sundar Dorai-Raj
use gregexpr and paste

 aze - paste(c(a, z, e), collapse = )
 sequence - paste(c(a,z,e,r,t,a,z,a,z,e,c), collapse = 
 )
 gregexpr(aze, sequence, fixed = TRUE)
[[1]]
[1] 1 8
attr(,match.length)
[1] 3 3

HTH,

--sundar

On Fri, Jun 5, 2009 at 6:22 AM, Ptit_Bleuptit_b...@yahoo.fr wrote:

 Hello,

 I'm just looking for an easy way to find the positions of a complete
 sequence in a bigger vector.
 For example :
 c(a,z,e) in c(a,z,e,r,t,a,z,a,z,e,c)
 and the result should be
 1 8
 that is the positions of the beginning of the complete sequence.

 I tried with %in%, match, is.element but all I get is, for example
 which(c(a,z,e) in c(a,z,e,r,t,a,z,a,z,e,c))
 1 2 3
 meaning that each character is in the bigger vector.

 It must be easy, except for me. Sorry.

 If you have a solution, thanks in advance to share it.
 Have a good week-end,
 Ptit Bleu.

 --
 View this message in context: 
 http://www.nabble.com/find-a-sequence-of-characters-in-a-vector-tp23888063p23888063.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] error message re: max(i), but code and output seen O.K.

2009-05-20 Thread Sundar Dorai-Raj
This error is thrown if the argument to max is either NULL or length zero:

[~] Rscript -e max(NULL)
[1] -Inf
Warning message:
In max(NULL) : no non-missing arguments to max; returning -Inf
[~] Rscript -e max(numeric(0))
[1] -Inf
Warning message:
In max(numeric(0)) : no non-missing arguments to max; returning -Inf

HTH,

--sundar

On Wed, May 20, 2009 at 11:23 AM, Kirsten Miles sirole@gmail.com wrote:
 I have a researcher who is consistently get the warning message:

 In max(i) : no non-missing arguments to max; returning -Inf

 Best as I can tell the code is working properly and the output is as
 expected. I would like some help in understanding why he is getting this
 error message and what its implications are.  I have his code.

 Sincerely,
 Kirsten Miles
 Support Specialist
 Research Computing Lab
 Charles L. Brown Science and Engineering Library

 kd...@virginia.edu

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] what is wrong with this code?

2009-05-19 Thread Sundar Dorai-Raj
You're missing a ) off end of the first line. You should consider
using an editor (e.g. ESS/Emacs) that does parentheses matching. I
found this in less than 5 sec (less time than I'm taking to write you
a note) by cut and pasting in Emacs.

--sundar

On Tue, May 19, 2009 at 12:52 PM, deanj2k dl...@le.ac.uk wrote:

 dlogl - -(n/theta)-sum((y/(theta)^2)*((1-exp(y/theta))/(1+exp(y/theta)))

 d2logl - (n/theta^2) - sum((-2y/theta^3)*(1-exp(y/theta))/(1+exp(y/theta)))
 - sum(((2*y/theta^4)*exp(y/theta))/((1+exp(y/theta))^2))

 returns the error message:
 Error: unexpected symbol in:
 dlogl - -(n/theta)-sum((y/(theta)^2)*((1-exp(y/theta))/(1+exp(y/theta)))
 d2logl

 do you know what i have done wrong
 --
 View this message in context: 
 http://www.nabble.com/what-is-wrong-with-this-code--tp23623227p23623227.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] convert large integers to hex

2009-05-07 Thread Sundar Dorai-Raj
Thanks for both answers. In the end I decided to use Gabor's bc package.

Thanks,

--sundar

On Thu, May 7, 2009 at 5:10 AM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 There is an interface between R and bc -- not on CRAN but available
 from its home page here:
 http://r-bc.googlecode.com

 source(http://r-bc.googlecode.com/svn/trunk/R/bc.R;)
 bc(obase = 16; 123456789123456789, retclass = character)
 [1] 1B69B4BACD05F15


 On Wed, May 6, 2009 at 9:59 PM, jim holtman jholt...@gmail.com wrote:
 You can use the 'bc' command (use Cygwin if on Windows);

 /cygdrive/c: bc
 bc 1.06
 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
 This is free software with ABSOLUTELY NO WARRANTY.
 For details type `warranty'.
 x=6595137340052185552
 obase=16
 x
 5B86A277DEB9A1D0

 You can call this from R.

 On Wed, May 6, 2009 at 3:26 PM, Sundar Dorai-Raj sdorai...@gmail.comwrote:

 Hi,

 I'm wondering if someone has solved the problem of converting very
 large integers to hex. I know about format.hexmode and as.hexmode, but
 these rely on integers. The numbers I'm working with are overflowing
 and losing precision. Here's an example:

 x - 6595137340052185552 # stored as character
 as.integer(x) # warning about inaccurate conversion
 format.hexmode(as.numeric(x)) # warnings about loss of precision
 as.hexmode(x) # more warnings and does not do what I expected

 I'm planning on writing a function that will do this, but would like
 to know if anybody already has a solution. Basically, I would like the
 functionality of format.hexmode on arbitrarily large integers.

 Thanks,

 --sundar

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] convert large integers to hex

2009-05-06 Thread Sundar Dorai-Raj
Hi,

I'm wondering if someone has solved the problem of converting very
large integers to hex. I know about format.hexmode and as.hexmode, but
these rely on integers. The numbers I'm working with are overflowing
and losing precision. Here's an example:

x - 6595137340052185552 # stored as character
as.integer(x) # warning about inaccurate conversion
format.hexmode(as.numeric(x)) # warnings about loss of precision
as.hexmode(x) # more warnings and does not do what I expected

I'm planning on writing a function that will do this, but would like
to know if anybody already has a solution. Basically, I would like the
functionality of format.hexmode on arbitrarily large integers.

Thanks,

--sundar

__
R-help@r-project.org 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] setting trellis auto.key color values

2009-05-05 Thread Sundar Dorai-Raj
Set the colors in graph.sets and not auto.key.

graph.sets - list(axis.text = list(cex = 0.65),
  par.ylab.text = list(cex = 1.25),
  par.xlab.text = list(cex = 1.25),
  superpose.polygon = list(col = 3:5))

Then remove the col = 3:5 from auto.key and barchart.

Also, you can simplify your code by removing gator_IR$ and including
data = gator_IR. I.e.

 barchart(MEAN ~ Hydro | as.factor(IR_ID),
 data = gator_IR, layout = c(4, 1),
 groups = Rain, ylim = c(0, 1), ...)

HTH,

--sundar

On Tue, May 5, 2009 at 8:32 AM,  steve_fried...@nps.gov wrote:


 I'm working with Lattice graphics and I would like very much to color code
 the auto.key fill color with the same corresponding colors that I use in
 the panels.  I've looked on the web for clues, and on the CRAN-R help sites
 searching on trellis auto.key color and variations, unfortunately the
 responses there are not very specific.

  Would someone please explain   I have the Book, if you can point me to the
 pages that explain this I'd appreciate that too



 graph.sets - list(axis.text = list(cex = 0.65),
              par.ylab.text = list(cex = 1.25),
              par.xlab.text = list(cex = 1.25))


   barchart(gator_IR$MEAN ~ gator_IR$Hydro |
 as.factor(gator_IR$IR_ID),layout=c(4,1),col = c(3:5),
                 groups=gator_IR$Rain, ylim=c(0,1), par.settings =
 graph.sets,
                 main = Alligator Nesting Performance, ylab= Mean HSI,
                 auto.key = list(top, columns=3, col=c(3:5))


 this script creates the graph nicely, with the qualification that the color
 for the key titles are the correct, but the filling colors are default
 pastels.  Where do I change them ?


 Windows XP  with R 2.8.1

 Thank you.

 Steve

 Steve Friedman Ph. D.
 Spatial Statistical Analyst
 Everglades and Dry Tortugas National Park
 950 N Krome Ave (3rd Floor)
 Homestead, Florida 33034

 steve_fried...@nps.gov
 Office (305) 224 - 4282
 Fax     (305) 224 - 4147

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] evaluate a expression

2009-05-02 Thread Sundar Dorai-Raj
Hi, Ning,

Try: eval(parse(text = expr))

HTH,

--sundar

On Sat, May 2, 2009 at 5:39 AM, Ning Ma pnin...@gmail.com wrote:
 Hi,

 I am new to R. Can anyone tell me how to evaluate an expression stored
 in a string?
 such as:
 expr - 3*5
 I want to get the result 15.

 Thanks in advance.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Flipping axes of qqnorm

2009-04-26 Thread Sundar Dorai-Raj
Try (re)reading ?qqnorm. Use datax = TRUE.

--sundar

On Sun, Apr 26, 2009 at 4:37 PM, Chris_d dewhurstch...@gmail.com wrote:

 Hi all,
       I have just started using R to produce qqnorm plots. I am trying to
 switch the x and y axes so that the theoretical values are plotted on the y
 axis and my data on the x axis. Can anyone help me with this?

 Thanks
 --
 View this message in context: 
 http://www.nabble.com/Flipping-axes-of-qqnorm-tp23248007p23248007.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Cannot clean infinite values

2009-04-26 Thread Sundar Dorai-Raj
Use ?is.infinite

inf - is.infinite(data)
data[inf] - 0.3 * sign(data[inf])

On Sun, Apr 26, 2009 at 5:44 PM, Nigel Birney na...@cam.ac.uk wrote:

 Hello all,

 I have to import numeric data from file but found it contains Infinite
 values which need to be eliminated. I tried to replace them in this way:

        data[which(data==-Inf)] - -0.3
        data[which(data==+Inf)] -  0.3

 But, somehow, the Infinite values stayed there. Any suggestions?

 regards,

 N.
 --
 View this message in context: 
 http://www.nabble.com/Cannot-clean-infinite-values-tp23248409p23248409.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Setting lattice par parameters

2009-04-23 Thread Sundar Dorai-Raj
Because you're not calling trellis.par.set correctly. It should be:

trellis.par.set(par.ylab.text = list(cex = 0.65), par.xlab.text =
list(cex = 0.65))

However, I usually do things like this:

my.theme - list(par.ylab.text = list(cex = 0.65), par.xlab.text =
list(cex = 0.65))
barchart(..., par.settings = my.theme)

so the settings are only changed for the current plot and not globally.

HTH,

--sundar

On Thu, Apr 23, 2009 at 6:25 AM,  steve_fried...@nps.gov wrote:

 Hello

 I'm plotting a large suite of barcharts and need to modify the size of the
 text for both the yaxis and xaxis labels.

 I've tried using the following:

 trellis.par.set(list(par.ylab.text = list(cex = 0.65)),
 trellis.par.set(list = par.xlab.text = list(cex = 0.65

 On inspection,  however after I invoke this line,

  trellis.par.get(par.ylab.text)
  trellis.par.get(par.xlab.text)

 It looks like the parameters have not been modified.

 Do I need to do something different than this approach ?

 Thank you very much in advance.

 Steve

 Steve Friedman Ph. D.
 Spatial Statistical Analyst
 Everglades and Dry Tortugas National Park
 950 N Krome Ave (3rd Floor)
 Homestead, Florida 33034

 steve_fried...@nps.gov
 Office (305) 224 - 4282
 Fax     (305) 224 - 4147

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] question on using lattice panel plots

2009-04-16 Thread Sundar Dorai-Raj
Try:

z - cbind(rep(c(BIC, hist), each = 150), rep(rep(c(5, 10, 30),
each = 50),2))

z - as.data.frame(z)

z - cbind(z, runif(300))
names(z) - c(Method, sigma, Error)
z$sigma - factor(z$sigma, c(5, 10, 30))
library(lattice)

sigma - as.numeric(levels(z$sigma))
sigmaExprList - lapply(sigma, function(s) bquote(sigma == .(s)))
sigmaExpr - as.expression(sigmaExprList)
bwplot(Error~Method | sigma, data = z,
   horiz = F, xlab = Method,
   strip = strip.custom(var.name = sigmaExpr,
 strip.levels = FALSE, strip.names = TRUE),
   layout = c(3,1))

HTH,

--sundar

On Thu, Apr 16, 2009 at 12:43 PM, Ranjan Maitra mai...@iastate.edu wrote:
 Hi,

 I think this question is best explained using the following
 self-contained toy example:




 ## cut code here and paste to R window

 z - cbind(rep(c(BIC, hist), each = 150), rep(rep(c(5, 10, 30),
 each = 50),2))

 z - as.data.frame(z)

 z - cbind(z, runif(300))

 names(z) - c(Method, sigma, Error)

 library(lattice)

 bwplot(Error~Method | sigma, data = z, horiz = F, xlab = Method,
 layout = c(3,1))


 ## end code




 Now the question:

 I would like the panels to be in the order of sigma, i. e. 5, 10, 30
 and not 10, 30 and 5 as is currently the case. Is this possible?

 Not to seek too much indulgence, but to ask anyway, I wonder if it is
 possible to have a Greek sigma = 5, a Greek sigma = 10 and a Greek
 sigma = 30. (Sort of what we would get using expression(sigma == 5),
 expression(sigma == 10), expression(sigma == 10) on base R figures).

 Please let me know if my question is not clear.

 Many thanks for any suggestions and help and best wishes!
 Ranjan

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] question on using lattice panel plots

2009-04-16 Thread Sundar Dorai-Raj
Sorry, that should be:

sigma - as.numeric(levels(z$sigma))
sigmaExprList - lapply(sigma, function(s) bquote(sigma == .(s)))
sigmaExpr - as.expression(sigmaExprList)
bwplot(Error~Method | sigma, data = z,
   horiz = F, xlab = Method,
   strip = function(which.given, which.panel, var.name,
strip.levels = FALSE,
strip.names = TRUE, ...) {
 strip.default(which.given, which.panel,
   var.name = sigmaExpr[which.panel],
   strip.levels = FALSE,
   strip.names = TRUE, ...)
   },
   layout = c(3,1))

Not sure how to do this with strip.custom.

--sundar

On Thu, Apr 16, 2009 at 1:20 PM, Sundar Dorai-Raj sdorai...@gmail.com wrote:
 Try:

 z - cbind(rep(c(BIC, hist), each = 150), rep(rep(c(5, 10, 30),
 each = 50),2))

 z - as.data.frame(z)

 z - cbind(z, runif(300))
 names(z) - c(Method, sigma, Error)
 z$sigma - factor(z$sigma, c(5, 10, 30))
 library(lattice)

 sigma - as.numeric(levels(z$sigma))
 sigmaExprList - lapply(sigma, function(s) bquote(sigma == .(s)))
 sigmaExpr - as.expression(sigmaExprList)
 bwplot(Error~Method | sigma, data = z,
       horiz = F, xlab = Method,
       strip = strip.custom(var.name = sigmaExpr,
         strip.levels = FALSE, strip.names = TRUE),
       layout = c(3,1))

 HTH,

 --sundar

 On Thu, Apr 16, 2009 at 12:43 PM, Ranjan Maitra mai...@iastate.edu wrote:
 Hi,

 I think this question is best explained using the following
 self-contained toy example:




 ## cut code here and paste to R window

 z - cbind(rep(c(BIC, hist), each = 150), rep(rep(c(5, 10, 30),
 each = 50),2))

 z - as.data.frame(z)

 z - cbind(z, runif(300))

 names(z) - c(Method, sigma, Error)

 library(lattice)

 bwplot(Error~Method | sigma, data = z, horiz = F, xlab = Method,
 layout = c(3,1))


 ## end code




 Now the question:

 I would like the panels to be in the order of sigma, i. e. 5, 10, 30
 and not 10, 30 and 5 as is currently the case. Is this possible?

 Not to seek too much indulgence, but to ask anyway, I wonder if it is
 possible to have a Greek sigma = 5, a Greek sigma = 10 and a Greek
 sigma = 30. (Sort of what we would get using expression(sigma == 5),
 expression(sigma == 10), expression(sigma == 10) on base R figures).

 Please let me know if my question is not clear.

 Many thanks for any suggestions and help and best wishes!
 Ranjan

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org 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] Changing the y-axis units of a lattice histogram

2009-04-03 Thread Sundar Dorai-Raj
Try:

library(lattice)
histogram( ~ height | voice.part,
  data = singer, type = c,
  scales = list(y =
list(at = seq(0, 20, 5),
 labels = seq(0, 200, 50

HTH,

--sundar

On Fri, Apr 3, 2009 at 2:01 PM, Judith Flores jur...@yahoo.com wrote:

 Hello,

   I need to multiply the number of counts in the y-axis of a lattice 
 histogram by a constant factor, such that the plot would represent a 
 different type of variable plotted in the y-axis, not counts. Can this be 
 done?

 Thank you,

 Judith

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] labeling panels in lattice plots

2009-03-31 Thread Sundar Dorai-Raj
Try converting year to a factor

xyplot(min + max + ave ~ month | factor(year), data = rain.stats, ...)

Also, notice the inclusion of the data argument.

HTH,

--sundar

On Tue, Mar 31, 2009 at 6:28 AM,  steve_fried...@nps.gov wrote:

 I am using windows XP with R 2.8.1


 I am generating a lattice plot of annual rain patterns using the following
 function:


  xyplot(rain.stats$min+ rain.stats$max + rain.stats$ave ~
 rain.stats$month |rain.stats$year,
            lty = 1,  data = rain.stats,  type = c(l,l, l), col =
 c(red, blue, green), distribute.type = TRUE,
            main = Annual Monthly Minimum, Average and Maximum PPT)


 Each panel is labels with rain.stats$year  instead of the actual value
 referenced by this variable.

 the data.frame I'm using has the following form (year values range from
 1965 to 2000 and month from 1 to 12).

 dim(rain.stats)
 432 6

rain.stats[1:10,]
   year month X2    min    max       ave
 1  1965     1  1 0. 1.9196 0.3650112
 2  1966     1  1 2.1483 4.9615 3.5247034
 3  1967     1  1 0.4038 3.9145 1.7133045
 4  1968     1  1 0.2033 3.2119 1.1844769
 5  1969     1  1 1.2533 5.6226 2.9505545
 6  1970     1  1 0.9142 3.8861 2.6248453
 7  1971     1  1 0.1191 1.6109 0.6570289
 8  1972     1  1 0.2309 2.9380 0.9259674
 9  1973     1  1 0.9471 3.6342 1.9019848
 10 1974     1  1 0.1739 9.0225 1.0672980


 The plot illustrates exactly what I'm after with the exception of the panel
 labels.  I'm following an example in the Lattice Book by Deepayan Sarkar
 (which I find very informative  - thanks), but I'm not getting the results
 as per the example.

 Can anyone offer a solution?

 Thanks in advance.

 Steve






 Steve Friedman Ph. D.
 Spatial Statistical Analyst
 Everglades and Dry Tortugas National Park
 950 N Krome Ave (3rd Floor)
 Homestead, Florida 33034

 steve_fried...@nps.gov
 Office (305) 224 - 4282
 Fax     (305) 224 - 4147

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Can not get a prediction interval from Predict

2009-03-31 Thread Sundar Dorai-Raj
?predict.glm has no interval argument. Perhaps you're thinking of
?predict.lm, which is different.

To get intervals in glm, I've used:

example(predict.glm)
pr - predict(budworm.lg, se.fit = TRUE)
family - family(budworm.lg)
lower - family$linkinv(pr$fit - qnorm(0.95) * pr$se.fit)
upper - family$linkinv(pr$fit + qnorm(0.95) * pr$se.fit)

Note that these are confidence limits and not prediction limits.
The latter would require more thought.

You could also try RSiteSearch(glm interval).

HTH,

--sundar

On Tue, Mar 31, 2009 at 9:58 AM, Taylor Davis
taylor.da...@klasresearch.com wrote:
 I am trying to get a prediction interval from a glm regression.

 With newdat being my set of values to be fitted, and glmreg the name of my
 regression, I am using the following code.

 predict(glmreg, newdat, se.fit = TRUE, interval = confidence, level =
 0.90)

 The problem is that I am only getting the standard error and the fitted
 value, not a prediction interval.

 Any help would be great! Thanks so much.

 ___
 TAYLOR DAVIS    |
 KLAS
 taylor.da...@klasresearch.com    |    801.734.6279

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] use R Group SFBA April meeting reminder; video of Feb k

2009-03-30 Thread Sundar Dorai-Raj
Could be that you have some sort of ad filter in your browser that's
blocking the video? It appears just fine for me in Firefox 3.

On Mon, Mar 30, 2009 at 3:55 PM, Ted Harding
ted.hard...@manchester.ac.uk wrote:
 On 30-Mar-09 22:13:04, Jim Porzak wrote:
 Next week Wednesday evening, April 8th, Mike Driscoll will be talking
 about Building Web Dashboards using R
 see: http://www.meetup.com/R-Users/calendar/9718968/ for details  to
 RSVP.

 Also of interest, our member Ron Fredericks has just posted a well
 edited video of the February kickoff panel discussion at Predictive
 Analytics World The R and Science of Predictive Analytics: Four Case
 Studies in R with
     * Bo Cowgill, Google
     * Itamar Rosenn, Facebook
     * David Smith, Revolution Computing
     * Jim Porzak, The Generations Network
 and chaired by Michael Driscoll, Dataspora LLC

 see: http://www.lecturemaker.com/2009/02/r-kickoff-video/

 Best,
 Jim Porzak

 It could be very interesting to watch that video! However, I have
 had a close look at the web page you cite:

  http://www.lecturemaker.com/2009/02/r-kickoff-video/

 and cannot find a link to a video. Lots of links to non-video
 things, but none that I could see to a video.

 There is a link on that page at:
  How Google and Facebook are using R
  by Michael E. Driscoll | February 19, 2009
  http://dataspora.com/blog/predictive-analytics-using-r/

 Following that link leads to a page, on which the first link, in:

  (March 26th Update: Video now available)
  Last night, I moderated our Bay Area R Users Group kick-off
  event with a panel discussion entitled The R and Science of
  Predictive Analytics, co-located with the Predictive Analytics
  World conference here in SF.

 leads you back to where you came from, and likewise the link at
 the bottom of the page:

  A video of the event is now available courtesy of Ron Fredericks
  and LectureMaker.

 Could you help by describing where on that web page it can be found?
 With thanks,
 Ted.

 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 30-Mar-09                                       Time: 23:55:07
 -- XFMail --

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Requesting help with lattice again

2009-03-25 Thread Sundar Dorai-Raj
For the first question, add a groups argument. E.g.

barchart(HSI ~ Scenario | Region, Wbirdsm, groups = HydroState)

Also note that using Wbirdsm$HSI makes your call less readable, so I
added the data argument.

For your second question, setting the key does not set the color
theme. You want to set the colors using par.setting. E.g.

dotplot(HSI ~ Scenario | Region, Wbirdsm,
groups = HydroState,
par.settings = list(superpose.symbol =
  list(col = c(red, green, blue))),
auto.key = list(space = right))

Then use auto.key instead of key.

HTH,

--sundar

On Wed, Mar 25, 2009 at 7:02 AM,  steve_fried...@nps.gov wrote:

 Hello, this is a request for assistance that I submitted earlier, this time
 with the dataset. My mistake for taking up bandwidth.  I've also rephrased
 the question to address an additional concern.

 I'm working on a windows XP machine with R 2.8.1

 1).  I'd like a barchart (or other lattice type display) HSI ~ of the three
 factors (Region, Scenario and HydroState).
      However barchart complains

 library(reshape)
 library(lattice)

  barchart(Wbirdsm$HSI ~ WBirdsm$Scenario | WBridsm$Region)

  # This works, but only marginally.  I'd like specify the interaction
 between the variables ( Scenario and HydroState)
    What is the best way to combine these factors so they can be treated
 as a single variable and rewrite the barchart call?

  barchart(Wbirdsm$HSI ~ WBirdsm$interaction between Scenario and
 HydroState) ~ Wbirdsm$Region)



 The second question refers back to my original posting.
 2)  #  using dotplot instead of barchart I use the following code.

 key.variable - list(space = right, text =
 list(levels(wbirdm$variable)), points = list(pch = 1:3,
 col=c(red,green, blue)))
 dotplot(wbirdm$value  ~ wbirdm$variable | wbirdm$Region, col=c(1:9), pch=
 rep(c(1:3), key = key.variable,  groups=wbirdm$variable,     ylab= Mean
 HSI))

 # However the key legend doesn't appear in the plot with this sequence
 and the labels are too along the panels.  Is there a way to address this?


 thank you very much for the assistance.

 Steve


 This is part of the larger data base, after I passed it thru melt.



                                Region Species Scenario HydroState
 HSI
 1                    Eastern Panhandle  WBLong      NSM        Ave
 0.165945170
 2                    Eastern Panhandle  WBLong      NSM        Dry
 0.056244263
 3                    Eastern Panhandle  WBLong      NSM        Wet
 0.290692607
 4                    Eastern Panhandle  WBLong      ECB        Ave
 0.165945170
 5                    Eastern Panhandle  WBLong     ECB         Dry
 0.056244263
 6                    Eastern Panhandle  WBLong     ECB         Wet
 0.290692607
 7                    Eastern Panhandle  WBLong     CERP        Ave
 0.165945170
 8                    Eastern Panhandle  WBLong     CERP        Dry
 0.056244263
 9                    Eastern Panhandle  WBLong     CERP        Wet
 0.290692607
 10 Long Pine Key / South Taylor Slough  WBLong      NSM        Ave
 0.151159734
 11 Long Pine Key / South Taylor Slough  WBLong      NSM        Dry
 0.067348863
 12 Long Pine Key / South Taylor Slough  WBLong      NSM        Wet
 0.20738
 13 Long Pine Key / South Taylor Slough  WBLong      ECB        Ave
 0.151159734
 14 Long Pine Key / South Taylor Slough  WBLong     ECB         Dry
 0.067348863
 15 Long Pine Key / South Taylor Slough  WBLong     ECB         Wet
 0.20738
 16 Long Pine Key / South Taylor Slough  WBLong     CERP        Ave
 0.151159734
 17 Long Pine Key / South Taylor Slough  WBLong     CERP        Dry
 0.067348863
 18 Long Pine Key / South Taylor Slough  WBLong     CERP        Wet
 0.20738
 19              Northern Taylor Slough  WBLong      NSM        Ave
 0.115503291
 20              Northern Taylor Slough  WBLong      NSM        Dry
 0.005617136
 21              Northern Taylor Slough  WBLong      NSM        Wet
 0.252428530
 22              Northern Taylor Slough  WBLong      ECB        Ave
 0.115503291
 23              Northern Taylor Slough  WBLong     ECB         Dry
 0.005617136
 24              Northern Taylor Slough  WBLong     ECB         Wet
 0.252428530
 25              Northern Taylor Slough  WBLong     CERP        Ave
 0.115503291
 26              Northern Taylor Slough  WBLong     CERP        Dry
 0.005617136
 27              Northern Taylor Slough  WBLong     CERP        Wet
 0.252428530
 28                         East Slough  WBLong      NSM        Ave
 0.313215457
 29                         East Slough  WBLong      NSM        Dry
 0.046917053
 30                         East Slough  WBLong      NSM        Wet
 0.447002596
 31                         East Slough  WBLong      ECB        Ave
 0.313215457
 32                         East Slough  WBLong     ECB         Dry
 0.046917053
 33                         East Slough  WBLong     ECB         Wet
 0.447002596
 34                         East Slough  WBLong     CERP        

Re: [R] XYplot simple question

2009-03-16 Thread Sundar Dorai-Raj
Convert Plot to factor:

xyplot(AbvBioAnnProd ~ Year | Plot, type = c(b, r), pch = 16)

Also note that using the type argument with multiple values prevents
the necessity of a custom panel function.

HTH,

--sundar

On Mon, Mar 16, 2009 at 5:54 AM, AllenL allen.laroc...@gmail.com wrote:

 Hello R friends,
 Simple question today: I am desiring to do an xyplot with the below code,
 which graphs time series across different experimental Plots-

 xyplot(AbvBioAnnProd~Year|Plot)        ### Plots each monoculture biomass vs
 time
 xyplot(AbvBioAnnProd~Year|Plot,panel=function(x,y){
 panel.xyplot(x,y,type=b,pch=16)
 panel.abline(lm(y~x))
 })

 What I want to add are unique labels for each panel, where instead of all
 labeled plot with the slide-bar visual (although that is okay) I want
 the Plot number to appear (i.e. the value of Plot for that panel).

 This should be easy, right?
 -Al
 --
 View this message in context: 
 http://www.nabble.com/XYplot-simple-question-tp22537350p22537350.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] XYplot simple question

2009-03-16 Thread Sundar Dorai-Raj
Sorry, I should have

xyplot(AbvBioAnnProd ~ Year | factor(Plot), type = c(b, r), pch = 16)

On Mon, Mar 16, 2009 at 6:17 AM, Sundar Dorai-Raj sdorai...@gmail.com wrote:
 Convert Plot to factor:

 xyplot(AbvBioAnnProd ~ Year | Plot, type = c(b, r), pch = 16)

 Also note that using the type argument with multiple values prevents
 the necessity of a custom panel function.

 HTH,

 --sundar

 On Mon, Mar 16, 2009 at 5:54 AM, AllenL allen.laroc...@gmail.com wrote:

 Hello R friends,
 Simple question today: I am desiring to do an xyplot with the below code,
 which graphs time series across different experimental Plots-

 xyplot(AbvBioAnnProd~Year|Plot)        ### Plots each monoculture biomass vs
 time
 xyplot(AbvBioAnnProd~Year|Plot,panel=function(x,y){
 panel.xyplot(x,y,type=b,pch=16)
 panel.abline(lm(y~x))
 })

 What I want to add are unique labels for each panel, where instead of all
 labeled plot with the slide-bar visual (although that is okay) I want
 the Plot number to appear (i.e. the value of Plot for that panel).

 This should be easy, right?
 -Al
 --
 View this message in context: 
 http://www.nabble.com/XYplot-simple-question-tp22537350p22537350.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org 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] Get user system name

2009-03-16 Thread Sundar Dorai-Raj
Assuming USER is defined on your system then

Sys.getenv(USER)

ought to work.

--sundar

On Mon, Mar 16, 2009 at 3:04 PM, Etienne Bellemare Racine
etienn...@gmail.com wrote:
 I would like to get the name of the user form the system. Is it possible ?
 Something like
  system.user()
 returning something like
 [1] etber12

 Thanks,
 Etienne

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Get user system name

2009-03-16 Thread Sundar Dorai-Raj
If that's the case, it's best to post the output from version to
this thread. Type version from the R command prompt and paste the
results here.

On Mon, Mar 16, 2009 at 3:14 PM, Etienne Bellemare Racine
etienn...@gmail.com wrote:
 It seems like it is not defined. I get an empty string. Is there a
 workaround or another solution ?

 --
 Etienne

 Sundar Dorai-Raj a écrit :

 Assuming USER is defined on your system then

 Sys.getenv(USER)

 ought to work.

 --sundar

 On Mon, Mar 16, 2009 at 3:04 PM, Etienne Bellemare Racine
 etienn...@gmail.com wrote:


 I would like to get the name of the user form the system. Is it possible ?
 Something like
  system.user()
 returning something like
 [1] etber12

 Thanks,
 Etienne

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org 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] Matrix Construction; Subdiagonal

2009-03-11 Thread Sundar Dorai-Raj
Does this help?

A - matrix(0, 6, 6)
vec - 1:5
A[row(A) == col(A) + 1] - vec

--sundar

On Wed, Mar 11, 2009 at 4:42 PM, Stu Field s...@colostate.edu wrote:
 I'm trying to enter a vector into the subdiagonal of a matrix but
 cannot find a command in R which corresponds to the MatLab version of
 diag(vec, k), where vec = the vector of interest, and k = the diagonal
 (k=0 for the diagonal; k=-1 for the subdiagonal; k=1 for
 superdiagonal, etc.)
 Is there an equivalent command in R?

 I'm looking for something like this:
 vec = seq(1, 5, 1)        # vector of interest

 A = xyz(vec,-1)           # creates a 6x6 matrix with vec on the
 subdiagonal
 where xyz is some function similar to diag, but with differing
 arguments.

 I can't believe there is not a simple way to do this...
 Thanks for your help,

 ~~
 Stu Field, PhD
 Postdoctoral Fellow
 Department of Biology
 Colorado State University
 1878 Campus Delivery
 Fort Collins, CO 80523-1878
 Office: E208 Anatomy/Zoology
 Phone: (970) 491-5744
 ~~





        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Matrix Construction; Subdiagonal

2009-03-11 Thread Sundar Dorai-Raj
You can always write your own function:

myDiag - function(x, vec, k) {
  x[row(x) == col(x) - k] - vec
  x
}

myDiag(A, vec, -1)

Of course, you should probably do some input checking too.

--sundar

On Wed, Mar 11, 2009 at 4:57 PM, Stu Field s...@colostate.edu wrote:
 Sure, that'll work fine, thanks.
 But I guess I was looking for something more similar to MatLab, I'm really
 surprised R doesn't have a preset command for this (?)
 Thanks again,
 Stu
 On 11 • Mar • 2009, at 5:49 PM, Sundar Dorai-Raj wrote:

 Does this help?

 A - matrix(0, 6, 6)
 vec - 1:5
 A[row(A) == col(A) + 1] - vec

 --sundar

 On Wed, Mar 11, 2009 at 4:42 PM, Stu Field s...@colostate.edu wrote:

 I'm trying to enter a vector into the subdiagonal of a matrix but

 cannot find a command in R which corresponds to the MatLab version of

 diag(vec, k), where vec = the vector of interest, and k = the diagonal

 (k=0 for the diagonal; k=-1 for the subdiagonal; k=1 for

 superdiagonal, etc.)

 Is there an equivalent command in R?

 I'm looking for something like this:

 vec = seq(1, 5, 1)        # vector of interest

 A = xyz(vec,-1)           # creates a 6x6 matrix with vec on the

 subdiagonal

 where xyz is some function similar to diag, but with differing

 arguments.

 I can't believe there is not a simple way to do this...

 Thanks for your help,

 ~~

 Stu Field, PhD

 Postdoctoral Fellow

 Department of Biology

 Colorado State University

 1878 Campus Delivery

 Fort Collins, CO 80523-1878

 Office: E208 Anatomy/Zoology

 Phone: (970) 491-5744

 ~~





        [[alternative HTML version deleted]]

 __

 R-help@r-project.org 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.


 ~~
 Stu Field, PhD
 Postdoctoral Fellow
 Department of Biology
 Colorado State University
 1878 Campus Delivery
 Fort Collins, CO 80523-1878
 Office: E208 Anatomy/Zoology
 Phone: (970) 491-5744
 ~~





__
R-help@r-project.org 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] Lattice: Customizing point-sizes with groups

2009-03-10 Thread Sundar Dorai-Raj
Try this:

xyplot(y ~ x, temp, groups = groups,
   par.settings = list(
 superpose.symbol = list(
   cex = c(1, 3),
   pch = 19,
   col = c(blue, red

See:

str(trellis.par.get())

for other settings you might want to change.

Also, you should drop the ; from all your scripts.

HTH,

--sundar

On Mon, Mar 9, 2009 at 6:49 PM, Paul Boutros paul.bout...@utoronto.ca wrote:
 Hello,

 I am creating a scatter-plot in lattice, and I would like to customize the
 size of each point so that some points are larger and others smaller.
  Here's a toy example:

 library(lattice);

 temp - data.frame(
        x = 1:10,
        y = 1:10,
        cex = rep( c(1,3), 5),
        groups = c( rep(A, 5), rep(B, 5) )
        );

 xyplot(y ~ x, temp, cex = temp$cex, pch = 19);

 This works just fine if I create a straight xy-plot, without groups.
  However when I introduce groupings the cex argument specifies the
 point-size for the entire group.  For example:

 xyplot(y ~ x, temp, cex = temp$cex, pch = 19, group = groups);

 Is it possible to combine per-spot sizing with groups in some way?  One
 work-around is to manually specify all graphical parameters, but I thought
 there might be a better way than this:

 temp$col - rep(blue, 10);
 temp$col[temp$groups == B] - red;
 xyplot(y ~ x, temp, cex = temp$cex, pch = 19, col = temp$col);

 Any suggestions/advice is much appreciated!
 Paul

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Lattice: Customizing point-sizes with groups

2009-03-10 Thread Sundar Dorai-Raj
Sorry, I missed your point the first time. Why not create a group for
each subset then?

xyplot(y ~ x, temp, groups = interaction(cex, groups),
   par.settings = list(
 superpose.symbol = list(
   cex = c(1, 2, 3, 4),
   pch = 19,
   col = c(blue, red, green, purple


On Tue, Mar 10, 2009 at 8:11 AM, Paul C. Boutros
paul.bout...@utoronto.ca wrote:
 Hi Sundar,

 Thanks for your help!  Unfortunately your code seems to give the same
 result.  Compare this:

 temp - data.frame(
       x = 1:10,
       y = 1:10,
       cex = rep( c(1,3), 5),
       col = c( rep(blue, 5), rep(red, 5) ),
       groups = c( rep(A, 5), rep(B, 5) )
       );

 xyplot(y ~ x, temp, groups = groups,
       par.settings = list(
         superpose.symbol = list(
           cex = c(1, 3),
           pch = 19,
           col = c(blue, red

 And this:
 xyplot(y ~ x, temp, cex = temp$cex, col = temp$col, pch = 19);

 Once I introduce groups, I lose the ability to customize individual
 data-points and seem only to be able to customize entire groups.

 Paul

 -Original Message-
 From: Sundar Dorai-Raj [mailto:sdorai...@gmail.com]
 Sent: Tuesday, March 10, 2009 5:49 AM
 To: paul.bout...@utoronto.ca
 Cc: r-help@r-project.org
 Subject: Re: [R] Lattice: Customizing point-sizes with groups

 Try this:

 xyplot(y ~ x, temp, groups = groups,
       par.settings = list(
         superpose.symbol = list(
           cex = c(1, 3),
           pch = 19,
           col = c(blue, red

 See:

 str(trellis.par.get())

 for other settings you might want to change.

 Also, you should drop the ; from all your scripts.

 HTH,

 --sundar

 On Mon, Mar 9, 2009 at 6:49 PM, Paul Boutros paul.bout...@utoronto.ca
 wrote:
 Hello,

 I am creating a scatter-plot in lattice, and I would like to customize the
 size of each point so that some points are larger and others smaller.
  Here's a toy example:

 library(lattice);

 temp - data.frame(
        x = 1:10,
        y = 1:10,
        cex = rep( c(1,3), 5),
        groups = c( rep(A, 5), rep(B, 5) )
        );

 xyplot(y ~ x, temp, cex = temp$cex, pch = 19);

 This works just fine if I create a straight xy-plot, without groups.
  However when I introduce groupings the cex argument specifies the
 point-size for the entire group.  For example:

 xyplot(y ~ x, temp, cex = temp$cex, pch = 19, group = groups);

 Is it possible to combine per-spot sizing with groups in some way?  One
 work-around is to manually specify all graphical parameters, but I thought
 there might be a better way than this:

 temp$col - rep(blue, 10);
 temp$col[temp$groups == B] - red;
 xyplot(y ~ x, temp, cex = temp$cex, pch = 19, col = temp$col);

 Any suggestions/advice is much appreciated!
 Paul

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org 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] 2 Simple Lattice Plot Questions

2009-03-10 Thread Sundar Dorai-Raj
Convert Year to a factor and both problems will be solved.

--sundar

On Tue, Mar 10, 2009 at 3:48 PM, jimdare jamesdar...@gmail.com wrote:

 Hi,

 I have created the plot below and have a few questions about changes.

 1) How do I change the Year title of each plot so it reads from the top
 2006,2007,2008,2009.
 2) How do I get rid of those vertical grey bars in the title bar of each
 plot?

 I apologise for my ignorance... one of those days :(

 James


 http://www.nabble.com/file/p22445242/PLOT.jpg
 --
 View this message in context: 
 http://www.nabble.com/2-Simple-Lattice-Plot-Questions-tp22445242p22445242.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] 2 Simple Lattice Plot Questions

2009-03-10 Thread Sundar Dorai-Raj
I don't believe Elena's suggestion will work. However, the following will:

xyplot(..., scales = list(y = list(at = seq(5, 25, 5

though you may need to extend the limits a little as well:

xyplot(..., ylim = lattice:::extend.limits(c(0, 30)))

and add the scales argument from the first example to place explicit
tick marks rather than let xyplot do so.

HTH,

--sundar

On Tue, Mar 10, 2009 at 7:04 PM, Elena Wilson ewil...@dbmcons.com.au wrote:
 Have you tried specifying the levels of y's you want to display, e.g. 
 ylim=c(0,5,10,15,20,30)?

  -Original Message-
 From:   r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]  
 On Behalf Of jimdare
 Sent:   Wednesday, 11 March 2009 12:50 PM
 To:     r-help@r-project.org
 Subject:        Re: [R] 2 Simple Lattice Plot Questions


 Thanks very much.    One other thing... see how the Y axis begins before 0.
 At first glance it appears that the 0's are actually worth something.  When
 I use ylim=c(0,30) I get the graph I want, but the tick marks show only
 5,10,15,20,25.  I want them to show 0,5,10,15,20,30.  Does anyone know how
 to change this setting?

 Cheers,






 jimdare wrote:

 Hi,

 I have created the plot below and have a few questions about changes.

 1) How do I change the Year title of each plot so it reads from the top
 2006,2007,2008,2009.
 2) How do I get rid of those vertical grey bars in the title bar of each
 plot?

 I apologise for my ignorance... one of those days :(

 James


  http://www.nabble.com/file/p22445242/PLOT.jpg


 --
 View this message in context: 
 http://www.nabble.com/2-Simple-Lattice-Plot-Questions-tp22445242p22447415.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org 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.
 --
 Message  protected by MailGuard: e-mail anti-virus, anti-spam and content 
 filtering.
 http://www.mailguard.com.au/mg


 https://login.mailguard.com.au/report/1x1TEaABIw/4soNUVnBh04s1coMEHC4LA/7.998

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Date conversion

2009-03-05 Thread Sundar Dorai-Raj
Hi,

There are possibly several ways to do this. My approach would be:

dates - strptime(as.character(DATE), %d%b%Y)
year - dates$year + 1900
week - floor(dates$yday/365 * 52)

HTH,

--sundar

On Thu, Mar 5, 2009 at 8:58 AM, Pele drdi...@yahoo.com wrote:

 Hi R users,

 I have a factor variable called date as shown below:  Can anyone share the
 best / most efficient way to extract year and week (e.g.  year = 2006, week
 = 52 for first record, etc..)?  My data set has 1 million records.

 DATE
 11DEC2006
 11SEP2006
 01APR2007
 02DEC2007


 Thanks in advance for any help!
 --
 View this message in context: 
 http://www.nabble.com/Date-conversion-tp22355788p22355788.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] lattice: remove box around a wireframe

2009-03-04 Thread Sundar Dorai-Raj
(Sorry for the repeat. Forgot to copy R-help)

Try,

test = data.frame(expand.grid(c(1:10), c(1:10)))
z = test[,1] + test[,2]
test = cbind(test, z)
names(test) = c(x, y, z)
require(lattice)
wireframe(z ~ x*y, data = test,
 par.settings = list(axis.line = list(col = transparent)),
 par.box = c(col = transparent) )

--sundar

On Wed, Mar 4, 2009 at 8:17 AM, Thomas Roth (geb. Kaliwe)
hamstersqu...@web.de wrote:
 #Hi,
 #
 #somebody knows how to  remove the outer box around a wireframe and reduce
 the height
 #
 #

 test = data.frame(expand.grid(c(1:10), c(1:10)))
 z = test[,1] + test[,2]
 test = cbind(test, z)
 names(test) = c(x, y, z)
 require(lattice)
 wireframe(z ~ x*y, data = test, par.box = c(col = transparent) )  #not
 this one but the remaining outer box.

 Thanks in advance

 Thomas Roth

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] levelplot help needed

2009-02-27 Thread Sundar Dorai-Raj
To reorder the y-labels, simply reorder the factor levels:

df - data.frame(x_label = factor(x_label),
 y_label = factor(y_label, rev(y_label)),
 values = as.vector(my.data))

Not sure about putting the strips at the bottom. A quick scan of
?xyplot and ?strip.default suggests that this is not possible, but I'm
sure Deepayan will correct me if I'm wrong (he often does).

--sundar

On Fri, Feb 27, 2009 at 5:51 AM, Antje niederlein-rs...@yahoo.de wrote:
 Hi there,

 I'm looking for someone who can give me some hints how to make a nice
 levelplot. As an example, I have the following code:

 # create some example data
 # --
 xl - 4
 yl - 10

 my.data - sapply(1:xl, FUN = function(x) { rnorm( yl, mean = x) })

 x_label - rep(c(X Label 1, X Label 2, X Label 3, X Label 4), each =
 yl)
 y_label - rep(paste(Y Label , 1:yl, sep=), xl)

 df - data.frame(x_label = factor(x_label),y_label = factor(y_label), values
 = as.vector(my.data))

 df1 - data.frame(df, group = rep(Group 1, xl*yl))
 df2 - data.frame(df, group = rep(Group 2, xl*yl))
 df3 - data.frame(df, group = rep(Group 3, xl*yl))

 mdf - rbind(df1,df2,df3)

 # plot
 # --

 graph - levelplot(mdf$values ~ mdf$x_label * mdf$y_label | mdf$group,
                                aspect = xy, layout = c(3,1),
                                scales = list(x = list(labels =
 substr(levels(factor(mdf$x_label)),0,5), rot = 45)))
            print(graph)

 # --


 (I need to put this strange x-labels, because in my real data the values of
 the x-labels are too long and I just want to display the first 10 characters
 as label)

 My questions:

 * I'd like to start with Y Label 1 in the upper row (that's a more general
 issue, how can I have influence on the order of x,y, and groups?)
 * I'd like to put the groups at the bottom

 Can anybody give me some help?

 Antje

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] lattice contourplot line types

2009-02-22 Thread Sundar Dorai-Raj
The only way I can figure out to do this is to use two calls to
panel.contourplot:

library(lattice)
x - seq(-2, 2, length = 20)
y - seq(-2, 2, length = 20)
grid - expand.grid(x=x, y=y)
grid$z - dnorm(grid$x) * dnorm(grid$y)
contourplot(z ~ x * y, grid,
panel = function(at, lty, col, ...) {
  at.o - at[seq(1, length(at), 2)]
  at.e - at[seq(2, length(at), 2)]
  panel.contourplot(at = at.o, lty = 1, col = blue, ...)
  panel.contourplot(at = at.e, lty = 4, col = red, ...)
},
at = pretty(grid$z, 10))

HTH,

--sundar

On Sun, Feb 22, 2009 at 12:45 PM, Andrew Beckerman
a.becker...@sheffield.ac.uk wrote:
 Dear all -

 I would like to adjust the line type of specific contours in contourplot
 from the lattice package, but it seems like lty does not take a list in the
 call.

 Here is my call to contourplot:

 contourplot(preds~size+trt|Size.Name,
data=pred.dat,layout=c(2,4),
at=c(0.025,0.5,0.975),
par.strip.text=list(cex=1.2),
scales=list(cex=0.5),
xlab=list(Size,cex=1.2),
ylab=list(Treatment,cex=1.2),
panel=function(x,y,z,...){
panel.contourplot(x,y,z,lwd=1,...)
panel.grid(h=-1,v=-1,col=grey,...)})

 I would like to specify lty=c(2,1,2) corresponding to the
 at=c(0.025,0.5,0.975), and have tried this in both the core part of the
 call, and in panel.countourplot.  However, it only recognises the first
 type.

 If there is no straightforward answer, I can provide the data.

 Best wishes,
 Andrew

 R version 2.8.1 (2008-12-22)
 i386-apple-darwin8.11.1

 locale:
 en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base

 other attached packages:
 [1] MASS_7.2-45 lattice_0.17-17

 loaded via a namespace (and not attached):
 [1] grid_2.8.1

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Uninstall question

2009-02-17 Thread Sundar Dorai-Raj
This is on the Mac FAQ:

http://cran.cnr.berkeley.edu/bin/macosx/RMacOSX-FAQ.html#How-can-R-for-Mac-OS-X-be-uninstalled_003f

HTH,

--sundar

On Tue, Feb 17, 2009 at 7:17 AM, ANJAN PURKAYASTHA
anjan.purkayas...@gmail.com wrote:
 I need to uninstall R 2.7.1 from my Mac. What is the best way to uninstall
 it? Simply delete the R icon in the Applications folder?
 Or is it more involved?
 TIA,
 Anjan

 --
 =
 anjan purkayastha, phd
 bioinformatics analyst
 whitehead institute for biomedical research
 nine cambridge center
 cambridge, ma 02142

 purkayas [at] wi [dot] mit [dot] edu
 703.740.6939

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Adding abline in Lattice graph

2009-02-12 Thread Sundar Dorai-Raj
Try:

coplot(lbxglu~lbxgh|eth, data = reg.dat.5,
   panel= function(...) {
panel.smooth(...)
panel.abline(h = 126, col = red)
panel.abline(v = 6.5, col = blue)
  },
  xlab=ABC, ylab=FBG)

Also note that you removed your with call and give coplot a data argument.

HTH,

--sundar

On Thu, Feb 12, 2009 at 3:41 PM, Veerappa Chetty chett...@gmail.com wrote:
 Hi,I would like add a horizontal line at 126 (col=red) and a vertical line
 at 6.5 ( col= blue) in each panel .How should I use the panel.abline
 function in the following code I am using:
 --
 library(lattice)
 with(reg.dat.5,coplot(lbxglu~lbxgh|eth,panel=panel.smooth,xlab=ABC,
 ylab=FBG))
 
 Thanks a lot.

 Professor of Family Medicine
 Boston University
 Tel: 617-414-6221, Fax:617-414-3345
 emails: chett...@gmail.com,vche...@bu.edu

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Adding abline in Lattice graph

2009-02-12 Thread Sundar Dorai-Raj
Sorry, that was my lack of understanding on how coplot works. Try the following:

coplot(lbxglu~lbxgh|eth, data = reg.dat.5,
   panel= function(...) {
 panel.smooth(...)
 abline(h = 126, col = red)
 abline(v = 6.5, col = blue)
  },
  xlab=ABC, ylab=FBG)

On Thu, Feb 12, 2009 at 3:49 PM, Sundar Dorai-Raj sdorai...@gmail.com wrote:
 Try:

 coplot(lbxglu~lbxgh|eth, data = reg.dat.5,
   panel= function(...) {
panel.smooth(...)
panel.abline(h = 126, col = red)
panel.abline(v = 6.5, col = blue)
  },
  xlab=ABC, ylab=FBG)

 Also note that you removed your with call and give coplot a data argument.

 HTH,

 --sundar

 On Thu, Feb 12, 2009 at 3:41 PM, Veerappa Chetty chett...@gmail.com wrote:
 Hi,I would like add a horizontal line at 126 (col=red) and a vertical line
 at 6.5 ( col= blue) in each panel .How should I use the panel.abline
 function in the following code I am using:
 --
 library(lattice)
 with(reg.dat.5,coplot(lbxglu~lbxgh|eth,panel=panel.smooth,xlab=ABC,
 ylab=FBG))
 
 Thanks a lot.

 Professor of Family Medicine
 Boston University
 Tel: 617-414-6221, Fax:617-414-3345
 emails: chett...@gmail.com,vche...@bu.edu

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org 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] changing settings on a barchart (lattice)

2009-02-11 Thread Sundar Dorai-Raj
Add the adj argument to panel.text to left (adj = 0) or right(adj =
1) justify the text. Add the font argument to change the font. See
?text.

--sundar

On Wed, Feb 11, 2009 at 1:25 PM, Dimitri Liakhovitski ld7...@gmail.com wrote:
 Thanks a lot, Sundar. I experimented somewhat and here is the code
 that works well - it allows me to modify most of the stuff I want to
 modify:

 p-as.vector(c(0.1, 0.2, 0.3, 0.4))
 names(p)-c(A,BB,,)
 barchart(~sort(p), main=list(Chart Title,cex=1),xlab=list(X axis
 title,cex=1),xlim=c(0,0.42),
layout = c(1,1),
stack = TRUE,
auto.key = list(points = FALSE, rectangles = TRUE, space = 
 top),
panel = function(y,x,...){
panel.grid(h = 0, v = -1, col = gray60, lty 
 =dotted)
panel.barchart(x,y,col=brown)
panel.text(x,y,label = round(x,2),cex=1)
}
 )

 One last question: How can I modify the way the value labels (those
 that are at the end of the bars) appear? Can I make them bold? Make
 them appear a bit to the right or to the left of where they currently
 are?
 Thanks a lot!

 Dimitri

 On Wed, Feb 11, 2009 at 12:46 PM, Sundar Dorai-Raj sdorai...@gmail.com 
 wrote:
 Pass a list to xlab and main for the font sizes:

 barchart(..., xlab = list(x-axis, cex = 2), main = list(title, cex = 2))

 For value labels and a grid you'll need a custom panel function:

 barchart(..., panel = function(x, y, ...) {
  panel.barchart(x, y, ...)
  panel.text(x, y, format(y), cex = 1.2)
  panel.grid(h = -1, v = -1)
 })

 This is untested, but I think it should get you started.

 --sundar

 On Wed, Feb 11, 2009 at 9:10 AM, Dimitri Liakhovitski ld7...@gmail.com 
 wrote:
 Hello!

 I apologize - I never used lattice before, so my question is probably
 very basic - but I just can't find the answer in the archive nor in
 the documentation:

 I have a named numeric vector p of 6 numbers (of the type 6 numbers
 with people's names to whom those numbers belong). I want a simple bar
 chart.

 I am doing:

 library(lattice)
 trellis.par.set(fontsize=list(text=12))  # Changes only axes font
 barchart(~sort(p),main=Text for main,xlab=Text for X axis,
 col=PrimaryColors[3])

 It works just fine.
 Question: Where how can I change such things as font size for X axis
 label (below the numbers), font size for Title, value labels (to label
 bars with actual numbers), add grids, etc.?

 Thanks a lot!

 --
 Dimitri Liakhovitski
 MarketTools, Inc.
 dimitri.liakhovit...@markettools.com

 __
 R-help@r-project.org 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.





 --
 Dimitri Liakhovitski
 MarketTools, Inc.
 dimitri.liakhovit...@markettools.com


__
R-help@r-project.org 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] Efficent way to create an nxn upper triangular matrix of one's

2009-02-11 Thread Sundar Dorai-Raj
Try

x - diag(n)
x[upper.tri(x)] - 1

On Wed, Feb 11, 2009 at 1:22 PM, Dale Steele dale.w.ste...@gmail.com wrote:
 The code below create an nxn upper triangular matrix of one's.  I'm
 stuck on finding a more efficient vectorized way - Thanks.  --Dale

 n - 9
 data - matrix(data=NA, nrow=n, ncol=n)
 data
 for (i in 1:n) {
data[,i] - c(rep(1,i), rep(0,n-i))
 }
 data

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] sapply

2009-02-08 Thread Sundar Dorai-Raj
I'm not sure what you really want, so perhaps a simple example would
help (i.e. what a sample of the input looks like and what the output
you need looks like). My guess would be

sapply(df, diff)

but again, I'm not sure.

--sundar

On Sun, Feb 8, 2009 at 4:24 PM, glenn g1enn.robe...@btinternet.com wrote:
 Newbie question sorry (have tried the help pages I promise)



 I have a dataframe (date,stockprice) say and looking how I might get the
 return of: dataframe (difference in days, change in stock price) using
 sapply - I require a very simple function and don't really want to go down
 the zoo and quant mod route



 Regards



 glenn


[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] subsets problem

2009-02-08 Thread Sundar Dorai-Raj
you can try

lapply(lapply(uniques, function(x) subset(df, date == x)), myfun)

or possibly more accurate (subset may be finicky due to scoping):

lapply(lapply(uniques, function(x) df[df$date == x, ]), myfun)

or use ?split

lapply(split(df, df$date), myfun)

HTH,

--sundar

On Sun, Feb 8, 2009 at 5:00 PM, glenn g1enn.robe...@btinternet.com wrote:
 Help with this much appreciated



 I have a large dataframe that I would like to subset where the constraint



 Test1 - subset(df, date == uniques[[1]]), where uniques is a list of dates
 that must be matched to create Test1.



 I would like to perform an operation on Test1 that results in a single
 column of data. So far so good.



 How do loop through all values in the uniques list (say there is 50),
 perform an operationon Test1Test50, and then bolt all the lists together
 in a single list please ?



 Regards





 Glenn




[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] Foreign function call

2009-02-04 Thread Sundar Dorai-Raj
You're missing that R_TSConv is an R object. You can use
stats:::R_TSConv to see the value. Not sure how this helps you though.

On Wed, Feb 4, 2009 at 10:08 AM,  rkevinbur...@charter.net wrote:
 Let me get more specific. I think it this can be answered then I can 
 translate the information to other calls. In the arima 'R' code there is a 
 reference to

 .Call(R_TSconv, a, b)

 If from the console I type:

 .Call(R_TSConv, c(1,-1), c(1,-1))

 I get:

 Error: object R_TSConv not found

 If I do

 getNativeSymbolInfo(R_TSConv)

 I get:

 Error in FUN(R_TSConv[[1L]], ...) : no such symbol R_TSConv

 What am I missing?

 Thank you.

 Kevin

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] color and fontfamily in lattice

2009-02-03 Thread Sundar Dorai-Raj
Try this:

dados - data.frame(varsep = factor(rep(1:2,10)),
i = runif(20))

library(lattice)
font.settings - list(
 font = 2,
 cex = 2,
 fontfamily = serif)
my.theme - list(
 box.umbrella = list(col = red),
 box.rectangle = list(col = purple),
 box.dot = list(col = blue, pch = 15),
 par.xlab.text = font.settings,
 par.ylab.text = font.settings,
 axis.text = font.settings)
bwplot(varsep ~ i, dados,
   xlab = names(dados)[1],
   ylab = names(dados)[2],
   panel = function(...) {
 panel.grid(v = -1, h = 0)
 panel.bwplot(...)
   },
   par.settings = my.theme)

Type trellis.par.get() at the R command line to see other parameters
you can change. To change the settings on all plots, you can remove
the par.settings from the call to bwplot and simply use:

trellis.par.set(theme = my.theme)

HTH,

--sundar


2009/2/3 Leandro Marino lean...@cesgranrio.org.br:




 Hi,
 I am having some problems using bwplot(lattice) in my data. I want change 
 some parameters:
 1) Fontfamily to serif
 2) The size of the font
 3) Put it in a bold face
 4) Change de color of the lines

 How can I do that?! Now, I am using this to plot my boxplot.
 dados - data.frame(varsep=as.factor(rep(1:2,10)),i=runif(20))
 bwplot(dados[,'varsep']~dados[,'i'],xlab=names(dados)[2],ylab=names(dados)[1],panel
  =function(...){panel.grid(v = -1, h = 
 0);panel.bwplot(...)},font=2,fontfamily='serif')

 Thanks for any help on advance and sorry about my English.










 Atenciosamente,
 Leandro Lins Marino
 Centro de Avaliação
 Fundação CESGRANRIO
 Rua Santa Alexandrina, 1011 - 2º andar
 Rio de Janeiro, RJ - CEP: 20261-903
 R (21) 2103-9600 R.:236
 0 (21) 8777-7907
 ( lean...@cesgranrio.org.br

 Aquele que suporta o peso da sociedade
é precisamente aquele que obtém
  as menores vantagens. (SMITH, Adam)

   Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO 
 AMBIENTE

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] xyplot with lowess curves

2009-02-02 Thread Sundar Dorai-Raj
You'll need a custom panel function. It would also help if you
provided a reproducible example:

xyplot (
  SnowLineElevation ~ Year | Model,
  data = data,
  panel = function(x, y, col, ...) {
col - ifelse(panel.number() == 1, red, green)
panel.xyplot(x, y, col = blue, ...)
panel.loess(x, y, col = col)
  },
  ylim = c(0,1800),
  pch = 21,
  xlab = 'Year',
  ylab = 'Snowline Elevation [m]'
)

Alternatively, you can use the group argument in conjunction with the panels:

xyplot(SnowLineElevation ~ Year | Model, data, groups = Model, type =
c(p, smooth))

if you want the points and the lines to be the same color.

--sundar

On Mon, Feb 2, 2009 at 10:20 AM, Hutchinson,David [PYR]
david.hutchin...@ec.gc.ca wrote:
 I am trying to change the attributes of the lowess lines fit to an
 xyplot command, but have been unsuccessful in my search of the online
 help. Right now, both the points and lowess line come out in the same
 color (blue). I am unsure how I can change the properties of the lowess
 line separately.

 xyplot (
  SnowLineElevation ~ Year | Model,
  data = data,
  ylim = c(0,1800),
  type = c('p','smooth'),
  col = 'blue',
  pch = 21,
  xlab = 'Year',
  ylab = 'Snowline Elevation [m]'
 )

 Any help would be much appreciated,

 Dave

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] xyplot with lowess curves

2009-02-02 Thread Sundar Dorai-Raj
Does this do what you want? The panel argument has the custom pane
function I referred to before.

Col - c(red, green, blue, purple)
xyplot (
 SnowLineElevation ~ Year | Model,
 data = d,
 panel = function(x, y, col, ...) {
   Col - Col[panel.number()]
   panel.xyplot(x, y, col = blue, ...)
   panel.loess(x, y, col = Col)
 },
 ylim = c(0,100),
 type = c('p','smooth'),
 col = 'blue',
 pch = 21,
 xlab = 'Year',
 ylab = 'Snowline Elevation [m]'
)

On Mon, Feb 2, 2009 at 12:18 PM, Hutchinson,David [PYR]
david.hutchin...@ec.gc.ca wrote:
 I haven't had much luck with a custom panel function; mainly because I
 don't truly understand how to embedd the functionality into the xyplot
 command.

 Here's a reproducible example if you can help out.

 Thanks,
 Dave

 library (lattice)

 d - NULL
 models - c('A','B','C','D')
 n = 100
 for (i in seq(along = models)){
  d - rbind(
d, data.frame (
  Model = models[i],
  Year = seq(1960, length.out=n, by = 1),
  SnowLineElevation = runif(n, 0, 100)
)
  )
 }

 xyplot (
  SnowLineElevation ~ Year | Model,
  data = d,
  ylim = c(0,100),
  type = c('p','smooth'),
  col = 'blue',
  pch = 21,
  xlab = 'Year',
  ylab = 'Snowline Elevation [m]'
 )

 -Original Message-
 From: Sundar Dorai-Raj [mailto:sdorai...@gmail.com]
 Sent: Monday, February 02, 2009 11:43 AM
 To: Hutchinson,David [PYR]
 Cc: r-help@r-project.org
 Subject: Re: [R] xyplot with lowess curves

 You'll need a custom panel function. It would also help if you provided
 a reproducible example:

 xyplot (
  SnowLineElevation ~ Year | Model,
  data = data,
  panel = function(x, y, col, ...) {
col - ifelse(panel.number() == 1, red, green)
panel.xyplot(x, y, col = blue, ...)
panel.loess(x, y, col = col)
  },
  ylim = c(0,1800),
  pch = 21,
  xlab = 'Year',
  ylab = 'Snowline Elevation [m]'
 )

 Alternatively, you can use the group argument in conjunction with the
 panels:

 xyplot(SnowLineElevation ~ Year | Model, data, groups = Model, type =
 c(p, smooth))

 if you want the points and the lines to be the same color.

 --sundar

 On Mon, Feb 2, 2009 at 10:20 AM, Hutchinson,David [PYR]
 david.hutchin...@ec.gc.ca wrote:
 I am trying to change the attributes of the lowess lines fit to an
 xyplot command, but have been unsuccessful in my search of the online
 help. Right now, both the points and lowess line come out in the same
 color (blue). I am unsure how I can change the properties of the
 lowess line separately.

 xyplot (
  SnowLineElevation ~ Year | Model,
  data = data,
  ylim = c(0,1800),
  type = c('p','smooth'),
  col = 'blue',
  pch = 21,
  xlab = 'Year',
  ylab = 'Snowline Elevation [m]'
 )

 Any help would be much appreciated,

 Dave

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org 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] Assigning colnames in loop

2009-02-02 Thread Sundar Dorai-Raj
It's always best to do this with list operations (e.g. lapply) rather
than a loop:

DF1 - split(DF, DF$male)
DF2 - lapply(DF1, function(x) {
  x2 - t(as.matrix(x[3:5], dimnames = list(levels(x$age), NULL)))
  as.data.frame(x2)
})

Then DF2[[0]] and DF2[[1]] are the data.frames you want.

HTH,

--sundar

On Mon, Feb 2, 2009 at 2:30 PM, Peter Jepsen p...@dce.au.dk wrote:
 Dear R-listers,

 I am trying to assign colnames to a data frame within a loop, but I keep
 getting a target of assignment expands to non-language object-error. I
 need to split up a large dataset into about 20 smaller ones, and I would
 like to assign colnames within the loop, so I won't have to type the
 same thing 20 times over.

 I have concocted this really goofy example which constructs two
 datasets:

 -
 male - rep(0:1, each=5)
 age - factor(c(10:14,10:14))
 DF - data.frame(male, age, res1=rnorm(10), res2=rnorm(10),
 res3=rnorm(10))

 for(n in 0:1) {
assign(paste(test,n, sep=.), as.data.frame(t(subset(DF,
 male==n, select=c(res1, res2, res3)
colnames(get(paste(test,n, sep=.))) -
 paste(age,levels(age), m, n, sep=) # This line gives an error.
assign(colnames(paste(test,n, sep=.))) -
 paste(age,levels(age), m, n, sep=) # This line gives the same
 error.
 }
 ---
 The following command assigns the right colnames to the 'test.0' data
 frame, but I want this line inside the loop so I won't have to type it
 20 times over.
 colnames(test.0) - paste(age,levels(age), m, 0, sep=)


 Thank you in advance for any assistance.
 Peter.

 sessionInfo()
 R version 2.8.1 (2008-12-22)
 i386-pc-mingw32

 locale:
 LC_COLLATE=Danish_Denmark.1252;LC_CTYPE=Danish_Denmark.1252;LC_MONETARY=
 Danish_Denmark.1252;LC_NUMERIC=C;LC_TIME=Danish_Denmark.1252

 attached base packages:
 [1] tools stats graphics  grDevices utils datasets  methods
 base

 other attached packages:
 [1] epiR_0.9-14 maptools_0.7-18 sp_0.9-29   foreign_0.8-30
 chron_2.3-28

 loaded via a namespace (and not attached):
 [1] grid_2.8.1  lattice_0.17-20

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] capturing stderr/stdout

2008-11-21 Thread Sundar Dorai-Raj

Hi, Prof. Ripley,

Thanks for the reply. Mostly I want to capture output as it is written 
to the stream. For example, I quite often do the following to view the 
progress of a log file from a computationally intensive script.


1. Open a console and type:

Rscript script.R  script.log

which directs both stdout and stderr to script.log

2. Open another console and type:

tail -f script.log

This way I get both the script's log file and its current progress.

I guess my question is: Is there a way to accomplish the tail -f 
command in R?


Thanks,

--sundar

Prof Brian Ripley said the following on 11/20/2008 11:43 PM:
I am not sure what the issue is here. Do you want to capture both stderr 
and stdout (use 21 in the command with an sh-like shell), or is the

problem that you don't get immediate output?

The latter is a Perl issue: you need to circumvent output buffering.
See e.g

http://perl.plover.com/FAQs/Buffering.html

Sundar Dorai-Raj wrote:

Hi,

I have an application in perl that prints some output to either stderr 
or stdout.


Here's an example:

# tmp.pl
print STDERR starting iterator\n;
for(my $i = 0; $i  100; $i++) {
  print $i . \n;
}

# tmp.R
con - pipe(perl tmp.pl)
r - readLines(con, n = -1)
close(con)

However, the second line stalls until the perl for-loop finishes. What 
I would like is to process each line as it comes. E.g. something like:


while(TRUE) {
  r - readLines(con, n = 1) # read one line
  if(r == 1) print(r)
  if(length(r) == 0) break
}

Of course, this won't work since I'm not calling readLines 
appropriately. Answers must work on Windows but may include cygwin 
utilities if necessary. Any advice would be appreciated. Version info 
at the end if it matters.


Thanks, --sundar


  version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  8.0
year   2008
month  10
day20
svn rev46754
language   R
version.string R version 2.8.0 (2008-10-20)

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

and provide commented, minimal, self-contained, reproducible code.





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] capturing stderr/stdout

2008-11-20 Thread Sundar Dorai-Raj

Hi,

I have an application in perl that prints some output to either stderr 
or stdout.


Here's an example:

# tmp.pl
print STDERR starting iterator\n;
for(my $i = 0; $i  100; $i++) {
  print $i . \n;
}

# tmp.R
con - pipe(perl tmp.pl)
r - readLines(con, n = -1)
close(con)

However, the second line stalls until the perl for-loop finishes. What I 
would like is to process each line as it comes. E.g. something like:


while(TRUE) {
  r - readLines(con, n = 1) # read one line
  if(r == 1) print(r)
  if(length(r) == 0) break
}

Of course, this won't work since I'm not calling readLines 
appropriately. Answers must work on Windows but may include cygwin 
utilities if necessary. Any advice would be appreciated. Version info at 
the end if it matters.


Thanks, --sundar


 version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  8.0
year   2008
month  10
day20
svn rev46754
language   R
version.string R version 2.8.0 (2008-10-20)

__
R-help@r-project.org 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] determining plot location in lattice

2008-11-08 Thread Sundar Dorai-Raj

Hi, Greg,

Thanks again for your reply. I looked at TkIdentify which lead me to 
plt, which with RSiteSearch(grid plt) lead me to gridBase::gridPLT. 
Here's my solution:



stopifnot(require(tkrplot),
  require(lattice),
  require(gridBase))
makePlot - function() {
  print(xyplot(1 ~ 1))
  if(click) {
trellis.focus(highlight = FALSE)
plt - gridPLT()
out - ((x  plt[1] || x  plt[2]) ||
(y  plt[3] || y  plt[4]))
cat(if(out) outside else inside, \n)
  }
}
clickPlot - function(x, y) {
  width  - as.numeric(tclvalue(tkwinfo(reqwidth, img)))
  height - as.numeric(tclvalue(tkwinfo(reqheight, img)))
  x - as.numeric(x)/width
  y - 1 - as.numeric(y)/height
  click - TRUE
  tkrreplot(img)
  click - FALSE
}
x - y - -1
click - FALSE
tt - tktoplevel()
img - tkrplot(tt, makePlot)
tkbind(img, 1, clickPlot)
tkpack(img)
tkwm.resizable(tt, 0, 0)


Greg Snow said the following on 11/7/2008 8:23 PM:

As far as R is concerned, the plot in tkrplot is being written to a file and 
therefore is not interactive.  So functions like grid.locator and trellis.focus 
are not going to work.

You need to use the Tk commands to determine where the mouse is and where a 
click occurred, then this needs to be converted to the coordinates of the 
trellis plot.  There are some examples of the first part in the TeachingDemos 
package, eg TkBrush, TkIdentify, TkApprox, and a couple of others (also the 
play.sudoku function in the Sudoku package).  These all work with base graphics 
rather than trellis/grid so will not help with the 2nd part.  Possibly 
something in the grid package can tell you the coordinates of the various 
viewports (but you need to save this information before the end of the plotting 
command because the information will probably be lost when the plot finishes).

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
801.408.8111



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
project.org] On Behalf Of Sundar Dorai-Raj
Sent: Friday, November 07, 2008 12:43 PM
To: r-help@r-project.org
Subject: [R] determining plot location in lattice

Hi,

I'm dealing with a lattice plot inserted into a tk widget and would
like
to know when a user has clicked on the plot area of a plot (i.e. inside
the axes). For example,

library(tkrplot)
library(lattice)
tt - tktoplevel()
makePlot - function() print(xyplot(1 ~ 1))
printCoords - function(x, y) print(c(x, y))
img - tkrplot(tt, makePlot)
tkbind(img, 1, printCoords)
tkpack(img)

I would like to know when a user clicks inside the axes, but don't know
how to determine where the plot region is. Essentially, this comes down
to answering the following question: Assuming the entire plot is on a
unit square, what are the coordinates of the plotting area?

This question is may seem unrelated to tkrplot, but outside of this
context I may not get answers that work. I have been playing with both
lattice::trellis.focus and grid::grid.locator to no avail.

Thanks,

--sundar

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-
guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] determining plot location in lattice

2008-11-07 Thread Sundar Dorai-Raj

Hi,

I'm dealing with a lattice plot inserted into a tk widget and would like 
to know when a user has clicked on the plot area of a plot (i.e. inside 
the axes). For example,


library(tkrplot)
library(lattice)
tt - tktoplevel()
makePlot - function() print(xyplot(1 ~ 1))
printCoords - function(x, y) print(c(x, y))
img - tkrplot(tt, makePlot)
tkbind(img, 1, printCoords)
tkpack(img)

I would like to know when a user clicks inside the axes, but don't know 
how to determine where the plot region is. Essentially, this comes down 
to answering the following question: Assuming the entire plot is on a 
unit square, what are the coordinates of the plotting area?


This question is may seem unrelated to tkrplot, but outside of this 
context I may not get answers that work. I have been playing with both 
lattice::trellis.focus and grid::grid.locator to no avail.


Thanks,

--sundar

__
R-help@r-project.org 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] tklistbox selection

2008-10-30 Thread Sundar Dorai-Raj
I solved this problem by adding exportselection = 0 to the call to 
tklistbox. I.e.


tb1 - tklistbox(tt, listvariable = tcl1,
 exportselection = 0,
 selectmode = multiple)

Thanks,

--sundar

Sundar Dorai-Raj said the following on 10/29/2008 5:56 PM:

Hi,

I'm posting yet another question about tcltk since I'm still struggling 
with the package. I'm trying to create a tklistbox and a ttkcombobox on 
the same parent and am having a problem. Here's an example:


library(tcltk)
tt - tktoplevel()
tcl1 - tclVar()
tcl2 - tclVar()
tclObj(tcl1) - letters[1:5]
tclObj(tcl2) - LETTERS[1]
tb1 - tklistbox(tt, listvariable = tcl1,
 selectmode = multiple)
tb2 - ttkcombobox(tt, values = LETTERS[1:2],
   textvariable = tcl2)
tkpack(tb1, tb2)

First, I select some values in the list box. But when I select a value 
from the combo box, the selection from the list box is no longer 
highlighted. Is this a bug or am I missing something in the 
documentation? My goal is to allow highlighted text simultaneously in 
both widgets.


Thanks,

--sundar

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

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] tklistbox selection

2008-10-29 Thread Sundar Dorai-Raj

Hi,

I'm posting yet another question about tcltk since I'm still struggling 
with the package. I'm trying to create a tklistbox and a ttkcombobox on 
the same parent and am having a problem. Here's an example:


library(tcltk)
tt - tktoplevel()
tcl1 - tclVar()
tcl2 - tclVar()
tclObj(tcl1) - letters[1:5]
tclObj(tcl2) - LETTERS[1]
tb1 - tklistbox(tt, listvariable = tcl1,
 selectmode = multiple)
tb2 - ttkcombobox(tt, values = LETTERS[1:2],
   textvariable = tcl2)
tkpack(tb1, tb2)

First, I select some values in the list box. But when I select a value 
from the combo box, the selection from the list box is no longer 
highlighted. Is this a bug or am I missing something in the 
documentation? My goal is to allow highlighted text simultaneously in 
both widgets.


Thanks,

--sundar

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] ttkcombobox

2008-10-27 Thread Sundar Dorai-Raj

Hi, all,

(sessionInfo at the end)

I've been struggling with the tcltk package and can't seem to get the 
ttkcombobox to work. Here's an example:


library(tcltk)
p - tktoplevel()
l - tclVar()
## I don't know if I'm even calling it correctly
cb - ttkcombobox(p, values = letters[1:4], textvariable = l)
tkpack(cb)

1. How do I know when the value of the combobox has been changed from, 
say, a to b?
2. How can I get the value of the box? E.g. if I switch the box to b, 
how can I access this value?
3. How can I set the default value to something of my choice? I've tried 
the set argument as described in the Tcl/Tk 8.5 Manual but I 
received an error:

cb - ttkcombobox(p, values = letters[1:4], textvariable = l, set = b)
Error in structure(.External(dotTclObjv, objv, PACKAGE = tcltk), 
class = tclObj) :

  [tcl] unknown option -set.

Thanks,

--sundar

 sessionInfo()
R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252


attached base packages:
[1] tcltk stats graphics  grDevices utils datasets  methods
[8] base

__
R-help@r-project.org 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] ttkcombobox

2008-10-27 Thread Sundar Dorai-Raj

Hi, Greg,

Yes, that helps immensely!

Thanks,

--sundar

Greg Snow said the following on 10/27/2008 7:14 PM:

Here is one example of using ttkcombobox, hopefully it helps:

library(tcltk)

have.ttk - function () { # from Prof. Ripley
as.character(tcl(info, tclversion)) = 8.5
}


testfunc - function() {
tt - tktoplevel()
if( !have.ttk() ) stop( Need version 8.5 or greater of tcl )

tkpack(tklabel(tt, text='Choose a package'), side='top')

tmp - tclVar()
tclvalue(tmp) - 'TeachingDemos'

tkpack(ttkcombobox( tt, values=c('blockrand',
'ObsSens','TeachingDemos','sudoku'), textvariable=tmp ),
side='left' )

tkpack(tkbutton(tt,text='print',command=function() 
print(tclvalue(tmp
tkpack(tkbutton(tt,text='exit', command=function() 
tkdestroy(tt)),side='right')
}


testfunc()

If you want something to happen when you change the combobox (rather than just 
getting the value when you press a button or something else), then you will 
probably have to use tkbind to bind an event to it, or use tkafter to check it 
on a regular basis.  I usually do as above and just have a button or something 
else run the code when I want and it just gets the current value.

Hope this helps,


--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
801.408.8111



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
project.org] On Behalf Of Sundar Dorai-Raj
Sent: Monday, October 27, 2008 3:02 PM
To: r-help@r-project.org
Subject: [R] ttkcombobox

Hi, all,

(sessionInfo at the end)

I've been struggling with the tcltk package and can't seem to get the
ttkcombobox to work. Here's an example:

library(tcltk)
p - tktoplevel()
l - tclVar()
## I don't know if I'm even calling it correctly
cb - ttkcombobox(p, values = letters[1:4], textvariable = l)
tkpack(cb)

1. How do I know when the value of the combobox has been changed from,
say, a to b?
2. How can I get the value of the box? E.g. if I switch the box to b,
how can I access this value?
3. How can I set the default value to something of my choice? I've
tried
the set argument as described in the Tcl/Tk 8.5 Manual but I
received an error:
cb - ttkcombobox(p, values = letters[1:4], textvariable = l, set =
b)
Error in structure(.External(dotTclObjv, objv, PACKAGE = tcltk),
class = tclObj) :
   [tcl] unknown option -set.

Thanks,

--sundar

  sessionInfo()
R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] tcltk stats graphics  grDevices utils datasets  methods
[8] base

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-
guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org 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] using bquote to construct function

2008-10-02 Thread Sundar Dorai-Raj

Thanks, Gabor! This workaround fixes my immediate needs.

--sundar

Gabor Grothendieck said the following on 10/1/2008 10:42 PM:

That may be a bug in R but I think there is another problem on top of that
as I don't think bquote descends into function bodies:


z - 2
bquote(function(x) {x^.(z)})

function(x) {x^.(z)}


bquote(function(x, y) { x^.(z) + y})

function(x, y) { x^.(z) + y}


R.version.string # Vista

[1] R version 2.7.2 (2008-08-25)

Try it this way:

z - 2
f - function(x, y) {}
body(f) - bquote({ x^.(z) + y })
eval(f)(2, 3)

On Thu, Oct 2, 2008 at 1:14 AM, Sundar Dorai-Raj
[EMAIL PROTECTED] wrote:

Hi, R-help,

(sessionInfo at the end)

I'm trying to construct a function using bquote and running into a strange
error message. As an example, what I would like to do is this:

z - 2
eval(bquote(function(x, y) { x^.(z) + y }))(2, 3)

However, I get the following:

Error in eval(expr, envir, enclos) :
 invalid formal argument list for function

However, if I change the command to following, it works:

z - 2
eval(bquote(function(x) { x^.(z) }))(2)
# [1] 4

In other words, I remove the second argument. Is there a workaround for this
without using eval(parse(text = ))?

Thanks,

--sundar


sessionInfo()

R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] using bquote to construct function

2008-10-01 Thread Sundar Dorai-Raj

Hi, R-help,

(sessionInfo at the end)

I'm trying to construct a function using bquote and running into a 
strange error message. As an example, what I would like to do is this:


z - 2
eval(bquote(function(x, y) { x^.(z) + y }))(2, 3)

However, I get the following:

Error in eval(expr, envir, enclos) :
  invalid formal argument list for function

However, if I change the command to following, it works:

z - 2
eval(bquote(function(x) { x^.(z) }))(2)
# [1] 4

In other words, I remove the second argument. Is there a workaround for 
this without using eval(parse(text = ))?


Thanks,

--sundar

 sessionInfo()
R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252


attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

__
R-help@r-project.org 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] use expression() in a loop

2008-08-18 Thread Sundar Dorai-Raj



Nanye Long said the following on 8/18/2008 3:00 PM:

Hi all,

I want to do plot() in a loop to make 10 graphs, so I have some code like

for (i in 1:10) {
   plot(... ... , xlab = expression(g[i]) )
}

I expect g_1, g_2, and so on appear on x labels, but it simply prints
g_i for each graph. Does anybody know how to get around this problem?
Thanks.

NL

__
R-help@r-project.org 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.


Try:

par(mfrow = c(2, 5))
for (i in 1:10) {
  plot(1, 1, xlab = bquote(g[.(i)]))
}

HTH,

--sundar

__
R-help@r-project.org 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] upgrade to 2.5

2008-07-31 Thread Sundar Dorai-Raj


Iasonas Lamprianou said the following on 5/2/2007 8:25 AM:
 Hi I am using R version 2.4.1. How can I upgrade to version 2.5 without 
 having to install all the packages again? 
 Thanks
 Jason
  

You may find the following link relevant.

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/75359.html

HTH,

--sundar

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

__
R-help@r-project.org 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] Accessing items in a list of lists

2008-05-14 Thread Sundar Dorai-Raj
[EMAIL PROTECTED] said the following on 5/14/2008 
12:40 PM:

Using R 2.6.2, say I have the following list of lists, comb:

data1 - list(a = 1, b = 2, c = 3)
data2 - list(a = 4, b = 5, c = 6)
data3 - list(a = 3, b = 6, c = 9)
comb - list(data1 = data1, data2 = data2, data3 = data3)

So that all names for the lowest level list are common.  How can I most
efficiently access all of the sublist items a indexed by the outer
list names?  For example, I can loop through comb[[i]], unlisting as I
go, and then look up the field a, as below, but there has got to be a
cleaner way.

finaldata - double(0)
for(i in 1:length(names(comb))) {
test - unlist(comb[[i]])
finaldata - c(finaldata, test[which(names(test) == a)])
}
data.frame(names(comb), finaldata)

Gives what I want:
  names.comb. finaldata
1   data1 1
2   data2 4
3   data3 3

Any help you can give would be greatly appreciated.  Thanks.


Try

data.frame(names.comb = names(comb),
   finaldata = sapply(comb, [[, a))

HTH,

--sundar

__
R-help@r-project.org 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] as.numeric with tclvalue redux

2008-03-24 Thread Sundar Dorai-Raj


Erin Hodgess said the following on 3/24/2008 10:39 AM:
 Hi again R People:
 
 This works fine:
 library(tcltk)
 a - tclVar(4.5)
 as.numeric(tclvalue(a))
 [1] 4.5
 #But if you have:
 b - tclVar(pi)
 as.numeric(tclvalue(b))
 [1] NA
 Warning message:
 NAs introduced by coercion
 
 Is anyone aware of a way around this, please?
 
 thanks,
 Erin
 
 

Does this help?

eval.tclvalue - function(x, ...) {
   x - type.convert(tclvalue(x), as.is = TRUE)
   if(is.character(x)  exists(x, ...)) {
 get(x)
   } else {
 x
   }
}

a - tclVar(4.5)
b - tclVar(pi)
c - tclVar(abcd)

eval.tclvalue(a)
eval.tclvalue(b)
eval.tclvalue(c)

HTH,

--sundar

__
R-help@r-project.org 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] Lme does not work without a random effect (UNCLASSIFIED)

2008-03-14 Thread Sundar Dorai-Raj


Park, Kyong H Mr ECBC said the following on 3/14/2008 12:25 PM:
 Classification:  UNCLASSIFIED 
 Caveats: NONE
 
 Dear R users,
 
 I'm interested in finding a random effect of the Block in the data shown
 below, but 'lme' does not work without the random effect. I'm not sure how
 to group the data without continuous value which is shown in the error
 message at the bottom line. If I use 'aov' with Error(Block), is there a
 test method comparing between with and without the Block random effect. I'm
 using R 2.4.1.
 
 Appreciate your help.
 
 Kyong  
 
  LCU ST1 SURF Block
 1  6.71   AN 1
 2  6.97   AY 1
 3  6.77   BN 1
 4  6.90   BY 1
 5  6.63   CN 1
 6  6.94   CY 1
 7  6.79   DN 1
 8  6.93   DY 1
 9  6.23   AN 2
 10 6.83   AY 2
 11 6.61   BN 2
 12 6.86   BY 2
 13 6.51   CN 2
 14 6.90   CY 2
 15 5.90   DN 2
 16 6.97   DY 2
 
 A result with the random effect:
 
 Anal1-lme(LCU~ST1*SURF,random=~1|Block,data=data1)
 summary(Anal1)
 Linear mixed-effects model fit by REML
  Data: data1 
AIC  BIClogLik
   25.38958 26.18399 -2.694789
 
 Random effects:
  Formula: ~1 | Block
 (Intercept) Residual
 StdDev:   0.1421141 0.218483
 
 Fixed effects: LCU ~ ST1 * SURF 
  Value Std.Error DF  t-value p-value
 (Intercept)  6.470 0.1842977  7 35.10625  0.
 ST1B 0.220 0.2184830  7  1.00694  0.3475
 ST1C 0.100 0.2184830  7  0.45770  0.6610
 ST1D-0.125 0.2184830  7 -0.57213  0.5851
 SURFY0.430 0.2184830  7  1.96812  0.0897
 ST1B:SURFY  -0.240 0.3089816  7 -0.77675  0.4627
 ST1C:SURFY  -0.080 0.3089816  7 -0.25892  0.8031
 ST1D:SURFY   0.175 0.3089816  7  0.56638  0.5888
 
 Without the random effect:
 
 Anal2-lme(LCU~ST1*SURF,data=data1)
 Error in getGroups.data.frame(dataMix, groups) : 
 Invalid formula for groups
 Classification:  UNCLASSIFIED 
 Caveats: NONE
 
 

Use lm to fit the model without random effect and use anova to compare:

z - read.table(con - textConnection( LCU ST1 SURF Block
1  6.71   AN 1
2  6.97   AY 1
3  6.77   BN 1
4  6.90   BY 1
5  6.63   CN 1
6  6.94   CY 1
7  6.79   DN 1
8  6.93   DY 1
9  6.23   AN 2
10 6.83   AY 2
11 6.61   BN 2
12 6.86   BY 2
13 6.51   CN 2
14 6.90   CY 2
15 5.90   DN 2
16 6.97   DY 2), header = TRUE)
close(con)

library(nlme)
fit - lme(LCU~ST1*SURF,random=~1|Block,data=z)
fit0 - lm(LCU~ST1*SURF,data=z)
anova(fit, fit0)

HTH,

--sundar

__
R-help@r-project.org 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] Distances between two datasets of x and y co-ordinates

2008-03-12 Thread Sundar Dorai-Raj


Andrew McFadden said the following on 3/12/2008 1:47 PM:
 Hi all
 
 I am trying to determine the distances between  two datasets of x and y
 points. The number of points in dataset One is very small i.e. perhaps
 5-10. The number of points in dataset Two is likely to be very large
 i.e. 20,000-30,000. My initial approach was to append the first dataset
 to the second and then carry out the calculation:
 
 dists - as.matrix(dist(gis data from 2 * datasets)) 
 
 However, the memory of the computer is not sufficient. A lot of
 calculations carried out in this situation are unnecessary as I only
 want approx 5 * 20,000 calculations versus 20,000 *20,000. 
 
 x - c(2660156,2663703,2658165,2659303,2661531,2660914)
 y - c(6476767,6475013,6475487,6479659,6477004,6476388)
 data2-cbind(x,y)
 
 x - c(266500,261)
 y - c(6478767,6485013)
 data1-cbind(x,y)
 
 Any suggestions on how to do this would be appreciated.
 
 Regards
 
 Andrew

If you're trying to find only the closest point in data1 to data2, then 
use knn (or knn1) in the 'class' package:

library(class)
nn - knn1(data2, data1, 1:nrow(data2))

which gives you the rows in data1 closest to each row in data2. Then 
compute the distance:

rowSums((data2[nn, ] - data1)^2)^0.5

HTH,

--sundar

__
R-help@r-project.org 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] LaTeX in R

2008-03-07 Thread Sundar Dorai-Raj
Or my personal favorite if the length of mySigma is variable:

mySigma - 2:3
plot(1:10, dnorm(1:10, sd = mySigma[1]), type = 'l')
lines(dnorm(1:10,sd = mySigma[2]),lty = 2)
leg - as.expression(lapply(mySigma, function(x) bquote(sigma == .(x
legend(x = topright, lty = c(1,2),legend = leg)

Thanks,

--sundar

Uwe Ligges said the following on 3/7/2008 8:15 AM:
 You might want to read
   Ligges, U. (2002): R Help Desk: Automation of Mathematical Annotation 
 in Plots. R News 2 (3), 32-34.
 with an example at the end that meets your requirements:
 
 (please note that I removed those ugly ;
 
 
 mySigma[1] - 2
 mySigma[2] - 3
 plot(1:10, dnorm(1:10, sd = mySigma[1]), type = 'l')
 lines(dnorm(1:10, sd = mySigma[2]), lty = 2)
 legend1 - substitute(sigma == myS, list(myS = mySigma[1]))
 legend2 - substitute(sigma == myS, list(myS = mySigma[2]))
 legend(x = topright, lty = c(1,2),
 legend = do.call(expression, list(legend1, legend2)))
 
 
 Uwe Ligges
 
 
 
 Mario Maiworm wrote:
 Finally, this should work for an array of sigmas. I just realized that the
 substitute()-command is not evaluated within a c()-environment :(

 mySigma[1] - 2; mySigma[2] - 3;
 plot(1:10, dnorm(1:10, sd = mySigma[1]), type = 'l') ;
 lines(dnorm(1:10,sd = mySigma[2]),lty = 2);
 legend(x = topright, lty = c(1,2),legend = c(substitute(sigma == myS,
 list(myS = mySigma[1])),substitute(sigma == myS, list(myS = mySigma[2]

 Mario.

  
 __

 Mario Maiworm
 Biological Psychology and Neuropsychology
 University of Hamburg
 Von-Melle-Park 11
 D-20146 Hamburg

 Tel.: +49 40 42838 3515
 Fax.: +49 40 42838 6591

 http://bpn.uni-hamburg.de/Maiworm_e.html
 http://cinacs.org
 __

 -Ursprüngliche Nachricht-
 Von: Uwe Ligges [mailto:[EMAIL PROTECTED]
 Gesendet: Freitag, 7. März 2008 16:30
 An: Mario Maiworm
 Cc: r-help@r-project.org
 Betreff: Re: AW: [R] LaTeX in R



 Mario Maiworm wrote:
 Thank you, uwe and jeremy. I was actually looking exactly for that!
 But
 something still doesn't work:
 I want to plot a symbol in a legend of a plot, lets say \sigma = 2.
 2
 should be the value of a variable. So, when I try

 mySigma=2;plot(1:10,dnorm(1:10,sd=mySigma),type='l')
 legend(x=topright,legend=paste(expression(sigma), =
 ,mySigma),lty=1)
 , the sigma is not plotted as a symbol. This version:

 mySigma=2;plot(1:10,dnorm(1:10,sd=mySigma),type='l')
 legend(x=topright,legend=expression(paste(sigma, =
 ,mySigma)),lty=1)
 gives me a 'real' sigma but the mySigma variable is not evaluated. Any
 ideas?
 Yes:


 mySigma - 2
 plot(1:10, dnorm(1:10, sd = mySigma), type='l')
 legend(x = topright, lty = 1,
 legend = substitute(sigma == myS, list(myS = mySigma)))


 Uwe Ligges


 Mario.

 __

 Mario Maiworm
 Biological Psychology and Neuropsychology
 University of Hamburg
 Von-Melle-Park 11
 D-20146 Hamburg

 Tel.: +49 40 42838 3515
 Fax.: +49 40 42838 6591

 http://bpn.uni-hamburg.de/Maiworm_e.html
 http://cinacs.org
 __

 -Ursprüngliche Nachricht-
 Von: Uwe Ligges [mailto:[EMAIL PROTECTED]
 Gesendet: Freitag, 7. März 2008 15:27
 An: Mario Maiworm
 Cc: r-help@r-project.org
 Betreff: Re: [R] LaTeX in R



 Mario Maiworm wrote:
 Dear Rers,
 I understand that I can include R-code in LaTeX using Sweave. Is
 there
 a way
 to do it the other way round? Particularly, I need some TeX
 symbols in
 the
 legend of an R-plot. This can be done in matlab easily, so I am
 optimistic
 with R. Any suggestions for a command or package?
 See   ?plotmath

 Uwe Ligges




 Best,
 Mario.



 __

 Mario Maiworm
 Biological Psychology and Neuropsychology
 University of Hamburg
 Von-Melle-Park 11
 D-20146 Hamburg

 Tel.: +49 40 42838 3515
 Fax.: +49 40 42838 6591

 http://bpn.uni-hamburg.de/Maiworm_e.html
 http://cinacs.org

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org 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] wire.frame tick labels from matrix

2008-02-15 Thread Sundar Dorai-Raj


Marlin Keith Cox said the following on 2/15/2008 11:39 AM:
 Dear R Users, close to the end of this I used wireframe to create a 3D plot
 from a matrix.  The x and y axis tick labels (1-6) for each were created
 from the matrix being a 6X6 matrix. I need the axis tick labels to be the
 row and column headings which you can see in the output (mat.x).  I have
 tried several work arounds, but they have not been successful.
 
 Thanks in advance. keith
 
 
 rm(list=ls())
 sen-read.csv(brooktroutsort.csv)
 
 #Resistance
 R=c(660, 548, 676, 763, 768, 692, 657, 630, 748, 680, 786, 645, 710, 677,
 692, 732, 737, 651, 396,
 601, 640, 448, 464, 472, 434, 487, 495, 426, 429, 456)
 
 #Detector length
 Lend=c(37.0,  39.0,  39.0,  39.0,  40.0,  41.5,  44.0,  45.0,  46.0,  47.0,
 47.0,  48.0,
 48.5,  49.0,  51.0,  53.0, 53.0,  60.0,  89.0, 103.0, 108.5, 118.0, 118.0,
 123.0,
 126.0, 138.0, 139.0, 141.0, 141.0, 151.0)
 
 #Errors to be multiplied by Restistance
 x=c(0,.05,.10,.15,.20,.25)
 
 #Errors to be multiplied by Detector length
 y=c(0,.01,.02,.03,.04,.05)
 
 #equation to predict water weight in grams
 a=3.453*((Lend^2)/R)+1.994
 
 X=(R%o%x+R)
 
 Y=((Lend%o%y+Lend)^2)
 
 num.x.col - length(X[1,])
 num.y.col - length(Y[1,])
 num.rows - length(X[,1])
 
 Z - matrix(nrow=num.rows, ncol=num.x.col*num.y.col)
 
 for( i in 1:num.rows)  {
Z[i,] - as.vector( Y[i,] %*% t(X[i,])^-1 )
 }
 
 pred.est - 3.453*Z+1.994
 z=(pred.est-a)/a
 
 colnames(z)- rep(c(X1,X2,X3,X4,X5,X6),6)
 
 meanz=colMeans(z)
 mat.x - matrix(meanz, nrow=6, ncol=6, byrow=TRUE)
 
 colnames(mat.x)- c(0,1,2,3,4,5)
 rownames(mat.x)-c(0,5,10,15,20,25)
 mat.x
 
 
 library(lattice)
 wireframe(mat.x,drape=TRUE,zlab=list(Proportion Error of Estimate,
 rot=90), xlab=Resistance Error (%) ,ylab=Length Error
 (%),scale=list(arrows=FALSE))
 detach(z)
 detach(sen)
 
 

Try:

mat.df - data.frame(z = as.vector(mat.x))
mat.df$x - rep(c(0,5,10,15,20,25), each = 6)
mat.df$y - rep(c(0,1,2,3,4,5), times = 6)

library(lattice)
wireframe(z ~ x * y, mat.df,
   drape = TRUE,
   zlab = list(Proportion Error of Estimate, rot=90),
   xlab = Resistance Error (%) ,
   ylab = Length Error (%),
   scales = list(arrows = FALSE))

HTH,

--sundar

__
R-help@r-project.org 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] fun.aggregate=mean in reshape

2008-02-12 Thread Sundar Dorai-Raj


[Ricardo Rodriguez] Your XEN ICT Team said the following on 2/12/2008 
12:23 AM:
 Hi all,
 
 We are facing a problem while introducing ourselves to Reshape package 
 use. Melt seems to work fine, but cast fails when we use mean as 
 fun.aggregate. As you see here, length and sum work fine, but mean 
 throws this same error whatever dataset we use.
 
   cast(aqm, month ~ variable, length)
   month ozone solar.r wind temp
 1 526  27   31   31
 2 6 9  30   30   30
 3 726  31   31   31
 4 826  28   31   31
 5 929  30   30   30
   cast(aqm, month ~ variable, sum)
   month ozone solar.r  wind temp
 1 5   6144895 360.3 2032
 2 6   2655705 308.0 2373
 3 7  15376711 277.2 2601
 4 8  15594812 272.6 2603
 5 9   9125023 305.4 2307
   cast(aqm, month ~ variable, mean)
 Error in get(as.character(FUN), mode = function, envir = envir) :
   variable fun of mode function was not found
  
 
 
 Our environment:
 
   version
_  
 platform   i386-apple-darwin8.10.1
 arch   i386   
 os darwin8.10.1   
 system i386, darwin8.10.1 
 status
 major  2  
 minor  6.2
 year   2008   
 month  02 
 day08 
 svn rev44383  
 language   R  
 version.string R version 2.6.2 (2008-02-08)
 
 
   installed.packages()
 
 reshapereshape
 /Library/Frameworks/R.framework/Resources/library 0.8.0   
 NANA
 
 
 Please, could you help use to work out this issue? Thanks!
 

Do you have an object called 'mean' that's masking the base::mean 
function? I can replicate your error using the following:

  library(reshape)
  names(airquality) - tolower(names(airquality))
  aqm - melt(airquality, id=c(month, day), na.rm=TRUE)
  mean - 1
  cast(aqm, month ~ variable, mean)
Error in get(as.character(FUN), mode = function, envir = envir) :
   variable fun of mode function was not found
  cast(aqm, month ~ variable, base::mean)
   monthozone  solar.r  wind temp
1 5 23.61538 181.2963 11.622581 65.54839
2 6 29.4 190.1667 10.27 79.1
3 7 59.11538 216.4839  8.941935 83.90323
4 8 59.96154 171.8571  8.793548 83.96774
5 9 31.44828 167.4333 10.18 76.9
  find(mean)
[1] .GlobalEnv   package:base


HTH,

--sundar

__
R-help@r-project.org 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] lattice color problem with symbols: bug?

2008-01-11 Thread Sundar Dorai-Raj


Stefan Grosse said the following on 1/11/2008 10:04 AM:
 Dear useR's,
 
 I have a problem with the lattice plotting of some symbols:
 
 library(lattice)
 
 test-data.frame(x=c(2,3,1,5),u=c(rep(1,2),rep(2,2)),g=c(rep(c(1,2),2)))
 
 xyplot(x~u,groups=g,
  data=test,
  par.settings=list(
 superpose.symbol=list(pch=c(22, 23),cex=c(1.7,1.6),col=black)
 ),
  key=list(
 text=list(c(t1,t2)),
 space = bottom,pch=c(23, 22),
 points=F,
 cex=1.0,
 col=black
 ),
 )
 
 As you see the symbols which have been plotted into the plotting area appear 
 to have some filling color while in the legend there is no filling color 
 although the specification of the symbols is the same.
 
 If I use a normal plot command, the symbols are also not filled:
 plot(c(1,2,3),c(1,2,3),pch=c(22,23,24),cex=1.5)
 
 That problem must have occured during a recent lattice update since the color 
 was not there when I was plotting a year ago with R2.5.x and some older 
 lattice. It occurs on my linux as well as on my windows machine both with R 
 2.6.1 and latest lattice from CRAN.
 
 So here my questions: How do I get rid of the color? (or is it a bug?) If it 
 is a feature, so how do I determine the color in both the symbols in the 
 legend and in the plot itself? (Actually I was overlaying two plots e.g. one 
 colored diamond and one empty diamond to achieve that effect but if there is 
 a more efficient way to draw bordered symbols with customized color that 
 would be preferable...)
 
 Stefan
 

Hi, Stefan

You need to use fill = 'transparent' in your par.settings call. If 
you're not using a fill color, you probably should use pch = c(0, 5) 
instead. This is explained under pch on the ?points help page.

Here's a modified version of your example:

library(lattice)
test - data.frame(x = c(2, 3, 1, 5),
u = rep(1:2, each = 2),
g = paste(t, rep(1:2, 2), sep = ))

xyplot(x ~ u, data = test, groups = g,
par.settings = list(
  superpose.symbol = list(
pch = c(22, 23),
cex = c(1.7, 1.6),
fill = c(red, blue),
col = black)),
auto.key = list(space = bottom))

HTH,

--sundar

__
R-help@r-project.org 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] side by side plots

2008-01-07 Thread Sundar Dorai-Raj


[EMAIL PROTECTED] said the following on 1/7/2008 2:59 PM:
 Hello everyone,
 
 I have an overlay plot it's nice but you can't see all the data. I would
 like to know if there is a way to get a plot that gives a side by side
 plot so that  each plot would be next to each other. The two plots have
 the same data are of different species. At the moment this is the code I'm
 using:
 
 exp-cbind(abs(round(rnorm(10),2)*10), seq(100, 200, by=10))
 ref-cbind(abs(round(rnorm(10),2)*10), seq(100, 200, by=10))
 
 plot(ref, ylab=Intensity, xlab=wavelength, type=h)
 points(exp, type=h, col=red)
 
 This is working in a script and I would like to have a single pdf/png file
 for the user with this plot, rather than asking the user to manually
 compare them.
 
 Any ideas on how I would do this?
 
 Thanks
 
 Paul
 
 __
 R-help@r-project.org 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.

Hi, Paul,

Simple enough in lattice:

library(lattice)
z - rbind(cbind(as.data.frame(exp), type = exp),
cbind(as.data.frame(ref), type = ref))
z$type - factor(z$type, levels = c(ref, exp))
xyplot(V2 ~ V1 | type, data = z, type = h)

HTH,

--sundar

__
R-help@r-project.org 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] mfrow for levelplot?

2008-01-05 Thread Sundar Dorai-Raj


marcg said the following on 1/5/2008 3:48 AM:
 hello
 
 could anyone tell my, why I do not suceed with mfrow?
 
 par(mfrow=c(4,4))
 
 for (i in 5:17){
 levelplot(maxwater[,i]~maxwater$V1*maxwater$V2, col.regions=whiteblue(5), 
 xlab=, cuts=4)
 }
 
 Thanks
 
 Marc
 --
 

Because par settings have little to no effect on lattice. From ?Lattice:

  Lattice plots are highly customizable via user-modifiable
  settings. However, these are completely unrelated to base graphics
  settings; in particular, changing 'par()' settings usually have no
  effect on lattice plots.

To do what you're doing, you need to understand how Lattice works with 
panels. Try:

## Since you didn't supply the data.frame 'maxwater'
## here's a fake dataset to demonstrate
library(lattice)
set.seed(1)
z - expand.grid(V1 = 1:10, V2 = 1:10)
z - cbind(z, matrix(rnorm(100 * 16), 100, 16))
names(z) - sprintf(V%d, 1:ncol(z))

## now create a formula
left - paste(names(z)[3:18], collapse = +)
right - paste(names(z)[1:2], collapse = *)
form - formula(sprintf(%s~%s, left, right))

## not sure how you defined 'whiteblue', but here's my version
whiteblue - colorRampPalette(c(white, blue))

## now call levelplot using a formula
levelplot(form, z, col.regions = whiteblue(5),
   xlab = , cuts = 4, as.table = TRUE)

In the future, please read the posting guide about providing commented, 
minimal, self-contained, reproducible code.

HTH,

--sundar

__
R-help@r-project.org 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] Accesing the value

2007-12-28 Thread Sundar Dorai-Raj
get(x)

This is a FAQ:

http://cran.cnr.berkeley.edu/doc/FAQ/R-FAQ.html#How-can-I-turn-a-string-into-a-variable_003f

--sundar

Shubha Vishwanath Karanth said the following on 12/28/2007 8:38 AM:
 Hi R,
 
  
 
 x=A
 
 A=5
 
  
 
 I need to get the value of A using x only. How do I do this?
 
  
 
 Thanks in advance, Shubha
 
 This e-mail may contain confidential and/or privileged i...{{dropped:13}}
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org 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] How can R be used to solve algebra equations?

2007-11-29 Thread Sundar Dorai-Raj


francogrex said the following on 11/29/2007 1:00 PM:
 suppose I have this equation:
 (x^2+y^2+3z^3)/(5*z^2*x^3)=0
 
 and I want to find x in relation to the other variables which actually is:
 
 x=sqrt(-3*z^3-y^2) or x=-sqrt(-3*z^3-y^2)
 
 Can R give me this expression solution? I know there is uniroot, but here I
 want the expression not the value, because I do  not have values for y and
 z.
 
 Thanks

Try:

library(Ryacas)
yacas(Solve((x^2+y^2+3*z^3)/(5*z^2*x^3)==0, x))

expression(list(x == root(-(4 * (y^2 + 3 * z^3)), 2)/2, x ==
 -root(-(4 * (y^2 + 3 * z^3)), 2)/2))

HTH,

--sundar

__
R-help@r-project.org 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] cumsum

2007-11-03 Thread Sundar Dorai-Raj


threshold said the following on 11/3/2007 4:41 AM:
 Hi, my problem belongs to the basic ones. I want to get cumulated sum over
 the matrix columns by one command (if such exists). Ordinary R's cumsum(x)
 when x is:
  [,1] [,2]
 [1,]15
 [2,]26
 [3,]37
 [4,]48
 
 yields:  1  3  6 10 15 21 28 36
 I want:
  [,1] [,2]
 [1,]15
 [2,]3   11
 [3,]6   18
 [4,]   10   26
 Is there any command to do so??
 
 best, robert
 
 
 

Try

apply(x, 2, cumsum)

HTH,

--sundar

__
R-help@r-project.org 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] plot for binomial glm

2007-10-28 Thread Sundar Dorai-Raj


Radek John said the following on 10/28/2007 5:53 AM:
  Hello everybody!
 I am trying to plot glm with family=binomial and can`t work it out. My Data
 are:
 mort
temp num numdead
 132   7   0
 232   8   0
 332   8   0
 437  15   3
 537  15   1
 637  17   3
 742  11   8
 842  28  14
 942  15  12
 10   47  10  10
 11   47  12  12
 12   47  13  13
 13   52  18  18
 14   52  19  19
 15   52  22  22
 I fitted glm
 glm.mort-glm(cbind(numdead, num - numdead) ~ temp, family=binomial)
 But now I don`t know, how to plot it. I need a plot with some points for
 variable numdead and some curve for the model. Thanks.
 
 Radek John

How about:

t1 - min(mort$temp)
t2 - max(mort$temp)
mort2 - data.frame(temp = seq(t1, t2, len = 100))
prd.mort - predict(glm.mort, mort2, type = r, se.fit = TRUE)

plot(mort2$temp, prd.mort$fit, type = l,
  xlab = Tempature, ylab = Proportion Dead)
lines(mort2$temp, prd.mort$fit - 1.96 * prd.mort$se.fit, lty = 2)
lines(mort2$temp, prd.mort$fit + 1.96 * prd.mort$se.fit, lty = 2)
points(mort$temp, mort$numdead/mort$num)

See ?predict.glm.

HTH,

--sundar

__
R-help@r-project.org 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] Wildcards

2007-10-15 Thread Sundar Dorai-Raj


subura said the following on 10/15/2007 12:04 PM:
 Care to explain how i can use a wildcard expression to source all files
 ending with .R in a subdirectory ? I've tried something like this
 'source(glob2rx(*.R))' without success.
 
 Thank you

Try

R.files - list.files(my.path, pattern = glob2rx(*.R), full = TRUE)
invisible(sapply(R.files, source))

HTH,

--sundar

__
R-help@r-project.org 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] use 'lapply' to creat 2 new columns based on old ones in a data frame

2007-10-12 Thread Sundar Dorai-Raj


runner said the following on 10/12/2007 4:46 PM:
 There is a dataset 'm', which has 3 columns: 'index', 'old1' and 'old2';
 
 I want to create 2 new columns: 'new1' and 'new2' on this condition: 
 if 'index'==i, then 'new1'='old1'+add[i].
 'add' is a vector of numbers to be added to old columns, e.g. add=c(10,20,30
 ...)
  
 Like this:
 
 index old1old2new1new2
 1 5   6   15  16
 2 5   6 2526
 3 5   6   35  36
 3 50 60  80  90
 
 Since the actual dataset is huge, I use 'lapply'. I am able to add 1 column:
 
 do.call(rbind, lapply( 1:nrow(m), 
 function(i) {m$new1[i]=m[i,2]+add[m[i,1]];
 return (m[i,])} 
))
 
 but don't know how to do for 2 columns at the same time, sth. like this
 simply doesn't work:
 do.call(rbind,lapply(1:nrow(m), 
   function(i){ m$new1[i]=m[i,2]+add[m[i,1]]; 
   m$new2[i]=m[i,3]+add[m[i,1]]; 
   return (m[i,])}
  ))
 Could you please tell me how? or any other better approach?
 
 


No need for lapply.

x$new1 - x$old1 + add[x$index]
x$new2 - x$old2 + add[x$index]

To see how this works, try:

add - c(10, 20, 30)
index - c(1, 2, 1, 3, 1, 2, 3)
add[index]

but be careful if 'add' is length 3 and 'index' has a 4 in it you will get

index - c(index, 4)
add[index] ## produces an 'NA'

I hope I understood your question correctly. It's happy hour on the U.S. 
east coast.

HTH,

--sundar

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Checking for adequate disk space

2007-10-03 Thread Sundar Dorai-Raj
Hi, all,

(version info at end)

I'm running a script which takes input files, does some analysis, and 
writes the output to csv files. Last night I ran the script (it took 
~6.5 hours) thinking all would go well since it ran on a subset of the 
data without issue. However, when I returned this morning more than half 
the output files had no data. I checked the Rout file for errors and 
there were none. After spending about an hour debugging the script I 
learned the problem was not the script, but I ran out of disk space. But 
write.table, along with the rest of the script, still continued as if 
nothing was wrong.

My question is: How can I programmatically determine if a user has 
adequate space to use write.* and then throw an error if they don't? I'm 
running R on Linux (RHEL4). For the short term, I will accept Linux-only 
solutions but would prefer an OS-free solution.

My quick-and-dirty solution is to use:

write.csv(x, file)
if(file.info(file)[size] == 0)
   stop(you *may* have run out of disk space)

However, this solution may not work as there may be other reasons the 
file size is 0 (e.g. x is NULL or 0-length?).

  x - character(0)
  write.table(x, file, col.names = FALSE, row.names = FALSE)
  file.info(file)[size]
  size
file0
 
  version
_
platform   i686-pc-linux-gnu
arch   i686
os linux-gnu
system i686, linux-gnu
status
major  2
minor  5.1
year   2007
month  06
day27
svn rev42083
language   R
version.string R version 2.5.1 (2007-06-27)

__
R-help@r-project.org 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.


  1   2   >