Re: [R] Retrieving samples when ussing BRugs.

2011-12-14 Thread Thiago Guerrera
Hi Sacha,

I was referring to the BRugs package, where I usually proceed as follows:

result = BRugsFit (...)

param_samples = samplesSample(param)(1)

But (1) takes a long time for big chains. So my question was specific to
BRugs, if there an alternative way to get the samples.

openbugs() mentioned by you seems to be from R2WinBUGS that I have never
used. I'll try that. Thanks for the suggestion.

Best,
Thiago

On Fri, Dec 9, 2011 at 4:34 PM, Sacha Epskamp sacha.epsk...@gmail.comwrote:

 If you obtain an output object with openbugs(), e.g.:

 samples - openbugs( ... )

 Then this is a list with all the parameters and samples. See
 names(samples). You can obtain the samples in a list with:

 samples[['sims.list']]

 Is this what you mean?

 On Fri, Dec 9, 2011 at 2:00 PM, Thiago Guerrera thig...@gmail.com wrote:
  Hello R users,
 
  I have used the R package BRugs in some applications but one thing that
  annoy me is the functions to retrieve samples (samplesSample) or
 summary
  statistics (samplesStats). They take a really long time to return the
  values if the size of the chains in question is moderate, for example
  10.000 samples. Does this happens with every one or there is a better way
  to obtain such values?
 
  Best
  --
  Thiago Guerrera.
 
 [[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.




-- 
Thiago Guerrera Martins

[[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] Question about escapes character in args parameter of the system2 function.

2011-12-14 Thread Xiaobo Gu
Hi,

I am trying to use the system2 function to execute external
applications(actually it is psql) inside R 2.14.0 on X64 Windows, but
the psql command has escape character inside it's full command line,
can you help to figure out the correct parameters for the system2
function,

The working command is :

psql -h 192.168.72.7 -U gpadmin -w -d miner_demo -c\copy demo.store
to 'd:\store.csv' with csv header

and my R code is:
  psql - psql.exe
  gphost - 192.168.72.7
  gpuser - gpadmin
  gpdb - miner_demo

  copycmd - -c \\\copy demo.store to 'd:\\store.csv' with csv header\
  args - c(-h, gphost, -U, gpuser, -w, -d, gpdb, copycmd )
  system2(psql, args)

And the return value of system2 function is 127.

Regards,

Xiaobo Gu

__
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] Improve a browse through list items - Transform a loop to apply-able function.

2011-12-14 Thread Patrizio Frederic
Hi robin,
I'm not sure is what you need, but that's an esthetically nice
solution (one single line without any loop :) )

matrix(apply(log(cbind(as.numeric(a),as.numeric(b),as.numeric(c),as.numeric(d))),1,sd),3)

hope it could help,

PF


On Mon, Dec 12, 2011 at 5:15 PM, Robin Cura robin.c...@gmail.com wrote:
 Hello,

 I'm currently trying to convert a slow and ugly script I made, so that it's
 faster and can be computed on a computer grid with the multicore package.
 My problem is that I don't see how to turn some loops into an apply-able
 function.

 Here's an example of my loops :
 I got a list of dataframes (or matrices like here), and I need to browse
 each cell of those many dataframes to compute a mean (or standard deviation
 like here).

 Here's a example script :

 a - b - c - d - result - matrix(nrow=3, ncol=3)
 a[] - sample.int(n=100,size=9,replace=TRUE)
 b[] - sample.int(n=100,size=9,replace=TRUE)
 c[] - sample.int(n=100,size=9,replace=TRUE)
 d[] - sample.int(n=100,size=9,replace=TRUE)
 result[] - NA
 mylist - list(a,b,c,d)

 for (row in 1:3)
 {
  for (col in 1:3)
  {
    tmpList - log(mylist[[1]][row, col])
    for (listitem in 2:4)
    {
      tmpList - c(tmpList, log(mylist[[listitem]][row, col]))
    }
    result[row, col] - sd(tmpList)
  }
 }

 Considering I have to look at the same cell in each dataframe, I don't
 understand how I could turn this into a function, considering I need the
 row and column number to iterate.

 I succeeded improving my script duration a lot, but such loops are really
 long to run, considering that my lists contains like 100 dataframes, who
 all contains thousands of values.

 Any help would be really appreciated

 Thanks in advance,

 Robin

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



-- 
+---
| Patrizio Frederic,
| http://www.economia.unimore.it/frederic_patrizio/
+---

__
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] Generating input population for microsimulation

2011-12-14 Thread Jan van der Laan

Emma,

If, as you say, each unit is the same you can just repeat the units to  
obtain the required number of units. For example,



  unit_size - 10
  n_units - 10

  unit_id - rep(1:n_units, each=unit_size)
  pid - rep(1:unit_size, n_units)
  senior  - ifelse(pid = 2, 1, 0)

  pop - data.frame(unit_id, pid, senior)


If you want more flexibility in generating the units, I would first  
generate the units (without the persons) and then generate the persons  
for each unit. In the example below I use the plyr package; you could  
probably also use lapply/sapply, or simply a loop over the units.


  library(plyr)

  generate_unit - function(unit) {
  pid - 1:unit$size
  senior - rep(0, unit$size)
  senior[sample(unit$size, 2)] - 1
  return(data.frame(unit_id=unit$id, pid=pid, senior=senior))
  }

  units - data.frame(id=1:n_units, size=unit_size)

  library(plyr)
  ddply(units, .(id), generate_unit)


HTH,

Jan




Emma Thomas thomas...@yahoo.com schreef:


Hi all,

I've been struggling with some code and was wondering if you all could help.

I am trying to generate a theoretical population of P people who are  
housed within X different units. Each unit follows the same  
structure- 10 people per unit, 8 of whom are junior and two of whom  
are senior. I'd like to create a unit ID and a unique identifier for  
each person (person ID, PID) in the population so that I have a  
matrix that looks like:


 unit_id pid senior
  [1,]  1   1  0
  [2,]  1   2  0
  [3,]  1   3  0
  [4,]  1   4  0
  [5,]  1   5  0
  [6,]  1   6  0
  [7,]  1   7  0
  [8,]  1   8  0
  [9,]  1   9  1
  [10,]    1   10   1
...

I came up with the following code, but am having some trouble  
getting it to populate my matrix the way I'd like.


world - function(units, pop_size, unit_size){
    pid - rep(0,pop_size) #person ID
    senior - rep(0,pop_size) #senior in charge
    unit_id - rep(0,pop_size) #unit ID
   
        for (i in 1:pop_size){
        for (f in 1:units)    { 
        senior[i] = sample(c(1,1,0,0,0,0,0,0,0,0), 1, replace = FALSE)
        pid[i] = sample(c(1:10), 1, replace = FALSE)
        unit_id[i] - f
                }}   
    data - cbind(unit_id, pid, senior)
   
    return(data)
    }

    world(units = 10,pop_size = 100, unit_size = 10) #call the function



The output looks like:
 unit_id pid senior
  [1,]  10   7  0
  [2,]  10   4  0
  [3,]  10  10  0
  [4,]  10   9  1
  [5,]  10  10  0
  [6,]  10   1  1
...

but what I really want is to generate is 10 different units with two  
seniors per unit, and with each person in the population having a  
unique identifier.


I thought a nested for loop was one way to go about creating my data  
set of people and families, but obviously I'm doing something (or  
many things) wrong. Any suggestions on how to fix this? I had been  
focusing on creating a person and assigning them to a unit, but  
perhaps I should create the units and then populate the units with  
people?


Thanks so much in advance.

Emma

__
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] predict in lmer

2011-12-14 Thread Ben Bolker
arunkumar akpbond007 at gmail.com writes:

 Please any one help in finding the predicted value for lmer function
 
 model- lmer(formula =formula,data=data,verbose=TRUE,family = gaussian)
 
 I need to get predicted value for this model.

  Please see the code at http://glmm.wikidot.com/faq , and 
direct further questions about lmer to the r-sig-mixed-mod...@r-project.org
mailing list ...

__
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] Prediction from censReg?

2011-12-14 Thread Terry Therneau
 Have a left-censored dataset, attempting to use a Tobit model and am
working
 with the censReg package. I like how easy it is to move from glm
models to
 predictions with 'predict' and wanted to ask if there was a way to do
so
 with objects output from 'censReg'.


You can fit tobin regression models with survreg, see the help page for
an example.  It has prediction methods.

Terry Therneau

(Sorry about the word wrap: a feature of my mail tool.)

__
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] A Question Re ISOdatetime

2011-12-14 Thread Alex Zhang
Dear all,

I am using the ISOdatetime function like this:

test.info$TradeTime = with(test.info, mapply(FUN = ISOdatetime, Year, Month, 
Day, Hour, Minute, 60, EST))


Where Year, Month etc are all numeric.

I think ISOdatetime should return a POSIXct object. However, the result I 
obtained from the line above is all numeric. Could you please advise? I wish to 
get POSIXct.

Thank you very much!

- Alex
[[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] plot matrix of characters

2011-12-14 Thread Ana
Hi, I am looking for options to plot the following type of matrices:

A B C D
A A C C
A A A C

as a image like this: http://www.phaget4.org/R/image002.jpg

__
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] Plotting a date variable after GAM

2011-12-14 Thread Shige Song
Dear Jean,

That is a simple and effective solution. Thank you!

Best,
Shige

On Tue, Dec 13, 2011 at 4:16 PM, Jean V Adams jvad...@usgs.gov wrote:

 Shige Song wrote on 12/12/2011 07:49:39 PM:


 Dear All,

 I am fitting a simple GAM model using the gam function in the mgcv
 package. The only independent variable is a continuous variable
 representing the time of the event (in year and month) coded so that
 0 represents January 1960, 1 represents February 1960, etc. Now
 when I try to plot the results, my x-axis ranges from -200 to 200,
 what I want is to convert these number into something like 1950-01
 or Jan. 1950. What is the best way to do this?

 Many thanks.

 Best,
 Shige


 How about decimal years?  Would that suffice?

 yourdates - -200:200
 dec.year - 1960 + yourdates/12

 Jean

__
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 matrix of characters

2011-12-14 Thread R. Michael Weylandt
I may be confused, but this seems ill-defined since, in the example,
the color corresponds to a numerical value: characters are only there
as labels. Do you intend to map the characters onto some numerical
spectrum? If so, how?

As a side note, one of the best places to get visualization ideas in
my experience has been the R Graph Gallery. It's often worth a look
and comes with code examples for all the entries: perhaps you can find
some attempts at graphing character data there.

Michael

On Wed, Dec 14, 2011 at 11:30 AM, Ana rrast...@gmail.com wrote:
 Hi, I am looking for options to plot the following type of matrices:

 A B C D
 A A C C
 A A A C

 as a image like this: http://www.phaget4.org/R/image002.jpg

 __
 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] A Question Re ISOdatetime

2011-12-14 Thread Prof Brian Ripley

On 14/12/2011 16:24, Alex Zhang wrote:

Dear all,

I am using the ISOdatetime function like this:

test.info$TradeTime = with(test.info, mapply(FUN = ISOdatetime, Year, Month, Day, Hour, 
Minute, 60, EST))


Where Year, Month etc are all numeric.

I think ISOdatetime should return a POSIXct object. However, the result I 
obtained from the line above is all numeric. Could you please advise? I wish to 
get POSIXct.


ISOdatetime did: mapply threw away the class.
See its SIMPLIFY argument, which defaults to TRUE.
It this case it is unnecessary: e.g.

ISOdatetime(2011, c(11,12), c(30,1), 1, 30, 35, tz=EST)

A 'sec' value of 60 should not be used ... it indicates a leap second 
which POSIX ignores.




Thank you very much.

- Alex




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

__
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] A Question Re ISOdatetime

2011-12-14 Thread Alex Zhang
Thank you very much, Prof Ripley. The problem is solved and my understanding is 
improved. 

Happy holidays!

- Alex



 From: Prof Brian Ripley rip...@stats.ox.ac.uk
To: Alex Zhang alex.zh...@ymail.com 
Cc: r-help@R-project.org r-help@r-project.org 
Sent: Wednesday, December 14, 2011 11:39 AM
Subject: Re: [R] A Question Re ISOdatetime

On 14/12/2011 16:24, Alex Zhang wrote:
 Dear all,

 I am using the ISOdatetime function like this:

 test.info$TradeTime = with(test.info, mapply(FUN = ISOdatetime, Year, Month, 
 Day, Hour, Minute, 60, EST))


 Where Year, Month etc are all numeric.

 I think ISOdatetime should return a POSIXct object. However, the result I 
 obtained from the line above is all numeric. Could you please advise? I wish 
 to get POSIXct.

ISOdatetime did: mapply threw away the class.
See its SIMPLIFY argument, which defaults to TRUE.
It this case it is unnecessary: e.g.

ISOdatetime(2011, c(11,12), c(30,1), 1, 30, 35, tz=EST)

A 'sec' value of 60 should not be used ... it indicates a leap second 
which POSIX ignores.


 Thank you very much.

 - Alex



-- 
Brian D. Ripley,                  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595
[[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] plot matrix of characters

2011-12-14 Thread R. Michael Weylandt
Forgot to cc the list.

M

On Wed, Dec 14, 2011 at 12:19 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 It's a bit of a hack-job, but this might get you started:

 d - structure(c(A, A, A, B, A, A, C, C, A, D,
 C, C), .Dim = 3:4)

 plot(0, type = n, xlim = c(0,ncol(d)), ylim = c(0, nrow(d)), xaxt = n,
     yaxt =n,xlab = NA,ylab = NA)

 ytop - (nrow(d) - row(d)) + 1
 ybottom - (nrow(d) - row(d))

 xleft - col(d)-1
 xright - col(d)

 cols - rainbow(length(unique(c(d

 rect(xleft = xleft, xright = xright, ytop = ytop, ybottom = ybottom,
     col = cols[as.integer(factor(d))])
 text(xleft + 1/2, ybottom + 1/2, labels = d, col = white)


 Some hints for a new poster:
 i) Always cc the list: it gives you opportunities for your questions
 to be seen by a much wider audience which will get you quicker and
 better answers.
 ii) Use dput() to make plain-text representations of your data for
 easy emailing (like how i set up d above)

 Best,

 Michael

 On Wed, Dec 14, 2011 at 11:53 AM, Ana rrast...@gmail.com wrote:
 What I would like to do is to plot the matrix A:

 A B C D
 A A C C
 A A A C

 into a image e.g.  with the following colours

 Yellow Blue Green Black
 Yellow Yellow Green Green
 Yellow Yellow Yellow Green


 I have no idea on how to do it, until now I've been only working with
 numeric and dates plots.




 On Wed, Dec 14, 2011 at 5:35 PM, R. Michael Weylandt
 michael.weyla...@gmail.com wrote:
 I may be confused, but this seems ill-defined since, in the example,
 the color corresponds to a numerical value: characters are only there
 as labels. Do you intend to map the characters onto some numerical
 spectrum? If so, how?

 As a side note, one of the best places to get visualization ideas in
 my experience has been the R Graph Gallery. It's often worth a look
 and comes with code examples for all the entries: perhaps you can find
 some attempts at graphing character data there.

 Michael

 On Wed, Dec 14, 2011 at 11:30 AM, Ana rrast...@gmail.com wrote:
 Hi, I am looking for options to plot the following type of matrices:

 A B C D
 A A C C
 A A A C

 as a image like this: http://www.phaget4.org/R/image002.jpg

 __
 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] Generating input population for microsimulation

2011-12-14 Thread Emma Thomas
Dear Jan,

Thanks for your reply.

The first solution works well for my needs for now, but I have a question about 
the second. If I run your code and then call the function:

generate_unit(10)

I get an error that

Error in unit$size : $ operator is invalid for atomic vectors


Did you experience the same thing?

In any case, I will definitely take a look at the plyr package, which I'm sure 
will be useful in the future.

Thanks again!

Emma



- Original Message -
From: Jan van der Laan rh...@eoos.dds.nl
To: r-help@r-project.org r-help@r-project.org
Cc: Emma Thomas thomas...@yahoo.com
Sent: Wednesday, December 14, 2011 6:18 AM
Subject: Re: [R] Generating input population for microsimulation

Emma,

If, as you say, each unit is the same you can just repeat the units to obtain 
the required number of units. For example,


  unit_size - 10
  n_units - 10

  unit_id - rep(1:n_units, each=unit_size)
  pid     - rep(1:unit_size, n_units)
  senior  - ifelse(pid = 2, 1, 0)

  pop - data.frame(unit_id, pid, senior)


If you want more flexibility in generating the units, I would first generate 
the units (without the persons) and then generate the persons for each unit. In 
the example below I use the plyr package; you could probably also use 
lapply/sapply, or simply a loop over the units.

  library(plyr)

  generate_unit - function(unit) {
      pid - 1:unit$size
      senior - rep(0, unit$size)
      senior[sample(unit$size, 2)] - 1
      return(data.frame(unit_id=unit$id, pid=pid, senior=senior))
  }

  units - data.frame(id=1:n_units, size=unit_size)

  library(plyr)
  ddply(units, .(id), generate_unit)


HTH,

Jan




Emma Thomas thomas...@yahoo.com schreef:

 Hi all,
 
 I've been struggling with some code and was wondering if you all could help.
 
 I am trying to generate a theoretical population of P people who are housed 
 within X different units. Each unit follows the same structure- 10 people per 
 unit, 8 of whom are junior and two of whom are senior. I'd like to create a 
 unit ID and a unique identifier for each person (person ID, PID) in the 
 population so that I have a matrix that looks like:
 
  unit_id pid senior
   [1,]  1   1  0
   [2,]  1   2  0
   [3,]  1   3  0
   [4,]  1   4  0
   [5,]  1   5  0
   [6,]  1   6  0
   [7,]  1   7  0
   [8,]  1   8  0
   [9,]  1   9  1
   [10,]    1   10   1
 ...
 
 I came up with the following code, but am having some trouble getting it to 
 populate my matrix the way I'd like.
 
 world - function(units, pop_size, unit_size){
     pid - rep(0,pop_size) #person ID
     senior - rep(0,pop_size) #senior in charge
     unit_id - rep(0,pop_size) #unit ID
    
         for (i in 1:pop_size){
         for (f in 1:units)    { 
         senior[i] = sample(c(1,1,0,0,0,0,0,0,0,0), 1, replace = FALSE)
         pid[i] = sample(c(1:10), 1, replace = FALSE)
         unit_id[i] - f
                 }}   
     data - cbind(unit_id, pid, senior)
    
     return(data)
     }
 
     world(units = 10,pop_size = 100, unit_size = 10) #call the function
 
 
 
 The output looks like:
  unit_id pid senior
   [1,]  10   7  0
   [2,]  10   4  0
   [3,]  10  10  0
   [4,]  10   9  1
   [5,]  10  10  0
   [6,]  10   1  1
 ...
 
 but what I really want is to generate is 10 different units with two seniors 
 per unit, and with each person in the population having a unique identifier.
 
 I thought a nested for loop was one way to go about creating my data set of 
 people and families, but obviously I'm doing something (or many things) 
 wrong. Any suggestions on how to fix this? I had been focusing on creating a 
 person and assigning them to a unit, but perhaps I should create the units 
 and then populate the units with people?
 
 Thanks so much in advance.
 
 Emma
 
 __
 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] Generating input population for microsimulation

2011-12-14 Thread Emma Thomas
Actually, scratch that, sorry! 

I put the second part of your second solution code into a function and get the 
right data frame in the end. So:

generate_unit- function(unit) {
pid- 1:unit$size
senior- rep(0, unit$size)
senior[sample(unit$size, 2)] - 1
return(data.frame(unit_id=unit$id, pid=pid, senior=senior))
}

world- function(n_units, unit_size){
units- data.frame(id=1:n_units, size=unit_size)
library(plyr)
a- ddply(units, .(id), generate_unit)
return(a)
}

and calling 

world(n_units = 2, unit_size = 5)

gives me 

   id unit_id pid senior

1   1       1   1      1
2   1       1   2      0
3   1       1   3      1
4   1       1   4      0
5   1       1   5      0
6   2       2   1      1
7   2       2   2      0
8   2       2   3      1
9   2       2   4      0
10  2       2   5      0

Which is perfect! Sorry for jumping the gun and thanks again!

-Emma


- Original Message -
From: Emma Thomas thomas...@yahoo.com
To: Jan van der Laan rh...@eoos.dds.nl; r-help@r-project.org 
r-help@r-project.org
Cc: 
Sent: Wednesday, December 14, 2011 12:23 PM
Subject: Re: [R] Generating input population for microsimulation

Dear Jan,

Thanks for your reply.

The first solution works well for my needs for now, but I have a question about 
the second. If I run your code and then call the function:

generate_unit(10)

I get an error that

Error in unit$size : $ operator is invalid for atomic vectors


Did you experience the same thing?

In any case, I will definitely take a look at the plyr package, which I'm sure 
will be useful in the future.

Thanks again!

Emma



- Original Message -
From: Jan van der Laan rh...@eoos.dds.nl
To: r-help@r-project.org r-help@r-project.org
Cc: Emma Thomas thomas...@yahoo.com
Sent: Wednesday, December 14, 2011 6:18 AM
Subject: Re: [R] Generating input population for microsimulation

Emma,

If, as you say, each unit is the same you can just repeat the units to obtain 
the required number of units. For example,


  unit_size - 10
  n_units - 10

  unit_id - rep(1:n_units, each=unit_size)
  pid     - rep(1:unit_size, n_units)
  senior  - ifelse(pid = 2, 1, 0)

  pop - data.frame(unit_id, pid, senior)


If you want more flexibility in generating the units, I would first generate 
the units (without the persons) and then generate the persons for each unit. In 
the example below I use the plyr package; you could probably also use 
lapply/sapply, or simply a loop over the units.

  library(plyr)

  generate_unit - function(unit) {
      pid - 1:unit$size
      senior - rep(0, unit$size)
      senior[sample(unit$size, 2)] - 1
      return(data.frame(unit_id=unit$id, pid=pid, senior=senior))
  }

  units - data.frame(id=1:n_units, size=unit_size)

  library(plyr)
  ddply(units, .(id), generate_unit)


HTH,

Jan




Emma Thomas thomas...@yahoo.com schreef:

 Hi all,
 
 I've been struggling with some code and was wondering if you all could help.
 
 I am trying to generate a theoretical population of P people who are housed 
 within X different units. Each unit follows the same structure- 10 people per 
 unit, 8 of whom are junior and two of whom are senior. I'd like to create a 
 unit ID and a unique identifier for each person (person ID, PID) in the 
 population so that I have a matrix that looks like:
 
  unit_id pid senior
   [1,]  1   1  0
   [2,]  1   2  0
   [3,]  1   3  0
   [4,]  1   4  0
   [5,]  1   5  0
   [6,]  1   6  0
   [7,]  1   7  0
   [8,]  1   8  0
   [9,]  1   9  1
   [10,]    1   10   1
 ...
 
 I came up with the following code, but am having some trouble getting it to 
 populate my matrix the way I'd like.
 
 world - function(units, pop_size, unit_size){
     pid - rep(0,pop_size) #person ID
     senior - rep(0,pop_size) #senior in charge
     unit_id - rep(0,pop_size) #unit ID
    
         for (i in 1:pop_size){
         for (f in 1:units)    { 
         senior[i] = sample(c(1,1,0,0,0,0,0,0,0,0), 1, replace = FALSE)
         pid[i] = sample(c(1:10), 1, replace = FALSE)
         unit_id[i] - f
                 }}   
     data - cbind(unit_id, pid, senior)
    
     return(data)
     }
 
     world(units = 10,pop_size = 100, unit_size = 10) #call the function
 
 
 
 The output looks like:
  unit_id pid senior
   [1,]  10   7  0
   [2,]  10   4  0
   [3,]  10  10  0
   [4,]  10   9  1
   [5,]  10  10  0
   [6,]  10   1  1
 ...
 
 but what I really want is to generate is 10 different units with two seniors 
 per unit, and with each person in the population having a unique identifier.
 
 I thought a nested for loop was one way to go about creating my data set of 
 people and families, but obviously I'm doing something (or many things) 
 wrong. Any suggestions on how to fix this? I had been focusing on creating a 
 person and assigning them to a unit, but perhaps I should create the units 
 and then populate the units with people?
 
 

Re: [R] Generating input population for microsimulation

2011-12-14 Thread Jan van der Laan

Emma,

That is because generate_unit expects a data.frame with one row and  
columns id and size:


generate_unit(data.frame(id=1, size=10))

Jan




Emma Thomas thomas...@yahoo.com schreef:


Dear Jan,

Thanks for your reply.

The first solution works well for my needs for now, but I have a  
question about the second. If I run your code and then call the  
function:


generate_unit(10)

I get an error that

Error in unit$size : $ operator is invalid for atomic vectors


Did you experience the same thing?

In any case, I will definitely take a look at the plyr package,  
which I'm sure will be useful in the future.


Thanks again!

Emma



- Original Message -
From: Jan van der Laan rh...@eoos.dds.nl
To: r-help@r-project.org r-help@r-project.org
Cc: Emma Thomas thomas...@yahoo.com
Sent: Wednesday, December 14, 2011 6:18 AM
Subject: Re: [R] Generating input population for microsimulation

Emma,

If, as you say, each unit is the same you can just repeat the units  
to obtain the required number of units. For example,



  unit_size - 10
  n_units - 10

  unit_id - rep(1:n_units, each=unit_size)
  pid     - rep(1:unit_size, n_units)
  senior  - ifelse(pid = 2, 1, 0)

  pop - data.frame(unit_id, pid, senior)


If you want more flexibility in generating the units, I would first  
generate the units (without the persons) and then generate the  
persons for each unit. In the example below I use the plyr package;  
you could probably also use lapply/sapply, or simply a loop over the  
units.


  library(plyr)

  generate_unit - function(unit) {
      pid - 1:unit$size
      senior - rep(0, unit$size)
      senior[sample(unit$size, 2)] - 1
      return(data.frame(unit_id=unit$id, pid=pid, senior=senior))
  }

  units - data.frame(id=1:n_units, size=unit_size)

  library(plyr)
  ddply(units, .(id), generate_unit)


HTH,

Jan




Emma Thomas thomas...@yahoo.com schreef:


Hi all,

I've been struggling with some code and was wondering if you all could help.

I am trying to generate a theoretical population of P people who  
are housed within X different units. Each unit follows the same  
structure- 10 people per unit, 8 of whom are junior and two of whom  
are senior. I'd like to create a unit ID and a unique identifier  
for each person (person ID, PID) in the population so that I have a  
matrix that looks like:


 unit_id pid senior
  [1,]  1   1  0
  [2,]  1   2  0
  [3,]  1   3  0
  [4,]  1   4  0
  [5,]  1   5  0
  [6,]  1   6  0
  [7,]  1   7  0
  [8,]  1   8  0
  [9,]  1   9  1
  [10,]    1   10   1
...

I came up with the following code, but am having some trouble  
getting it to populate my matrix the way I'd like.


world - function(units, pop_size, unit_size){
    pid - rep(0,pop_size) #person ID
    senior - rep(0,pop_size) #senior in charge
    unit_id - rep(0,pop_size) #unit ID
   
        for (i in 1:pop_size){
        for (f in 1:units)    { 
        senior[i] = sample(c(1,1,0,0,0,0,0,0,0,0), 1, replace = FALSE)
        pid[i] = sample(c(1:10), 1, replace = FALSE)
        unit_id[i] - f
                }}   
    data - cbind(unit_id, pid, senior)
   
    return(data)
    }

    world(units = 10,pop_size = 100, unit_size = 10) #call the function



The output looks like:
 unit_id pid senior
  [1,]  10   7  0
  [2,]  10   4  0
  [3,]  10  10  0
  [4,]  10   9  1
  [5,]  10  10  0
  [6,]  10   1  1
...

but what I really want is to generate is 10 different units with  
two seniors per unit, and with each person in the population having  
a unique identifier.


I thought a nested for loop was one way to go about creating my  
data set of people and families, but obviously I'm doing something  
(or many things) wrong. Any suggestions on how to fix this? I had  
been focusing on creating a person and assigning them to a unit,  
but perhaps I should create the units and then populate the units  
with people?


Thanks so much in advance.

Emma

__
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] R - Linux_SSH

2011-12-14 Thread Chris Mcowen
Dear List,

 

I am unsure if this is the correct list to post to, if it isn't I apologise.

 

I am using SSH to access a Linux version of R on a remote computer as it
offers more memory and processing power. The model will take 1-2 days to
run, I am accessing R through Putty and when I close the connection and open
R again, I am faced with a new session.

 

As a Linux newbie, I was wondering if anybody here knew how to keep R
running and interactive and return to it on a later date?

 

Thanks

 

Chris


[[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] SQL select ... where R variable

2011-12-14 Thread agent dunham
Thank you, 

I guess it didn't work for me, maybe is not possible?

I've tried: 

 con- odbcDriverConnect(Driver=SQL Server;
 Server=...\\...;Database=...;Uid=...;Pwd=... ;)

 v1=sqlQuery(con, select v1 from sqltable where v3 =cte and v2 in (select
 v2 from R_dataframe) order by (select v2 from R_dataframe))

 head(rbind(R_dataframe$v2, v1))
   [,1] 
  
   1251   
  
v1 42S02 208 [Microsoft][ODBC SQL Server Driver][SQL Server]*The name of
the object 'R_dataframe' is not valid.*

Thanks in advance, 
u...@host.com
   

--
View this message in context: 
http://r.789695.n4.nabble.com/SQL-select-where-R-variable-tp4190882p4194629.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] My finding-resent

2011-12-14 Thread 孟欣
Sorry for some typo last mail.
 
I corrected it,and resent.Sorry for it.
 
 
Sir:
I find out that for 2 level factor, if I set it to factor, then I'll get 
error reply.
For the instance last mail, if I use:


result1-glm(y ~ factor(gender),family = binomial);#gender has 2 levels
logistic.display(result1)
Error in coeff[, 1] : incorrect number of dimensions




 if I use:


result1-glm(y ~ factor(age),family = binomial); #age has 3 levels
logistic.display(result1)


It works well.

So,I conclude that for 2level variable,I must NOT set it to factor.The 
following command can work well for instance:

result1-glm(y ~ gender,family = binomial);#gender has 2 levels
logistic.display(result1)

It works well.

So I have a suggestion that no matter the number of levels, if I set it to 
factor, logistic.disply can all works well.

 











 
 



At 2011-12-14 13:53:21,Virasakdi Chongsuvivatwong cvira...@gmail.com wrote:
logistic.display need a rather tidy model ie all independent variables must be 
the original name not any function of a variable in the dataset of the model.

If data1 is your dataset containing y, 'gender' and 'age', what you need to do 
is

 data1$age1 - factor(data1$age)

 result1-glm(y ~ age1 + gender + CD4,family = binomial, data=data1)
 logistic.display(result1)

Note that 'gender', like 'y', is already dichotomized (0,1). There is no need 
to 'factor'

Virasakdi C




2011/12/14 ÃÏÐÀ lm_meng...@163.com


Hi sir:
I follow your suggestion:


result-glm(y ~ factor(age) + factor(gender) + CD4,family = binomial)
logistic.display(result)


Error in coeff[, 1] : incorrect number of dimensions











At 2011-12-14 01:59:36,Jorge I Velez jorgeivanve...@gmail.com wrote:
Hi there,


Try


require(epicalc)
logistic.display(result)


HTH,
Jorge


On Tue, Dec 13, 2011 at 7:16 AM, ÃÏÐÀ  wrote:
Hi all:
My data has 3 variables:
age(3levels : 30y=1  30-50y=2, 50y=3)
gender(Male=0, Female=1)
CD4 cell count(raw lab measurement)
y(1:death  0:alive)

I perform logistic regression to find out the factors that influence y.

result-glm(y ~ factor(age) + factor(gender) + CD4,family = binomial)

From the result,I can get OR(Odds Ratio) of gender  via exp(Estimate of 
Female, since Male is regarded as reference group and has no result).But how 
can I compute the 95%CI of OR of gender?


Thanks a lot for your help.

My best!




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






--

-- NOTE: Prince of Songkla University will NEVER ask for your PSU 
Passport/Email Username or password by e-mail. If you receive such a message, 
please report it to report-ph...@psu.ac.th.

 NEVER reply to any e-mail asking for your PSU Passport/Email or other 
personal details. 
For more information, contact the PSU E-Mail Service by dialing 2121








[[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] mgcv 'bam' : prediction levels for random effects

2011-12-14 Thread lglew
Hi R users,

I'm using the 'bam' function in mgcv to examine trends in a remotely sensed
vegetation index.  I have one random effect variable, 'cons' (with six
levels) which identifies different subjects within this analysis.

My model is specified as follows:

rm4-bam(trend~factor(zone)+s(cons,bs=re)+s(year,
bs=cc),data=rain.data,family=gaussian(link=identity),method=ML,na.action=na.omit,
rho=0.884)


I'm using the bam routine as the dataframe is very large (300,000 rows of
data).  If possible, I'd like to extract the random effects from the fitted
gam object which is returned as I'm interested to know how dynamics vary
between subjects.  I'm aware that specifying the random effect using s()
with bs=re, is dummying a random effect, but I'm not sure if it is still
possible to extact the random effects levels using this method?

Thanks for your help,

Louise

--
View this message in context: 
http://r.789695.n4.nabble.com/mgcv-bam-prediction-levels-for-random-effects-tp4195614p4195614.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] Download and Unzip a file

2011-12-14 Thread himanshuy
Hi 

I am trying to download and unzip a zip file from the following location.

http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip

I initially there was issue with useragent so i ran the following code

options(HTTPUserAgent=Firefox/8.0.1)
u =
http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip;
o = getURLContent(u, verbose = TRUE, useragent = getOption(HTTPUserAgent))

now I want to unzip and save this file. I was initially working on matlab
and have recently moved to R.
any help would be much appreciated.

Thanks
Himanshu Y


--
View this message in context: 
http://r.789695.n4.nabble.com/Download-and-Unzip-a-file-tp4194895p4194895.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] uniroot function question

2011-12-14 Thread kchkchkch
I have one equation, two unknowns, so I am trying to build the solution set
by running through possible values for one unknown, and then using uniroot
to solve for the accompanying second solution, then graphing the two
vectors.

p0 = .36
f = function(x) 0.29 * exp(5.66*(x - p0))
f.integral = integrate(f, p0, 1)
p1 = p0 + .01
i = 1
n = (1 - p0)/.01
p1.vector = rep(0,n)
p2.vector = rep(0,n)
for (i in 1:n) {
p1.vector[i] = p1
fcn = function(p2) p1*f(p1) + (.20/5.66)*(exp(5.66*(p2 - p0)) -
exp(5.66*(p1 - p0))) + (1 - p2)*f(p2) - as.numeric(f.integral$value)
sol = uniroot(try, lower = p1, upper = 1)
p2.vector[i] = p2
i = i+1
p1 = p1 + .01
}
plot(p1.vector,p2.vector)

p1, p2 both have to be between p0 and 1, p1  p2.  Is there a better way to
do this?  I keep getting the error that my lower and upper bounds are not of
opposite sign, but I don't know how to find the correct interval values in
that case.  This may not even be a uniroot question (although I don't know
how to find those values in a general sense), if there is a better way to do
the same thing.  

Any ideas?

--
View this message in context: 
http://r.789695.n4.nabble.com/uniroot-function-question-tp4195737p4195737.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] labels in lattice

2011-12-14 Thread matteo
Dear all,

here is a simple problem that surely you already come across, but is giving
me a big headache...

I have a dataframe like this:

set.seed(3)
mydata - data.frame(var = rnorm(100,20,1),
 temp = sin(sort(rep(c(1:10),10))),
 subj = as.factor(rep(c(1:10),5)))

and I need to make a scatter plot for each subj, not a problem, but...
what i want is to replace the strips from the lattice and add a label to
each plot.
I manage to do this with the following code, but I'm still not happy...

xyplot(var ~ temp | subj, 
   data = mydata,
   strip=FALSE,
   panel = function(x, y,...) {
   panel.xyplot(x, y,...)
   panel.text(1,21,labels=which.packet())
   }) 

The last bit...where i got stacked...is how to print letters instead of
numbers in each panel. I would like to call the panels a,b,c... and so on.

Any suggestions...
Many thanks
matteo 

--
View this message in context: 
http://r.789695.n4.nabble.com/labels-in-lattice-tp4195766p4195766.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] Sampling data every third hour

2011-12-14 Thread abcdef ghijk
 Good Morning ,

I want to sample the following time series for every third hour. For example at 
00:00,03:00,06:00,09:00 etc. 

    
2011-01-01 00:00:00 0.00e+00
2011-01-01 01:00:00 1.471667e+01
2011-01-01 02:00:00 1.576667e+01
2011-01-01 03:00:00 0.00e+00
2011-01-01 04:00:00 0.00e+00
2011-01-01 05:00:00 0.00e+00
2011-01-01 06:00:00 0.00e+00
2011-01-01 07:00:00 0.00e+00
2011-01-01 08:00:00 0.00e+00
2011-01-01 09:00:00 1.826667e+01
2011-01-01 10:00:00 0.00e+00
2011-01-01 11:00:00 0.00e+00
2011-01-01 12:00:00 0.00e+00
2011-01-01 13:00:00 0.00e+00
2011-01-01 14:00:00 0.00e+00
2011-01-01 15:00:00 0.00e+00
2011-01-01 16:00:00 0.00e+00
2011-01-01 17:00:00 0.00e+00
2011-01-01 18:00:00 0.00e+00
2011-01-01 19:00:00 0.00e+00
2011-01-01 20:00:00 0.00e+00
2011-01-01 21:00:00 7.01e+01
2011-01-01 22:00:00 7.154167e+02
2011-01-01 23:00:00 2.039167e+02
2011-01-02 00:00:00 3.703000e+02
2011-01-02 01:00:00 9.130167e+02
2011-01-02 02:00:00 0.00e+00
2011-01-02 03:00:00 0.00e+00
Thanks in advance.
Regards,
Shan

[[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] Saving non table object as text file with outputting preserved?

2011-12-14 Thread Tony Stocker
All,

Given the following commands:

 ag.m35-read.table(m35.txt,header=TRUE,sep=,)
 ag.m35.lp-subset(ag.m35, race==lp)
 aov.m35.lp=aov(year~time,data=ag.m35.lp)
 anova.m35.lp=anova(aov.m35.lp)
 anova.m35.lp
Analysis of Variance Table

Response: year
  Df Sum Sq Mean Sq F value Pr(F)
time   1  11.56 11.5649  1.7282 0.1929
Residuals 70 468.44  6.6919

 pwt.m35.lp-pairwise.t.test(ag.m35.lp$time,ag.m35.lp$year)
 pwt.m35.lp

Pairwise comparisons using t tests with pooled SD

data:  ag.m35.lp$time and ag.m35.lp$year

 2002   2003   2004   2005   2006   2007   2008   2009
2003 0.0368 -  -  -  -  -  -  -
2004 1. 0.0072 -  -  -  -  -  -
2005 1. 1. 0.9733 -  -  -  -  -
2006 1. 1. 0.4370 1. -  -  -  -
2007 1. 1. 0.7099 1. 1. -  -  -
2008 1. 1. 0.7099 1. 1. 1. -  -
2009 1. 0.1465 1. 1. 1. 1. 1. -
2010 1. 0.0012 1. 0.3092 0.1244 0.2110 0.2125 1.

 dput(pwt.m35.lp, foo)

Is there any way, other than dput(), to output something that is not a
table to a text file and preserve its formatting?  If you compare the
output of the implicit print statement in the R console line 
pwt.m35.lp, to the following output from # cat foo as the OS
command line you'll see that the exported text file from dput is not
formatted and easy to read as the output inside of R:

= cat foo
structure(list(method = t tests with pooled SD, data.name = g2$time
and g2$year,
p.value = structure(c(0.0367532070877987, 1, 1, 1, 1, 1,
1, 1, NA, 0.00718315554357665, 1, 1, 1, 1, 0.146481016374305,
0.0012185417136, NA, NA, 0.973279068747759, 0.436956148539609,
0.709867943596168, 0.709867943596168, 1, 1, NA, NA, NA, 1,
1, 1, 1, 0.309223819660721, NA, NA, NA, NA, 1, 1, 1, 0.124449626396277,
NA, NA, NA, NA, NA, 1, 1, 0.210956065413139, NA, NA, NA,
NA, NA, NA, 1, 0.212525673297984, NA, NA, NA, NA, NA, NA,
NA, 1), .Dim = c(8L, 8L), .Dimnames = list(c(2003, 2004,
2005, 2006, 2007, 2008, 2009, 2010), c(2002,
2003, 2004, 2005, 2006, 2007, 2008, 2009))),
p.adjust.method = holm), .Names = c(method, data.name,
p.value, p.adjust.method), class = pairwise.htest)


In addition to dput() I have tried using write(), write.table(), and
dump() to no avail.  Is what I'm trying to do something that's not
normally done or am I just missing an obvious elephant in the room?

Thanks

__
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] nice report generator?

2011-12-14 Thread Greg Snow
Duncan, 

If you are taking suggestions for expanding the tables package (looks great) 
then I would suggest some way to get the tables into MS products.  If I create 
a full output/report myself then I am happy to work in LaTeX, but much of what 
I do is to produce tables and graphs to clients that don't know LaTeX and just 
want something that they can copy and paste into powerpoint or word.  For this 
I have been using the R2wd package (and the wdTable function for the tables).  
I would love to have some toolset that I could use your tables package to 
create the main table, then transfer it fairly simply to word or excel.  I 
don't care much about the fluff of how the table looks (coloring rows or 
columns, line widths, etc.) just getting it into a table (not just the text 
version).

One possibility is just an as.matrix method that would produce something that I 
could feed to wdTable.  Or just a textual representation of the table with 
columns separated by tabs so that it could be copied to the clipboard then 
pasted into excel or word (I would then let the client deal with all the tweaks 
on the appearance).

Thanks,

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Duncan Murdoch
Sent: Thursday, December 08, 2011 4:52 PM
To: Tal Galili
Cc: r-help
Subject: Re: [R] nice report generator?

On 11-12-08 1:37 PM, Tal Galili wrote:
 Helloe dear Duncan, Gabor, Michael and others,

 Do you think it could be (reasonably) possible to create a bridge between a
 cast_df object from the {reshape} package into a table in Duncan's new
 {tables} package?

I'm not that familiar with the reshape package (and neither it nor 
reshape2 appears to have a vignette to give me an overview), so I don't 
have any idea if that makes sense.  The table package is made to work on 
dataframes, and only dataframes.  It converts them into matrices with 
lots of attributes, so that the print methods can put nice labels on. 
But it's strictly rectangular to rectangular in the kinds of conversions 
it does, and from the little I know about reshape, it works on more 
general arrays, converting them to and from dataframes.



 That would allow one to do pivot-table like operations on an object using
 {reshape}, and then display it (as it would have been in excel - or better)
 using the {tables} package.

You'll have to give an example of what you want to do.

Duncan Murdoch








 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)
 --




 On Thu, Dec 8, 2011 at 5:24 PM, Michaelcomtech@gmail.com  wrote:

 Hi folks,

 In addition to Excel style tables, it would be great to have Excel 2010
 Pivot Table in R...

 Any thoughts?

 Thanks a lot!

 On Thu, Dec 8, 2011 at 4:49 AM, Tal Galilital.gal...@gmail.com  wrote:

 I think it would be *great *if an extension of Duncan's new tables
 package could include themes and switches as are seen in the video Gabor
 just linked to.


 Tal


   On Thu, Dec 8, 2011 at 6:58 AM, Gabor Grothendieck
 ggrothendi...@gmail.com  wrote:

   On Wed, Dec 7, 2011 at 11:42 PM, Michaelcomtech@gmail.com  wrote:
 Do you have an example...? Thanks a lot!

 See this video:
 http://www.woopid.com/video/1388/Format-as-Table

 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at 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.htmlhttp://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.

__
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] map at fips level using multiple variables

2011-12-14 Thread Greg Snow
Colors probably are not the best for so many levels and combinations.  Look at 
the symbols function (or the my.symbols and subplot functions in the 
TeachingDemos package) for ways to add symbols to a map showing multiple 
variables.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of bby2...@columbia.edu
Sent: Wednesday, December 07, 2011 9:14 PM
To: David Winsemius
Cc: r-help@r-project.org
Subject: Re: [R] map at fips level using multiple variables

Hi David,

Sorry it sounds vague.

Here is my current code, which gives the distribution of family size  
at US county level. You will see on a US map family size distribution  
represented by different colors.

Now if i have another variable income, which has 3 categories(50k,  
50k-80k,80k). How do I show 5x3 categories on the map? I guess I  
could always create a third variable to do this. Just wondering maybe  
there is a function to do this readily?

Thank you!
Bonnie Yuan

y=data1$size
x11()
hist(y,nclass=15) # histogram of y
fivenum(y)
# specify the cut-off point of y
y.colorBuckets=as.numeric(cut(y, c(1,2, 3,6)))
# legend showing the cut-off points.
legend.txt=c(0-1,1-2,2-3,3-6,6)
colorsmatched=y.colorBuckets[match(county.fips$fips,fips[,1])]
x11()
map(county, col = colors[colorsmatched], fill = TRUE, resolution = 0)
map(state, col = white, fill = FALSE, add = TRUE, lty = 1, lwd = 0.2)
title(Family Size)
legend(bottom, legend.txt, horiz = TRUE, fill = colors, cex=0.7)



Quoting David Winsemius dwinsem...@comcast.net:


 On Dec 7, 2011, at 6:12 PM, bby2...@columbia.edu wrote:

 Hi, I just started playing with county FIPS feature in maps package  
  which allows geospatial visualization of variables on US county   
 level. Pretty cool.

 Got code?


 I did some search but couldn't find answer to this question--how   
 can I map more than 2 variables on US map?

 2 variables is a bit on the vague side for programming purposes.

 For example, you can map by the breakdown of income or family size.  
  How do you further breakdown based on the values of both variables  
  and show them on the county FIPS level?

 breakdown suggests a factor construct. If so, then :

 ?interaction

 But the show part of the question remains very vague.

  Can't you be a bit more specific? What DO you want?

 -- 
 David Winsemius, MD
 West Hartford, CT

__
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] R - Linux_SSH

2011-12-14 Thread Rich Shepard

On Wed, 14 Dec 2011, Chris Mcowen wrote:


As a Linux newbie, I was wondering if anybody here knew how to keep R
running and interactive and return to it on a later date?


Chris,

  Screen will retain the session and keep the process going. Read 'man
screen'.

  Whether this works from a remote Microsoft host I've no idea.

Rich

__
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] R - Linux_SSH

2011-12-14 Thread Jan van der Laan
What I did in the past (not with R scripts) is to start my jobs using  
at (start the job at a specified time e.g. now) or batch (start the  
job when the cpu drops below ?%)


at now R CMD BATCH yourscript.R

or

batch R CMD BATCH yourscript.R

something like that, you'll have to look at the man pages for at  
and/or batch. You probably need something like atd running. I do not  
know if current linux distributions have that running by default.  
You'll get an email when the job is finished.


HTH
Jan



R CMD BATCH [options] my_script.R [outfile]


Chris Mcowen chrismco...@gmail.com schreef:


Dear List,



I am unsure if this is the correct list to post to, if it isn't I apologise.



I am using SSH to access a Linux version of R on a remote computer as it
offers more memory and processing power. The model will take 1-2 days to
run, I am accessing R through Putty and when I close the connection and open
R again, I am faced with a new session.



As a Linux newbie, I was wondering if anybody here knew how to keep R
running and interactive and return to it on a later date?



Thanks



Chris


[[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] R - Linux_SSH

2011-12-14 Thread Peter Langfelder
On Wed, Dec 14, 2011 at 4:35 AM, Chris Mcowen chrismco...@gmail.com wrote:
 Dear List,



 I am unsure if this is the correct list to post to, if it isn't I apologise.



 I am using SSH to access a Linux version of R on a remote computer as it
 offers more memory and processing power. The model will take 1-2 days to
 run, I am accessing R through Putty and when I close the connection and open
 R again, I am faced with a new session.



 As a Linux newbie, I was wondering if anybody here knew how to keep R
 running and interactive and return to it on a later date?



I am not aware of any way to keep the R session interactive although
perhaps a VNC server/client may offer this possibility. If you have a
long calculation, put it all in a script named myScript.R (or any
other file name) that does not require any human input, then run it as
a batch using the nohup linux command:

nohup R CMD BATCH myScript.R

The nohup command will prevent the termination of your R after you log
out, but you cannot run an interactive program this way.

HTH

Peter



 Thanks



 Chris


        [[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] uniroot function question

2011-12-14 Thread Berend Hasselman

kchkchkch wrote
 
 I have one equation, two unknowns, so I am trying to build the solution
 set by running through possible values for one unknown, and then using
 uniroot to solve for the accompanying second solution, then graphing the
 two vectors.
 
 p0 = .36
 f = function(x) 0.29 * exp(5.66*(x - p0))
 f.integral = integrate(f, p0, 1)
 p1 = p0 + .01
 i = 1
 n = (1 - p0)/.01
 p1.vector = rep(0,n)
 p2.vector = rep(0,n)
 for (i in 1:n) {
   p1.vector[i] = p1
   fcn = function(p2) p1*f(p1) + (.20/5.66)*(exp(5.66*(p2 - p0)) -
 exp(5.66*(p1 - p0))) + (1 - p2)*f(p2) - as.numeric(f.integral$value)
   sol = uniroot(try, lower = p1, upper = 1)
   p2.vector[i] = p2
   i = i+1
   p1 = p1 + .01
 }
 plot(p1.vector,p2.vector)
 
 p1, p2 both have to be between p0 and 1, p1  p2.  Is there a better way
 to do this?  I keep getting the error that my lower and upper bounds are
 not of opposite sign, but I don't know how to find the correct interval
 values in that case.  This may not even be a uniroot question (although I
 don't know how to find those values in a general sense), if there is a
 better way to do the same thing.  
 

Shouldn't the line with uniroot be (why try as function?)

sol = uniroot(fcn, lower = p1, upper = 1)

Before the line with  for(i in 1:n) insert the following

fcn = function(p2) p1*f(p1) + (.20/5.66)*(exp(5.66*(p2 - p0)) - exp(5.66*(p1
- p0))) + (1 - p2)*f(p2) - as.numeric(f.integral$value) 
curve(fcn, from=0, to=1)

And it should be obvious what the problem is.

Berend

--
View this message in context: 
http://r.789695.n4.nabble.com/uniroot-function-question-tp4195737p4196220.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.


Re: [R] Sampling data every third hour

2011-12-14 Thread R. Michael Weylandt
1) Use dput() to submit data.

2) Would this work? (It requires your data are evenly spaced, but I
think that's it) d[seq(1, nrow(d), by = 3), ]

Michael

On Wed, Dec 14, 2011 at 7:17 AM, abcdef ghijk lineh...@yahoo.com wrote:
  Good Morning ,

 I want to sample the following time series for every third hour. For example 
 at 00:00,03:00,06:00,09:00 etc.


 2011-01-01 00:00:00 0.00e+00
 2011-01-01 01:00:00 1.471667e+01
 2011-01-01 02:00:00 1.576667e+01
 2011-01-01 03:00:00 0.00e+00
 2011-01-01 04:00:00 0.00e+00
 2011-01-01 05:00:00 0.00e+00
 2011-01-01 06:00:00 0.00e+00
 2011-01-01 07:00:00 0.00e+00
 2011-01-01 08:00:00 0.00e+00
 2011-01-01 09:00:00 1.826667e+01
 2011-01-01 10:00:00 0.00e+00
 2011-01-01 11:00:00 0.00e+00
 2011-01-01 12:00:00 0.00e+00
 2011-01-01 13:00:00 0.00e+00
 2011-01-01 14:00:00 0.00e+00
 2011-01-01 15:00:00 0.00e+00
 2011-01-01 16:00:00 0.00e+00
 2011-01-01 17:00:00 0.00e+00
 2011-01-01 18:00:00 0.00e+00
 2011-01-01 19:00:00 0.00e+00
 2011-01-01 20:00:00 0.00e+00
 2011-01-01 21:00:00 7.01e+01
 2011-01-01 22:00:00 7.154167e+02
 2011-01-01 23:00:00 2.039167e+02
 2011-01-02 00:00:00 3.703000e+02
 2011-01-02 01:00:00 9.130167e+02
 2011-01-02 02:00:00 0.00e+00
 2011-01-02 03:00:00 0.00e+00
 Thanks in advance.
 Regards,
 Shan

        [[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] nice report generator?

2011-12-14 Thread Richard M. Heiberger
Greg,

Please look at the SWord package.  This package integrates MS Word with R
in a manner similar to the SWeave integration of LaTeX with R.
Download SWord from rcom.univie.ac.at
If you have a recent download of RExcel from the RAndFriends installer, then
you will already have SWord on your machine.

Rich

On Wed, Dec 14, 2011 at 12:39 PM, Greg Snow greg.s...@imail.org wrote:

 Duncan,

 If you are taking suggestions for expanding the tables package (looks
 great) then I would suggest some way to get the tables into MS products.
  If I create a full output/report myself then I am happy to work in LaTeX,
 but much of what I do is to produce tables and graphs to clients that don't
 know LaTeX and just want something that they can copy and paste into
 powerpoint or word.  For this I have been using the R2wd package (and the
 wdTable function for the tables).  I would love to have some toolset that I
 could use your tables package to create the main table, then transfer it
 fairly simply to word or excel.  I don't care much about the fluff of how
 the table looks (coloring rows or columns, line widths, etc.) just getting
 it into a table (not just the text version).

 One possibility is just an as.matrix method that would produce something
 that I could feed to wdTable.  Or just a textual representation of the
 table with columns separated by tabs so that it could be copied to the
 clipboard then pasted into excel or word (I would then let the client deal
 with all the tweaks on the appearance).

 Thanks,

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Duncan Murdoch
 Sent: Thursday, December 08, 2011 4:52 PM
 To: Tal Galili
 Cc: r-help
 Subject: Re: [R] nice report generator?

 On 11-12-08 1:37 PM, Tal Galili wrote:
  Helloe dear Duncan, Gabor, Michael and others,
 
  Do you think it could be (reasonably) possible to create a bridge
 between a
  cast_df object from the {reshape} package into a table in Duncan's new
  {tables} package?

 I'm not that familiar with the reshape package (and neither it nor
 reshape2 appears to have a vignette to give me an overview), so I don't
 have any idea if that makes sense.  The table package is made to work on
 dataframes, and only dataframes.  It converts them into matrices with
 lots of attributes, so that the print methods can put nice labels on.
 But it's strictly rectangular to rectangular in the kinds of conversions
 it does, and from the little I know about reshape, it works on more
 general arrays, converting them to and from dataframes.


 
  That would allow one to do pivot-table like operations on an object using
  {reshape}, and then display it (as it would have been in excel - or
 better)
  using the {tables} package.

 You'll have to give an example of what you want to do.

 Duncan Murdoch


 
 
 
 
 
 
  Contact
  Details:---
  Contact me: tal.gal...@gmail.com |  972-52-7275845
  Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
  www.r-statistics.com (English)
 
 --
 
 
 
 
  On Thu, Dec 8, 2011 at 5:24 PM, Michaelcomtech@gmail.com  wrote:
 
  Hi folks,
 
  In addition to Excel style tables, it would be great to have Excel 2010
  Pivot Table in R...
 
  Any thoughts?
 
  Thanks a lot!
 
  On Thu, Dec 8, 2011 at 4:49 AM, Tal Galilital.gal...@gmail.com
  wrote:
 
  I think it would be *great *if an extension of Duncan's new tables
  package could include themes and switches as are seen in the video
 Gabor
  just linked to.
 
 
  Tal
 
 
On Thu, Dec 8, 2011 at 6:58 AM, Gabor Grothendieck
  ggrothendi...@gmail.com  wrote:
 
On Wed, Dec 7, 2011 at 11:42 PM, Michaelcomtech@gmail.com
  wrote:
  Do you have an example...? Thanks a lot!
 
  See this video:
  http://www.woopid.com/video/1388/Format-as-Table
 
  --
  Statistics  Software Consulting
  GKX Group, GKX Associates Inc.
  tel: 1-877-GKX-GROUP
  email: ggrothendieck at 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.htmlhttp://www.r-project.org/posting-guide.html
 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.htmlhttp://www.r-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

 __
 R-help@r-project.org mailing list
 

Re: [R] labels in lattice

2011-12-14 Thread David Winsemius


On Dec 14, 2011, at 11:43 AM, matteo wrote:


set.seed(3)
mydata - data.frame(var = rnorm(100,20,1),
temp = sin(sort(rep(c(1:10),10))),
subj = as.factor(rep(c(1:10),5)))

and I need to make a scatter plot for each subj, not a problem, but...
what i want is to replace the strips from the lattice and add a  
label to

each plot.
I manage to do this with the following code, but I'm still not  
happy...


xyplot(var ~ temp | subj,
  data = mydata,
  strip=FALSE,
  panel = function(x, y,...) {
  panel.xyplot(x, y,...)
  panel.text(1,21,labels=which.packet())


Instead use the packet numer a an index into `letters`

   panel.text(1,21,labels=letters[which.packet()])


  })


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] Saving non table object as text file with outputting preserved?

2011-12-14 Thread David Winsemius


On Dec 14, 2011, at 10:01 AM, Tony Stocker wrote:


All,

Given the following commands:


ag.m35-read.table(m35.txt,header=TRUE,sep=,)
ag.m35.lp-subset(ag.m35, race==lp)
aov.m35.lp=aov(year~time,data=ag.m35.lp)
anova.m35.lp=anova(aov.m35.lp)
anova.m35.lp

Analysis of Variance Table

Response: year
 Df Sum Sq Mean Sq F value Pr(F)
time   1  11.56 11.5649  1.7282 0.1929
Residuals 70 468.44  6.6919


pwt.m35.lp-pairwise.t.test(ag.m35.lp$time,ag.m35.lp$year)
pwt.m35.lp


   Pairwise comparisons using t tests with pooled SD

data:  ag.m35.lp$time and ag.m35.lp$year

2002   2003   2004   2005   2006   2007   2008   2009
2003 0.0368 -  -  -  -  -  -  -
2004 1. 0.0072 -  -  -  -  -  -
2005 1. 1. 0.9733 -  -  -  -  -
2006 1. 1. 0.4370 1. -  -  -  -
2007 1. 1. 0.7099 1. 1. -  -  -
2008 1. 1. 0.7099 1. 1. 1. -  -
2009 1. 0.1465 1. 1. 1. 1. 1. -
2010 1. 0.0012 1. 0.3092 0.1244 0.2110 0.2125 1.


dput(pwt.m35.lp, foo)


Is there any way, other than dput(), to output something that is not a
table to a text file and preserve its formatting?


?capture.output
?mtable   # I think in pkg:mtable
?ftable
?latex   #in package:Hmisc



If you compare the
output of the implicit print statement in the R console line 
pwt.m35.lp, to the following output from # cat foo as the OS
command line you'll see that the exported text file from dput is not
formatted and easy to read as the output inside of R:

= cat foo
structure(list(method = t tests with pooled SD, data.name = g2$time
and g2$year,
   p.value = structure(c(0.0367532070877987, 1, 1, 1, 1, 1,
   1, 1, NA, 0.00718315554357665, 1, 1, 1, 1, 0.146481016374305,
   0.0012185417136, NA, NA, 0.973279068747759, 0.436956148539609,
   0.709867943596168, 0.709867943596168, 1, 1, NA, NA, NA, 1,
   1, 1, 1, 0.309223819660721, NA, NA, NA, NA, 1, 1, 1,  
0.124449626396277,

   NA, NA, NA, NA, NA, 1, 1, 0.210956065413139, NA, NA, NA,
   NA, NA, NA, 1, 0.212525673297984, NA, NA, NA, NA, NA, NA,
   NA, 1), .Dim = c(8L, 8L), .Dimnames = list(c(2003, 2004,
   2005, 2006, 2007, 2008, 2009, 2010), c(2002,
   2003, 2004, 2005, 2006, 2007, 2008, 2009))),
   p.adjust.method = holm), .Names = c(method, data.name,
p.value, p.adjust.method), class = pairwise.htest)


In addition to dput() I have tried using write(), write.table(), and
dump() to no avail.  Is what I'm trying to do something that's not
normally done or am I just missing an obvious elephant in the room?

Thanks

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] JavaGD package

2011-12-14 Thread Cable, Sam B Civ USAF AFMC AFRL/RVBXI
Am trying to install package JGR and, by necessity, JavaGD on a few
Linux platforms.  R rev. 2.14.0.  Had some success on one platform, but
am running into a problem on a new platform.  I installed rJava, JavaGD,
iplots, and JGR.  Things went - I thought - without a hitch.  Now, when
I try to use JGR, I start R and issue the command library(JGR) and get
an error message:

 

Error in library(pkg, character.only = TRUE, logical.return = TRUE,
lib.loc = lib.loc) :

  package 'JavaGD' does not have a NAMESPACE and should be re-installed

 

I tried re-installing and got the same result.  (rJava, by the way,
seems to load OK.)

 

I can't find any problem in the JavaGD config log.  I have no idea what
this means.  Anyone know what to do next?  Thanks.

 

--Sam Cable


[[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] labels in lattice

2011-12-14 Thread Patrick Connolly
On Wed, 14-Dec-2011 at 08:43AM -0800, matteo wrote:

| Dear all,
| 
| here is a simple problem that surely you already come across, but is giving
| me a big headache...
| 
| I have a dataframe like this:
| 
| set.seed(3)
| mydata - data.frame(var = rnorm(100,20,1),
|  temp = sin(sort(rep(c(1:10),10))),
|  subj = as.factor(rep(c(1:10),5)))
| 
| and I need to make a scatter plot for each subj, not a problem, but...
| what i want is to replace the strips from the lattice and add a label to
| each plot.
| I manage to do this with the following code, but I'm still not happy...
| 
| xyplot(var ~ temp | subj, 
|data = mydata,
|strip=FALSE,
|panel = function(x, y,...) {
|panel.xyplot(x, y,...)
|panel.text(1,21,labels=which.packet())
|}) 
| 
| The last bit...where i got stacked...is how to print letters instead of
| numbers in each panel. I would like to call the panels a,b,c... and so on.

Make a,b,c... the levels of your subj column and lattice does it all
for you.

HTH



| 
| Any suggestions...
| Many thanks
| matteo 
| 
| --
| View this message in context: 
http://r.789695.n4.nabble.com/labels-in-lattice-tp4195766p4195766.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.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
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] R - Linux_SSH

2011-12-14 Thread Patrick Connolly
On Wed, 14-Dec-2011 at 09:55AM -0800, Peter Langfelder wrote:

| On Wed, Dec 14, 2011 at 4:35 AM, Chris Mcowen chrismco...@gmail.com wrote:
|  Dear List,
| 
| 
| 
|  I am unsure if this is the correct list to post to, if it isn't I 
apologise.
| 
| 
| 
|  I am using SSH to access a Linux version of R on a remote computer as it
|  offers more memory and processing power. The model will take 1-2 days to
|  run, I am accessing R through Putty and when I close the connection and 
open
|  R again, I am faced with a new session.
| 
| 
| 
|  As a Linux newbie, I was wondering if anybody here knew how to keep R
|  running and interactive and return to it on a later date?
| 
| 
| 
| I am not aware of any way to keep the R session interactive although
| perhaps a VNC server/client may offer this possibility. If you have a

VNC will work fine.  Use putty to start the vnc server, then whatever
you set running will stay operational even though you disconnect the
client.  The server will keep running until it's stopped irrespective
of what goes on with the client.

HTH


| long calculation, put it all in a script named myScript.R (or any
| other file name) that does not require any human input, then run it as
| a batch using the nohup linux command:
| 
| nohup R CMD BATCH myScript.R
| 
| The nohup command will prevent the termination of your R after you log
| out, but you cannot run an interactive program this way.
| 
| HTH
| 
| Peter
| 
| 
| 
|  Thanks
| 
| 
| 
|  Chris
| 
| 
|

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
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] Simple R server for SQL Server?

2011-12-14 Thread Mike Beddo
I have a big SQL Server application that needs some help from R, and this R 
needs to load a large workspace in order to service the database request. I'd 
like to keep an R process running continually because loading the workspace 
takes about 1 minute. The data in the workspace doesn't change very often.

Rserve doesn't seem to align with my needs - I don't want a new workspace with 
each new connection, because I just have to load the large workspace I need 
each time.

So I want an R process with its workspace pre-loaded, sitting and waiting for 
requests from SQL Server. These would be simple requests, such as 
make-forecast. The R process crunches and puts the answers back into the 
database using RODBC.

I think I need two pieces?


1)  Some R code to set up a small server listening for the make-forecast 
command

2)  An intermediate program that SQL Server talks to, which in turn talks 
to the running R process. I don't know if SQL server can communicate to R 
through a socket, that's why I think I need an intermediate program.

All of this (R, SQL Server) would run on the same Windows server box.

Some small code examples for 1) would be helpful, but advice would be better.


-  Mike Beddo

[[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] uniroot function question

2011-12-14 Thread kchkchkch
Heh.  Yes, 
Berend Hasselman wrote
 
 Shouldn't the line with uniroot be (why try as function?)
 
 sol = uniroot(fcn, lower = p1, upper = 1)
 
 Before the line with  for(i in 1:n) insert the following
 
 fcn = function(p2) p1*f(p1) + (.20/5.66)*(exp(5.66*(p2 - p0)) -
 exp(5.66*(p1 - p0))) + (1 - p2)*f(p2) - as.numeric(f.integral$value) 
 curve(fcn, from=0, to=1)
 
 And it should be obvious what the problem is.
 
 Berend
 
 I had been trying various solutions (so I'd been trying stating the
functions a bunch of different ways)--hence the try in there.

but then I fixed it as you suggested--name the function correctly (insert
eyeroll at myself here), and move the fcn = line to outside the for
loop--and I still get the same error.

--
View this message in context: 
http://r.789695.n4.nabble.com/uniroot-function-question-tp4195737p4196520.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.


Re: [R] SQL select ... where R variable

2011-12-14 Thread Gabor Grothendieck
On Wed, Dec 14, 2011 at 7:04 AM, agent dunham crossp...@hotmail.com wrote:
 Thank you,

 I guess it didn't work for me, maybe is not possible?

 I've tried:

 con- odbcDriverConnect(Driver=SQL Server;
 Server=...\\...;Database=...;Uid=...;Pwd=... ;)

 v1=sqlQuery(con, select v1 from sqltable where v3 =cte and v2 in (select
 v2 from R_dataframe) order by (select v2 from R_dataframe))

 head(rbind(R_dataframe$v2, v1))
       [,1]
       1251
 v1 42S02 208 [Microsoft][ODBC SQL Server Driver][SQL Server]*The name of
 the object 'R_dataframe' is not valid.*

Since you have changed the problem by introducing new elements into it
clearly the answer must change too.  Either:

1. write R_variable to a table in your database and revise your SQL
statement so that its valid SQL or
2. if there are only a few elements in R_variable$x e.g. making it a
plain vector with R_variable - 1:10 then construct the appropriate
sql statement:

R_variable - 1:10
sql_stmt - sprintf(select v1
   from sqltable
   where v2 in ( %s )
   order by v2
, toString(R_variable))

which gives:

 cat(sql_stmt)
select v1
   from sql_table
   where v2 in ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )
   order by v2




-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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.


Re: [R] Download and Unzip a file

2011-12-14 Thread R. Michael Weylandt
Do unz / unzip get the job done?

Michael

On Wed, Dec 14, 2011 at 8:19 AM, himanshuy himanshu@gmail.com wrote:
 Hi

 I am trying to download and unzip a zip file from the following location.

 http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip

 I initially there was issue with useragent so i ran the following code

 options(HTTPUserAgent=Firefox/8.0.1)
 u =
 http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip;
 o = getURLContent(u, verbose = TRUE, useragent = getOption(HTTPUserAgent))

 now I want to unzip and save this file. I was initially working on matlab
 and have recently moved to R.
 any help would be much appreciated.

 Thanks
 Himanshu Y


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Download-and-Unzip-a-file-tp4194895p4194895.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] JavaGD package

2011-12-14 Thread Uwe Ligges



On 14.12.2011 19:43, Cable, Sam B Civ USAF AFMC AFRL/RVBXI wrote:

Am trying to install package JGR and, by necessity, JavaGD on a few
Linux platforms.  R rev. 2.14.0.  Had some success on one platform, but
am running into a problem on a new platform.  I installed rJava, JavaGD,
iplots, and JGR.  Things went - I thought - without a hitch.  Now, when
I try to use JGR, I start R and issue the command library(JGR) and get
an error message:



Error in library(pkg, character.only = TRUE, logical.return = TRUE,
lib.loc = lib.loc) :

   package 'JavaGD' does not have a NAMESPACE and should be re-installed



That means you have a JavaGD installation in one of your libraries that 
has been installed with R  2.14.0 but you are trying to use it with R 
= 2.14.0.


Uwe Ligges





I tried re-installing and got the same result.  (rJava, by the way,
seems to load OK.)



I can't find any problem in the JavaGD config log.  I have no idea what
this means.  Anyone know what to do next?  Thanks.



--Sam Cable


[[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] nice report generator?

2011-12-14 Thread Greg Snow
Richard,

I have looked at SWord before, but to my knowledge it does not deal directly 
with the tabular objects created by the tables package (please correct me if I 
am wrong).  These objects do have a matrix as the main data, but the attributes 
are different from the usual dimnames.   There are functions in tables that 
will then take this structure and print it out in a nice way with the headers, 
or work with the latex function to create a nice table for LaTeX, but there are 
not (yet) tools for doing this in MS products.  SWord and R2wd (and other 
tools) could transfer the data just fine, but then the column and row 
names/headers would still need to be put in by hand, which negates the whole 
convenience of using these tools.  One option would be to have a function in 
tables that converted to a regular matrix with some form of meaningful dimnames 
that could then be used with R2wd or SWord or odfWeave or other tools (that was 
one of my suggestions).

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111

From: Richard M. Heiberger [mailto:r...@temple.edu]
Sent: Wednesday, December 14, 2011 11:20 AM
To: Greg Snow
Cc: Duncan Murdoch; Tal Galili; r-help
Subject: Re: [R] nice report generator?

Greg,

Please look at the SWord package.  This package integrates MS Word with R
in a manner similar to the SWeave integration of LaTeX with R.
Download SWord from rcom.univie.ac.athttp://rcom.univie.ac.at
If you have a recent download of RExcel from the RAndFriends installer, then
you will already have SWord on your machine.

Rich

On Wed, Dec 14, 2011 at 12:39 PM, Greg Snow 
greg.s...@imail.orgmailto:greg.s...@imail.org wrote:
Duncan,

If you are taking suggestions for expanding the tables package (looks great) 
then I would suggest some way to get the tables into MS products.  If I create 
a full output/report myself then I am happy to work in LaTeX, but much of what 
I do is to produce tables and graphs to clients that don't know LaTeX and just 
want something that they can copy and paste into powerpoint or word.  For this 
I have been using the R2wd package (and the wdTable function for the tables).  
I would love to have some toolset that I could use your tables package to 
create the main table, then transfer it fairly simply to word or excel.  I 
don't care much about the fluff of how the table looks (coloring rows or 
columns, line widths, etc.) just getting it into a table (not just the text 
version).

One possibility is just an as.matrix method that would produce something that I 
could feed to wdTable.  Or just a textual representation of the table with 
columns separated by tabs so that it could be copied to the clipboard then 
pasted into excel or word (I would then let the client deal with all the tweaks 
on the appearance).

Thanks,

-Original Message-
From: r-help-boun...@r-project.orgmailto:r-help-boun...@r-project.org 
[mailto:r-help-boun...@r-project.orgmailto:r-help-boun...@r-project.org] On 
Behalf Of Duncan Murdoch
Sent: Thursday, December 08, 2011 4:52 PM
To: Tal Galili
Cc: r-help
Subject: Re: [R] nice report generator?

On 11-12-08 1:37 PM, Tal Galili wrote:
 Helloe dear Duncan, Gabor, Michael and others,

 Do you think it could be (reasonably) possible to create a bridge between a
 cast_df object from the {reshape} package into a table in Duncan's new
 {tables} package?

I'm not that familiar with the reshape package (and neither it nor
reshape2 appears to have a vignette to give me an overview), so I don't
have any idea if that makes sense.  The table package is made to work on
dataframes, and only dataframes.  It converts them into matrices with
lots of attributes, so that the print methods can put nice labels on.
But it's strictly rectangular to rectangular in the kinds of conversions
it does, and from the little I know about reshape, it works on more
general arrays, converting them to and from dataframes.



 That would allow one to do pivot-table like operations on an object using
 {reshape}, and then display it (as it would have been in excel - or better)
 using the {tables} package.

You'll have to give an example of what you want to do.

Duncan Murdoch








 Contact
 Details:---
 Contact me: tal.gal...@gmail.commailto:tal.gal...@gmail.com |  
 972-52-7275845
 Read me: www.talgalili.comhttp://www.talgalili.com/ (Hebrew) | 
 www.biostatistics.co.ilhttp://www.biostatistics.co.il/ (Hebrew) |
 www.r-statistics.comhttp://www.r-statistics.com/ (English)
 --




 On Thu, Dec 8, 2011 at 5:24 PM, 
 Michaelcomtech@gmail.commailto:comtech@gmail.com  wrote:

 Hi folks,

 In addition to Excel style tables, it would be great to have Excel 2010
 Pivot Table in R...

 Any thoughts?

 Thanks a lot!

 On Thu, Dec 8, 2011 at 4:49 AM, Tal 
 

Re: [R] nice report generator?

2011-12-14 Thread Greg Snow
There is also the problem that SWord's license does not allow for commercial 
use.  R2wd, write.table, and odfWeave don't have this restriction.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111

From: Richard M. Heiberger [mailto:r...@temple.edu]
Sent: Wednesday, December 14, 2011 11:20 AM
To: Greg Snow
Cc: Duncan Murdoch; Tal Galili; r-help
Subject: Re: [R] nice report generator?

Greg,

Please look at the SWord package.  This package integrates MS Word with R
in a manner similar to the SWeave integration of LaTeX with R.
Download SWord from rcom.univie.ac.athttp://rcom.univie.ac.at
If you have a recent download of RExcel from the RAndFriends installer, then
you will already have SWord on your machine.

Rich

On Wed, Dec 14, 2011 at 12:39 PM, Greg Snow 
greg.s...@imail.orgmailto:greg.s...@imail.org wrote:
Duncan,

If you are taking suggestions for expanding the tables package (looks great) 
then I would suggest some way to get the tables into MS products.  If I create 
a full output/report myself then I am happy to work in LaTeX, but much of what 
I do is to produce tables and graphs to clients that don't know LaTeX and just 
want something that they can copy and paste into powerpoint or word.  For this 
I have been using the R2wd package (and the wdTable function for the tables).  
I would love to have some toolset that I could use your tables package to 
create the main table, then transfer it fairly simply to word or excel.  I 
don't care much about the fluff of how the table looks (coloring rows or 
columns, line widths, etc.) just getting it into a table (not just the text 
version).

One possibility is just an as.matrix method that would produce something that I 
could feed to wdTable.  Or just a textual representation of the table with 
columns separated by tabs so that it could be copied to the clipboard then 
pasted into excel or word (I would then let the client deal with all the tweaks 
on the appearance).

Thanks,

-Original Message-
From: r-help-boun...@r-project.orgmailto:r-help-boun...@r-project.org 
[mailto:r-help-boun...@r-project.orgmailto:r-help-boun...@r-project.org] On 
Behalf Of Duncan Murdoch
Sent: Thursday, December 08, 2011 4:52 PM
To: Tal Galili
Cc: r-help
Subject: Re: [R] nice report generator?

On 11-12-08 1:37 PM, Tal Galili wrote:
 Helloe dear Duncan, Gabor, Michael and others,

 Do you think it could be (reasonably) possible to create a bridge between a
 cast_df object from the {reshape} package into a table in Duncan's new
 {tables} package?

I'm not that familiar with the reshape package (and neither it nor
reshape2 appears to have a vignette to give me an overview), so I don't
have any idea if that makes sense.  The table package is made to work on
dataframes, and only dataframes.  It converts them into matrices with
lots of attributes, so that the print methods can put nice labels on.
But it's strictly rectangular to rectangular in the kinds of conversions
it does, and from the little I know about reshape, it works on more
general arrays, converting them to and from dataframes.



 That would allow one to do pivot-table like operations on an object using
 {reshape}, and then display it (as it would have been in excel - or better)
 using the {tables} package.

You'll have to give an example of what you want to do.

Duncan Murdoch








 Contact
 Details:---
 Contact me: tal.gal...@gmail.commailto:tal.gal...@gmail.com |  
 972-52-7275845
 Read me: www.talgalili.comhttp://www.talgalili.com/ (Hebrew) | 
 www.biostatistics.co.ilhttp://www.biostatistics.co.il/ (Hebrew) |
 www.r-statistics.comhttp://www.r-statistics.com/ (English)
 --




 On Thu, Dec 8, 2011 at 5:24 PM, 
 Michaelcomtech@gmail.commailto:comtech@gmail.com  wrote:

 Hi folks,

 In addition to Excel style tables, it would be great to have Excel 2010
 Pivot Table in R...

 Any thoughts?

 Thanks a lot!

 On Thu, Dec 8, 2011 at 4:49 AM, Tal 
 Galilital.gal...@gmail.commailto:tal.gal...@gmail.com  wrote:

 I think it would be *great *if an extension of Duncan's new tables
 package could include themes and switches as are seen in the video Gabor
 just linked to.


 Tal


   On Thu, Dec 8, 2011 at 6:58 AM, Gabor Grothendieck
 ggrothendi...@gmail.commailto:ggrothendi...@gmail.com  wrote:

   On Wed, Dec 7, 2011 at 11:42 PM, 
 Michaelcomtech@gmail.commailto:comtech@gmail.com  wrote:
 Do you have an example...? Thanks a lot!

 See this video:
 http://www.woopid.com/video/1388/Format-as-Table

 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.comhttp://gmail.com/

 __
 R-help@r-project.orgmailto:R-help@r-project.org mailing list
 

Re: [R] nice report generator?

2011-12-14 Thread Richard M. Heiberger
On Wed, Dec 14, 2011 at 4:43 PM, Greg Snow greg.s...@imail.org wrote:

  There is also the problem that SWord’s license does not allow for
 commercial use.  R2wd, write.table, and odfWeave don’t have this
 restriction.


The free license for SWord does have the commercial use restriction.
There is also a commerical license available.  You will need to write to
Thomas Baier tho...@statconn.com for details.

You will also need to discuss with Thomas what would be involved in making
the
tables package work smoothly with SWord.

Rich


  

 ** **

 -- 

 Gregory (Greg) L. Snow Ph.D.

 Statistical Data Center

 Intermountain Healthcare

 greg.s...@imail.org

 801.408.8111

 ** **

 *From:* Richard M. Heiberger [mailto:r...@temple.edu]
 *Sent:* Wednesday, December 14, 2011 11:20 AM
 *To:* Greg Snow
 *Cc:* Duncan Murdoch; Tal Galili; r-help

 *Subject:* Re: [R] nice report generator?

   ** **

 Greg,

  

 Please look at the SWord package.  This package integrates MS Word with R*
 ***

 in a manner similar to the SWeave integration of LaTeX with R.

 Download SWord from rcom.univie.ac.at

 If you have a recent download of RExcel from the RAndFriends installer,
 then

 you will already have SWord on your machine.

  

 Rich

  

 On Wed, Dec 14, 2011 at 12:39 PM, Greg Snow greg.s...@imail.org wrote:**
 **

 Duncan,

 If you are taking suggestions for expanding the tables package (looks
 great) then I would suggest some way to get the tables into MS products.
  If I create a full output/report myself then I am happy to work in LaTeX,
 but much of what I do is to produce tables and graphs to clients that don't
 know LaTeX and just want something that they can copy and paste into
 powerpoint or word.  For this I have been using the R2wd package (and the
 wdTable function for the tables).  I would love to have some toolset that I
 could use your tables package to create the main table, then transfer it
 fairly simply to word or excel.  I don't care much about the fluff of how
 the table looks (coloring rows or columns, line widths, etc.) just getting
 it into a table (not just the text version).

 One possibility is just an as.matrix method that would produce something
 that I could feed to wdTable.  Or just a textual representation of the
 table with columns separated by tabs so that it could be copied to the
 clipboard then pasted into excel or word (I would then let the client deal
 with all the tweaks on the appearance).

 Thanks,


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Duncan Murdoch
 Sent: Thursday, December 08, 2011 4:52 PM
 To: Tal Galili
 Cc: r-help
 Subject: Re: [R] nice report generator?

 On 11-12-08 1:37 PM, Tal Galili wrote:
  Helloe dear Duncan, Gabor, Michael and others,
 
  Do you think it could be (reasonably) possible to create a bridge
 between a
  cast_df object from the {reshape} package into a table in Duncan's new
  {tables} package?

 I'm not that familiar with the reshape package (and neither it nor
 reshape2 appears to have a vignette to give me an overview), so I don't
 have any idea if that makes sense.  The table package is made to work on
 dataframes, and only dataframes.  It converts them into matrices with
 lots of attributes, so that the print methods can put nice labels on.
 But it's strictly rectangular to rectangular in the kinds of conversions
 it does, and from the little I know about reshape, it works on more
 general arrays, converting them to and from dataframes.


 
  That would allow one to do pivot-table like operations on an object using
  {reshape}, and then display it (as it would have been in excel - or
 better)
  using the {tables} package.

 You'll have to give an example of what you want to do.

 Duncan Murdoch


 
 
 
 
 
 
  Contact
  Details:---
  Contact me: tal.gal...@gmail.com |  972-52-7275845
  Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
  www.r-statistics.com (English)
 
 --
 
 
 
 
  On Thu, Dec 8, 2011 at 5:24 PM, Michaelcomtech@gmail.com  wrote:
 
  Hi folks,
 
  In addition to Excel style tables, it would be great to have Excel 2010
  Pivot Table in R...
 
  Any thoughts?
 
  Thanks a lot!
 
  On Thu, Dec 8, 2011 at 4:49 AM, Tal Galilital.gal...@gmail.com
  wrote:
 
  I think it would be *great *if an extension of Duncan's new tables
  package could include themes and switches as are seen in the video
 Gabor
  just linked to.
 
 
  Tal
 
 
On Thu, Dec 8, 2011 at 6:58 AM, Gabor Grothendieck
  ggrothendi...@gmail.com  wrote:
 
On Wed, Dec 7, 2011 at 11:42 PM, Michaelcomtech@gmail.com
  wrote:
  Do you have an example...? Thanks a lot!
 
  See this video:
  http://www.woopid.com/video/1388/Format-as-Table
 

Re: [R] Hi

2011-12-14 Thread Trying To learn again
Hi all,

I have solved my question


Output- matrix(0, length(x), 1)


for (i in 1:length(x)){

files - paste('KT', i, '.csv', sep = '')



da1 - read.csv(files)

Output[i,1]-da1[1,2]
}


2011/12/14 Trying To learn again tryingtolearnag...@gmail.com

 Hi all,

 I have 100 csv files always with this information (I Attach two example
 excels)

 KT80.csv contains:
  ,x
  1,127.188271604938

 KT80.csv contains

  ,x
  1,1.06329287351545


 I have three questions:

 First

 When I created this input files I used write.csv and it authomaticaly
 creates the structure of the file as you can see.

 Second. If I try to read csv it appears:

  read.csv(KT2.csv,header=T, sep='.')
 Error en read.table(file = file, header = header, sep = sep, quote =
 quote,  :
   objeto 'KT2.csv' no encontrado

 But the file is in the right directy

 Third (supossing I can solve the format files)

 My main question is:

 I want to create a matrix (or data frame) for instance from file KT80.csv
 to KT81.csv so that the rows are without header and position.



 127.18
 1.06


 Wich function would help me?

 I think I should use something like



 ffor (i in 80:81){

 files - paste('KT', i, '.csv', sep = '')

 myfun - function(d) {

 da1 - read.csv(d)

 Output[i,1]=da1[1,2]



 }

 lout- lapply(files, myfun)

 }

 But results that says Output doesn´t exists?

 I must create before? How?

 Many Thans¡¡¡


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

2011-12-14 Thread Trying To learn again
First PRoblem solved

 read.csv(KT80.csv)
  X  x
1 1 0.01331361


I ommitt  in calling the file name...



2011/12/14 Trying To learn again tryingtolearnag...@gmail.com

 Hi all,

 I have 100 csv files always with this information (I Attach two example
 excels)

 KT80.csv contains:
  ,x
  1,127.188271604938

 KT80.csv contains

  ,x
  1,1.06329287351545


 I have three questions:

 First

 When I created this input files I used write.csv and it authomaticaly
 creates the structure of the file as you can see.

 Second. If I try to read csv it appears:

  read.csv(KT2.csv,header=T, sep='.')
 Error en read.table(file = file, header = header, sep = sep, quote =
 quote,  :
   objeto 'KT2.csv' no encontrado

 But the file is in the right directy

 Third (supossing I can solve the format files)

 My main question is:

 I want to create a matrix (or data frame) for instance from file KT80.csv
 to KT81.csv so that the rows are without header and position.



 127.18
 1.06


 Wich function would help me?

 I think I should use something like



 ffor (i in 80:81){

 files - paste('KT', i, '.csv', sep = '')

 myfun - function(d) {

 da1 - read.csv(d)

 Output[i,1]=da1[1,2]



 }

 lout- lapply(files, myfun)

 }

 But results that says Output doesn´t exists?

 I must create before? How?

 Many Thans¡¡¡


[[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] htest class members and print method

2011-12-14 Thread Rui Barradas
Hello,

I am writing a test function, and would like to have it return an
appropriate 'htest'
object. This is very easy, but the test can be run for several orders, a
frequent situation
in time series tests.

It would be nice to return a data.frame with order, params, test statistic,
p.value.

After seeing the 'htest' members in the help pages, I discovered that the
class has a 'null.value' member that fits the job (it's what I'm using) but
it's name may be misleading.

Is it possible to create a new member with a new, or at least different,
name and have print.htest correctly print it?


Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/htest-class-members-and-print-method-tp4196932p4196932.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.


Re: [R] labels in lattice

2011-12-14 Thread matteo dossena
Thanks David and Patrick,

really appreciate tour help...

m.


Il giorno 14 Dec 2011, alle ore 18:33, David Winsemius ha scritto:

 
 On Dec 14, 2011, at 11:43 AM, matteo wrote:
 
 set.seed(3)
 mydata - data.frame(var = rnorm(100,20,1),
   temp = sin(sort(rep(c(1:10),10))),
   subj = as.factor(rep(c(1:10),5)))
 
 and I need to make a scatter plot for each subj, not a problem, but...
 what i want is to replace the strips from the lattice and add a label to
 each plot.
 I manage to do this with the following code, but I'm still not happy...
 
 xyplot(var ~ temp | subj,
 data = mydata,
 strip=FALSE,
 panel = function(x, y,...) {
 panel.xyplot(x, y,...)
 panel.text(1,21,labels=which.packet())
 
 Instead use the packet numer a an index into `letters`
 
  panel.text(1,21,labels=letters[which.packet()])
 
 })
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT


__
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] Reading Oracle SQL Developer BLOB/CLOB files into R (Packages: DBI, foreign, RODBC, ROracle)

2011-12-14 Thread hardworker
Hi everyone,

I have been following these forums closely for the last few months but this
is my first time posting. Basically I am trying to get an Oracle SQL
Developer Binary Large Object(BLOB/CLOB) file in as an R object in R. For
those not familiar with a BLOB/CLOB file, it is basically lik a table that
has cells that contain tables or files. By converting the large table into a
BLOB/CLOB file the size of the file can be greatly reduced and processing
for various applications improved.

I am approaching this problem with the help of a colleague who is looking at
solutions from a Java point of view while I am looking at solutions from a R
point of view. We have searched and found many packages such as:
- RODBC (Doesn't support BLOB objects)
- ROracle (Received an error message)
- Foreign(Seems to enable reading of SAS, minitab, SPSS and many other
software packages into R but not BLOB columns)
-DBI (Enables direct connection to R but had errors)

Below I present the error message as well as what we think is going on with
R when it is trying to convert the BLOB object into an R object (We could be
wrong so please correct us if we are wrong):

 We believe ROracle/DBI is capable because it did not return error when
reading from BLOB column, but instead it converted the column into
String(255) (This is what we think it did based on following message)


 rs - dbSendQuery(con, SELECT CLOB_COL from R_BLOB_TEST where ROW_ID=1)
Warning message:
In oraExecStatement(ps, ora.buf.size = as.integer(ora.buf.size)) :
  RS-DBI driver warning: (unkown ORA type 112 (extracted as STRING(255)))

The Ora type 113 and 112 seem to be pointing to CLOB and BLOB objects as
being unrecognised. Is there anyway to fix this?

So far our attempts on the R side have not been good but we have found lots
of material on using java to convert a BLOB file into another object like an
XML then reading that into R. But there are two more packages: rJava and
RUniversal that may enable us to use Java jar files or the Java language to
convert to R itself. I personally don't understand these java packages too
well but my colleague will be looking at them today in more detail but if
anyone can shed some light on this problem it would be a great help.

Best Regards,

hardworker

--
View this message in context: 
http://r.789695.n4.nabble.com/Reading-Oracle-SQL-Developer-BLOB-CLOB-files-into-R-Packages-DBI-foreign-RODBC-ROracle-tp4197551p4197551.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] Storing graphics

2011-12-14 Thread JulieV
Dear R members,

I would like to store 18 graphics at the end of a loop (as we do for data
frames and arrays). For each iteration, I use the function x11() and I want
to keep my graphs in a single window to re-use them later. Do you know a
function for storing graphics ? 

Many thanks

Julie

--
View this message in context: 
http://r.789695.n4.nabble.com/Storing-graphics-tp4196952p4196952.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] Omit Inf

2011-12-14 Thread Trying To learn again
Hi all

 a-c(2,Inf)
 max(a)
[1] Inf


How can I say...omit Inf?

I cannot find anything...

[[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] Omit Inf

2011-12-14 Thread William Dunlap
 range(a, finite=TRUE)[2]  # [1] for the min
[1] 2

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Trying To learn
 again
 Sent: Wednesday, December 14, 2011 3:55 PM
 To: r-help@r-project.org
 Subject: [R] Omit Inf
 
 Hi all
 
  a-c(2,Inf)
  max(a)
 [1] Inf
 
 
 How can I say...omit Inf?
 
 I cannot find anything...
 
   [[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] Omit Inf

2011-12-14 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of William Dunlap
 Sent: Wednesday, December 14, 2011 4:19 PM
 To: Trying To learn again; r-help@r-project.org
 Subject: Re: [R] Omit Inf
 
  range(a, finite=TRUE)[2]  # [1] for the min
 [1] 2
 
 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Trying To learn
  again
  Sent: Wednesday, December 14, 2011 3:55 PM
  To: r-help@r-project.org
  Subject: [R] Omit Inf
 
  Hi all
 
   a-c(2,Inf)
   max(a)
  [1] Inf
  
 
  How can I say...omit Inf?
 
  I cannot find anything...
 

You could use something like

max(a[is.finite(a)])


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


__
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] Storing graphics

2011-12-14 Thread Bert Gunter
Please follow the posting guide and provide some example code.

Bottom line, most functions that draw a graph return a graphic
object that, like any other R object, can be given a name in the
global environment, put into a list, etc.

Alternatively, depending on what you mean -- it was not entirely clear
to me -- merely store the code that produced the objects and they can
be reproduced at will (with some possible caveats due to e.g. possible
random number generation) from the data in a saved workspace --
?save.image.

As always, a careful reading of R's docs and Help files would probably
tell you what you need to know.

-- Bert

On Wed, Dec 14, 2011 at 12:52 PM, JulieV sharkette...@hotmail.com wrote:
 Dear R members,

 I would like to store 18 graphics at the end of a loop (as we do for data
 frames and arrays). For each iteration, I use the function x11() and I want
 to keep my graphs in a single window to re-use them later. Do you know a
 function for storing graphics ?

 Many thanks

 Julie

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Storing-graphics-tp4196952p4196952.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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] windrose color ramp issue

2011-12-14 Thread MacQueen, Don
There is also a windrose (though not with that name) function in the
openair package.
-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 12/12/11 1:20 PM, Adrienne Wootten amwoo...@ncsu.edu wrote:

Greetings!

I'm having an issue with the windrose produced by the windrose
function from the circular package.  For our weather stations in North
Carolina I'm helping with a script which takes hourly wind speed and
direction data to create windroses for our end users.  One of the
stations in the mountains frequently reaches wind speed of 40 to 60
mph and in storms can reach wind speed over 80 mph.  This has brought
up an issue with the color ramp.

Currently the color ramp works one of two ways:

#1) Holding the pedal colors fixed:

incrspeeds = 2 # fills out the increments argument
pedalcolors =  
c(darkblue,blue,royalblue,darkturquoise,forestgreen,green,yel
lowgreen,yellow4,yellow,orange,red,darkred,violetred,mediumo
rchid,purple)

#or 2) Making the pedal colors dynamic based on the increments and the
max wind speed.

incrspeeds = 2 # fills out the increments argument

breaks=seq(0,round(maxwind),incrspeeds) # maxwind is the maximum wind
speed
numcolors=length(breaks)

if(numcolorslength(pedalcolors)){
pedalcolors=rev(rainbow(numcolors))
}

# In either case the result ends up in the wind rose function

rose=windrose(wr,breaks=NULL,bins=numpedals,increment=incrspeeds,main=NULL
,fill.col=pedalcolors,plot.mids=FALSE,units=degrees,template=geographic
s,ticks=FALSE,osize=0.05,cir.ind
=0.05,cex=0.9,zero=NULL,rotation=NULL,right=FALSE,shrink=NULL,label.freq=T
RUE,calm=c(0),number.calm=TRUE)

The issue when there are really large wind speeds in the first case,
the windrose wraps the color ramp twice in both the legend and the
windrose itself, and then gives only white for the remaining bands of
each pedal.  For the second case, when pedalcolors will have the same
number of colors as numcolors, the legend has the right color ramp,
but the pedals of the windrose don't have all the colors that are
passed to it.  Say pedalcolors has 40 colors, which are included in
the legend, but the windrose only includes the first 16 colors in
pedalcolors.

Any thoughts as to why this might be happening in either case?  Thanks!

Adrienne

-- 
Adrienne Wootten
Graduate Research Assistant
State Climate Office of North Carolina
Department of Marine, Earth and Atmospheric Sciences
North Carolina State University

__
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] windrose color ramp issue

2011-12-14 Thread Clint Bowman

library(openair)
?windRose

--
Clint BowmanINTERNET:   cl...@ecy.wa.gov
Air Quality Modeler INTERNET:   cl...@math.utah.edu
Department of Ecology   VOICE:  (360) 407-6815
PO Box 47600FAX:(360) 407-7534
Olympia, WA 98504-7600


USPS:   PO Box 47600, Olympia, WA 98504-7600
Parcels:300 Desmond Drive, Lacey, WA 98503-1274


On Wed, 14 Dec 2011, MacQueen, Don wrote:


There is also a windrose (though not with that name) function in the
openair package.
-Don




__
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] axis tick colors: only one value allowed?

2011-12-14 Thread Carl Witthoft
That only puts different colors on different axes.  I was wondering 
about the (silly) possibility of having a range of colors for the ticks 
on a given axis.



quote
From: Hans W Borchers hwborchers_at_googlemail.com
Date: Tue, 13 Dec 2011 14:21:31 +
Carl Witthoft carl at witthoft.com writes:


 Hi,
 So far as I can tell, the 'col.ticks' parameter for axis() only uses the
 first value provided. E.g.:

 plot(0:1,0:1, col.ticks=c('blue','red','green')) #all ticks are blue

 Just wondering if there's a different option in the basic plot commands
 that can handle multiple colors, and also whether ggplot and/or lattice
 allow for multiple tick colors.
See `?axis' or try this:

plot(0:1,0:1, type = n, axes = FALSE) box()
axis(side=1, lwd.ticks = 2, col.ticks=blue) axis(side=2, 
lwd.ticks = 2, col.ticks=red)

--

Sent from my Cray XK6
Pendeo-navem mei anguillae plena est.

__
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] Storing graphics

2011-12-14 Thread Prof Brian Ripley

Bert,

The OP may be looking for recordPlot/replayPlot.

We were not told the OS (x11 exists even on Windows).  The standard 
screen devices on Windows (windows() ) and Mac OS X (quartz()) have plot 
histories that can be used to flick between plots.  And 'flick' is the 
operative word here: it is quick and under mouse/PgUp/PgDn control. 
AFAIR Rstudio has copied the idea.


With as many as 18 plots, I would be looking for more effective ways to 
browse them, and probably produce PNGs to view in an image browser or a 
multi-page PDF to browse in a viewer which showed thumbnails.


On 15/12/2011 00:34, Bert Gunter wrote:

Please follow the posting guide and provide some example code.

Bottom line, most functions that draw a graph return a graphic
object that, like any other R object, can be given a name in the
global environment, put into a list, etc.

Alternatively, depending on what you mean -- it was not entirely clear
to me -- merely store the code that produced the objects and they can
be reproduced at will (with some possible caveats due to e.g. possible
random number generation) from the data in a saved workspace --
?save.image.

As always, a careful reading of R's docs and Help files would probably
tell you what you need to know.

-- Bert

On Wed, Dec 14, 2011 at 12:52 PM, JulieVsharkette...@hotmail.com  wrote:

Dear R members,

I would like to store 18 graphics at the end of a loop (as we do for data
frames and arrays). For each iteration, I use the function x11() and I want
to keep my graphs in a single window to re-use them later. Do you know a
function for storing graphics ?

Many thanks

Julie




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

__
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] axis tick colors: only one value allowed?

2011-12-14 Thread Peter Ehlers

On 2011-12-14 18:32, Carl Witthoft wrote:

That only puts different colors on different axes.  I was wondering
about the (silly) possibility of having a range of colors for the ticks
on a given axis.



I think you would have to either hack the code or issue
several axis() calls, e.g.

  plot(1:9, 1:9, axes=FALSE, frame=TRUE)
  axis(1, at=c(1,4,7), col.ticks=2, lwd.ticks=2)
  axis(1, at=c(2,5,8), col.ticks=3, lwd.ticks=2)
  axis(1, at=c(3,6,9), col.ticks=4, lwd.ticks=2)

Add col.axis=yourColourChoice arguments if you also want
coloured labels.

Peter Ehlers



quote
From: Hans W Borchershwborchers_at_googlemail.com
Date: Tue, 13 Dec 2011 14:21:31 +
Carl Witthoftcarlat  witthoft.com  writes:

  
Hi,
So far as I can tell, the 'col.ticks' parameter for axis() only uses the
first value provided. E.g.:
  
plot(0:1,0:1, col.ticks=c('blue','red','green')) #all ticks are blue
  
Just wondering if there's a different option in the basic plot commands
that can handle multiple colors, and also whether ggplot and/or lattice
allow for multiple tick colors.
See `?axis' or try this:

  plot(0:1,0:1, type = n, axes = FALSE) box()
  axis(side=1, lwd.ticks = 2, col.ticks=blue) axis(side=2,
lwd.ticks = 2, col.ticks=red)


__
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] Download and Unzip a file

2011-12-14 Thread himanshuy
I tried using unzip but it gave the following error Invalid zip name
argument 

options(HTTPUserAgent=Firefox/8.0.1)
u =
http://www.nseindia.com/content/historical/DERIVATIVES/2011/DEC/fo08DEC2011bhav.csv.zip;
o = getURLContent(u, verbose = TRUE, useragent = getOption(HTTPUserAgent)) 

after this I ran the unzip
unzip(o , files = NULL, list = FALSE, overwrite = TRUE, junkpaths = FALSE,
exdir = D:\\, unzip = internal, setTimes = FALSE)

but i got this error

Error in unzip(o, files = NULL, list = FALSE, overwrite = TRUE, junkpaths =
FALSE,  : 
  invalid zip name argument

Thanks
Himanshu Y

--
View this message in context: 
http://r.789695.n4.nabble.com/Download-and-Unzip-a-file-tp4194895p4198145.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] Trouble converting hourly data into daily data

2011-12-14 Thread Sean Baumgarten
Hello,

I have a data frame with hourly or sub-hourly weather records that span
several years, and from that data frame I'm trying to select only the
records taken closest to noon for each day. Here's what I've done so far:

#Add a column to the data frame showing the difference between noon and the
observation time (I converted time to a 0-1 scale so 0.5 represents noon):
data$Diff_from_noon - abs(0.5-data$Time)

#Find the minimum value of Diff_from_noon for each Date:
aggregated - aggregate(Diff_from_noon ~ Date, data, FUN=min)


The problem is that the aggregated data frame only has two columns: Date
and Diff_from_noon. I can't figure out how to get the columns with the
actual weather variables to carry over from the original data frame.

Any suggestions you have would be much appreciated.

Thanks,
Sean

[[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] Inquiry about matrix pooling

2011-12-14 Thread Jana Makedonska
Dear R-users,


I am a relatively new R user and I have a simple question. Is there a
command attached to a R function, which performs matrix pooling?


Thanks in advance,
Jana

-- 

-- 
The world is full of mysteries. Life is one. The curious limitations of
finite minds are another.(J.B.S. Haldane, The Causes of Evolution)

Jana Makedonska, M.Sc.
Ph.D. candidate/ Part-time lecturer
Department of Anthropology
College of Arts  Sciences
State University of New York at Albany
1400 Washington Avenue
1 Albany, NY
Office phone: 518-442-4699

[[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] Monetary support to the R-project (Was: Re: Executable for Production Use)

2011-12-14 Thread Xu Wang
I am still interested in this. Is there no way to pay directly online? via
paypal or other?

Thanks,

Xu

--
View this message in context: 
http://r.789695.n4.nabble.com/Re-Monetary-support-to-the-R-project-Was-Re-Executable-for-Production-Use-tp1585186p4198369.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] how to draw random numbers from many categorical distributions quickly?

2011-12-14 Thread Sean Zhang
Dear R helpers,

I have a question about drawing random numbers from many categorical
distributions.

Consider n individuals, each follows a categorical distribution defined
over k categories.
Consider a simple case in which n=4, k=3 as below

catDisMat -
rbind(c(0.1,0.2,0.7),c(0.2,0.2,0.6),c(0.1,0.2,0.7),c(0.1,0.2,0.7))

outVec - rep(NA,nrow(catDisMat))
for (i in 1:nrow(catDisMat)){
outVec[i] - sample(1:3,1, prob=catDisMat[i,], replace = TRUE)
}

I can think of one way to potentially speed it up (in reality, my n is very
large, so speed matters). The approach above only samples 1 value each
time. I could have sampled two values for c(0.1,0.2,0.7) because it appears
three times. so by doing some manipulation, I think I can have the idea,
sample(1:3, 3, prob=c(0.1,0.2,0.7), replace = TRUE),  implemented to
improve speed a bit. But, I wonder whether there is a better approach for
speed?

Thanks in advance.

-Sean

[[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] modify the name of axis of an R function

2011-12-14 Thread plocq
Hi,

I use the function fpot of packages evd. If I call the fit that I obtain
fit, I want to modify the name of the axis and the main title that is
produced by plot(fit1). To do this, I want to create a new function where I
would have the names modified. The problem is that I can't find the function
that produce these plots... I tried to see in plot.uvevd but it doesn't
seems to be the good one. Can anybody help me?
Many thanks! 

--
View this message in context: 
http://r.789695.n4.nabble.com/modify-the-name-of-axis-of-an-R-function-tp4198804p4198804.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.


Re: [R] uniroot function question

2011-12-14 Thread Berend Hasselman

kchkchkch wrote
 
 Heh.  Yes, 
 Berend Hasselman wrote
 
 Shouldn't the line with uniroot be (why try as function?)
 
 sol = uniroot(fcn, lower = p1, upper = 1)
 
 Before the line with  for(i in 1:n) insert the following
 
 fcn = function(p2) p1*f(p1) + (.20/5.66)*(exp(5.66*(p2 - p0)) -
 exp(5.66*(p1 - p0))) + (1 - p2)*f(p2) - as.numeric(f.integral$value) 
 curve(fcn, from=0, to=1)
 
 And it should be obvious what the problem is.
 
 Berend
 
  I had been trying various solutions (so I'd been trying stating the
 functions a bunch of different ways)--hence the try in there.
 
 but then I fixed it as you suggested--name the function correctly (insert
 eyeroll at myself here), and move the fcn = line to outside the for
 loop--and I still get the same error.
 

Yes of course.
But you are misinterpreting what I wrote.

I said to insert two lines (NOT move) before the start of the for loop. The
second line to insert was curve() which will draw a plot of your function
for the first case. And you will see that the function fcn does not cross
the horizontal axis which it should do if it is to have a root for fcn(x)=0.
So you need to take a closer look at your function.

Berend

--
View this message in context: 
http://r.789695.n4.nabble.com/uniroot-function-question-tp4195737p4198877.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.