Re: [R] Accumulating results from "for" loop in a list/array

2009-09-10 Thread Schalk Heunis
Steven

I think list() can help you

##
indlist = list()
 for (i in 1:(dim(x)[2]))  {
 indlist[[paste("ind", i, sep = "")]] <-  which(x[ , i] == "y")
 }
accum = unlist(indlist)
print(indlist$ind1)
###

Schalk Heunis



On Fri, Sep 11, 2009 at 7:52 AM, Steven Kang  wrote:
> Dear R users,
>
>
> I would like to accumulate objects generated from 'for' loop to a list or
> array.
>
> To illustrate the problem, arbitrary data set and script is shown below,
>
>
> x <- data.frame(a = c(rep("n",3),rep("y",2),rep("n",3),rep("y",2)), b =
> c(rep("y",2),rep("n",4),rep("y",3),"n"), c = c(rep("n",7),rep("y",3)), d =
> c("y", rep("n",4), rep("y",2), rep("n",3)))
>
> for (i in 1:(dim(x)[2]))  {
>         assign(paste("ind", i, sep = ""), which(x[ , i] == "y"))
>          accum <- c(ind1, ind2, ind3, ind4)
> }
>
>> ind1
> [1]  4  5  9 10
>> ind2
> [1] 1 2 7 8 9
>> ind3
> [1]  8  9 10
>> ind4
> [1] 1 6 7
>> accum
>  [1]  4  5  9 10  1  2  7  8  9  8  9 10  1  6  7
>
> Are there any alternative method where the highlighted statement above can
> be represented without typing individual objects manually? (as it can be
> very tedious with large number of objects; i.e ind1, ind2, ., ind100)
>
> Also, is there any way to extract individual objects ('ind1' etc) from
> 'accum'?
>
>> accum[1:length(ind1)]
> [1]  4  5  9 10
> gives 'ind1', but this may become messy for other objects (like 'ind10')
>
>
> Highly appreciate for sharing your expertise in solving this problem.
>
>        [[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] Merge data frames but prefer values in one

2009-09-10 Thread jo
Thanks for the post-processing ideas. But is there any way to do that
in one step?

On Thu, Sep 10, 2009 at 7:20 PM, Henrique Dallazuanna  wrote:
>
> Try this:
>
> xy <- merge(x, y, by = c("a","b"),all = TRUE)
> xy$c <- ifelse(rowSums(!is.na(.x <- xy[, c('c.x', 'c.y')])) > 1, .x[,1], 
> rowSums(.x, na.rm = TRUE))
> xy
>
> On Thu, Sep 10, 2009 at 12:21 PM, JiHO  wrote:

JiHO
---
http://maururu.net

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] problem formula (newbe)

2009-09-10 Thread Robert U




Dear R-users,

 

I am trying to run a function of the package “adabag” (e.g. boosting.cv)
in order to determine a proper number of cluster that I would specify later on
my KMeans clustering. 

(I had this idea from: http://www.statsoft.com/TEXTBOOK/stcluan.html)


 

However, I do have a problem with the “formula” parameter of
e.g. boosting.cv : I am not familiar with these formulas and my research in the
R user guide did not really helped me: 

 

I have 2 columns in my dataset corresponding to 2 “response”
variables (x = coordinates along PCA axis 1 and y = coordinates along PCA axis
2 of my raw dataset) and that’s on these variables that I would like to run 
the
boosting.cv, therefore I tried to define a formula with 2 response variables
and no terms but it’s not really explained this way in the R-guide and I’m 
not
even sure it’s possible. 

 

I also tried by making my KMeans clustering before, applying
the cluster number to each row and using this number (recoded  as.character) 
as a term, but it does not work
either.

 

A quick overview of code / error message if needed : 

 

> form <- as.formula (COORDI_PCA1n2$Dim.1 +
COORDI_PCA1n2$Dim.2 ~KMeans)

> boosting.cv(form, COORDI_PCA1n2)

Error in `[.data.frame`(data, , as.character(formula[[2]]))
: 

  undefined columns
selected

> boosting.cv(form, COORDI_PCA1n2[, 1:2])

Error in `[.data.frame`(data, , as.character(formula[[2]]))
: 

  undefined columns
selected  

 

If anyone has the time to indicate me where I’m being wrong…

 

With regards




  
[[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] Accumulating results from "for" loop in a list/array

2009-09-10 Thread Steven Kang
Dear R users,


I would like to accumulate objects generated from 'for' loop to a list or
array.

To illustrate the problem, arbitrary data set and script is shown below,


x <- data.frame(a = c(rep("n",3),rep("y",2),rep("n",3),rep("y",2)), b =
c(rep("y",2),rep("n",4),rep("y",3),"n"), c = c(rep("n",7),rep("y",3)), d =
c("y", rep("n",4), rep("y",2), rep("n",3)))

for (i in 1:(dim(x)[2]))  {
 assign(paste("ind", i, sep = ""), which(x[ , i] == "y"))
  accum <- c(ind1, ind2, ind3, ind4)
}

> ind1
[1]  4  5  9 10
> ind2
[1] 1 2 7 8 9
> ind3
[1]  8  9 10
> ind4
[1] 1 6 7
> accum
 [1]  4  5  9 10  1  2  7  8  9  8  9 10  1  6  7

Are there any alternative method where the highlighted statement above can
be represented without typing individual objects manually? (as it can be
very tedious with large number of objects; i.e ind1, ind2, ., ind100)

Also, is there any way to extract individual objects ('ind1' etc) from
'accum'?

> accum[1:length(ind1)]
[1]  4  5  9 10
gives 'ind1', but this may become messy for other objects (like 'ind10')


Highly appreciate for sharing your expertise in solving this problem.

[[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] Best R text editors?

2009-09-10 Thread Johannes Huesing
Martin Maechler  [Wed, Sep 02, 2009 at 09:17:42AM 
CEST]:
> > "PaCo" == p connolly 
> > on Wed, 02 Sep 2009 12:19:31 +1200 writes:
> 
> PaCo> On Mon, 31-Aug-2009 at 08:25PM +1000, Jim Lemon wrote:
> PaCo> [...]
[...]
> PaCo> |> Emacs still
> PaCo> |> has that annoying trait of being determinedly incompatible with 
> anything
> PaCo> |> else, even if the conventions are quite sensible. 

A lot of the keystrokes are the same as when you are using the bash.

[...]
> 
> well, actually, since Emacs 23, in its 'Options' Menu there's
> now a check-box entry 
> 
> " C-x/C-c/C-v Cut and Paste (CUA) "
> 
> ((which still is "off" by default ;-))

and in previous versions, you could always do M-x cua-mode for
the same effect. Talk about a well-hidden function mostly directed
at beginners ...


-- 
Johannes Hüsing   There is something fascinating about science. 
  One gets such wholesale returns of conjecture 
mailto:johan...@huesing.name  from such a trifling investment of fact.  
  
http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] eps file with embedded font

2009-09-10 Thread Paul Murrell

Hi

My suggested code had dropped the ...

 format="epswrite"

... and if you put that back, then the /setpagesize command is removed.

Does that improve things in your test cases?

Paul


Ted Harding wrote:

Thanks, Paul.
In fact I had been hoping to lure you to the surface, from the
12740-km ocean depths which you inhabit, during our hours of
darkness!

Your suggested modification of the "options" in the embedFonts
command indeed produces an EPS file which displays without clipping.

However, when these files are imported into a PS document using
'groff', the "blanking" problem described at the end of my included
orifginal posting (below) persisted.

So I posted a summary of the problem to the 'groff' mailing-list.
This can be found in the thread
  [Groff] EPS importing problem, Ted Harding, 2009/09/09
at
  http://lists.gnu.org/archive/html/groff/2009-09/threads.html

There is a reply by Tadziu Hoffmann:

  > Attached are two EPS files:
  >
  >   test1.eps
  >   test1-EMB2.eps
  >
  [snip]

  File "test1-EMB2.eps"[*] contains a call to "setpagedevice"
  (through "setpagesize"), which is a bin no-no for EPS files.
  Does the problem still occur If you delete the line that says
  "720 360 /letter setpagesize"?

[*] which was generated by your modified "embedFonts()"

and, as my reply confirms, commenting-out that line resolved the
problem (though there a minor issue that the BoundingBox is not
what is really wanted, but that can be resolved by editing the
EPS file). I'm not sure where the insertion of the call to
"setpagedevice" arose from, but I think it is down to 'gs'.

There was a much longer private reply from a Robert Herrmann,
which I shall send you privately since it may be of interest,
along with the PS filoe I got after implementing Tadziu Hoffmann.

Meanwhile, those who are interested by the issues arising in this
thread, raised by Simone Gabbriellini, may find the above useful.

Ted.

On 08-Sep-09 23:51:27, Paul Murrell wrote:

Hi
Thanks for the further analysis on this Ted.  I think the problem is
that, with such a "wide" plot, you are running into the default paper
size.  If you look at the EPS produced by ghostscript, you will see a
line like this ...

612 792 /letter setpagesize

... and notice that the value 612 corresponds to the unexpected right
hand clipping margin.  So a possible solution is to specify a paper
size
or, more generally, a device size, that is larger (especially wider)
than the original plot.  Here's an example for this particular case ...

embedFonts(file="test1.eps",
outfile="test1-EMB.eps",
options="-dDEVICEWIDTHPOINTS=720 -dDEVICEHEIGHTPOINTS=360")

Now, rather than clipping the output to the default paper size, the
result is clipped to the edges of the plot.

Hope that helps.

Paul

p.s.  Another useful tip that helps in these situations is to get
ghostscript to just calculate a bounding box for your plot.  For
example ...

 > gs -dNOPAUSE -dBATCH -q -sDEVICE=bbox test1.eps
%%BoundingBox: 4 18 691 336
%%HiResBoundingBox: 4.968000 18.71 690.134885 335.214341

... which shows that ghostscript can produce the right bounding box, if
it ignores the default paper size for output.


Ted Harding wrote:

I am going back to Simone's original query (though this will
split the thread) because subsequent replies did not include
his original. Some comments interspersed below; the main
response at the end.

I have had some private correspondence with Simone, who sent me
two of his files that exhibit the problem, and this has enabled
me to form an idea of where the trouble may lie. It would seem
that either there is something seriously wrong with the function
embedFonts(), or with ghostscript when executing the command
generated by embedFonts(), or with both. I shal descibe the results
of my esperminets, in the hope that some expert in embedFonts(),
or in ghostscript, or in both, can make a useful suggestion.

On 04-Sep-09 14:01:44, Simone Gabbriellini wrote:

Dear list,
I am trying to make eps file with embedded font.
I use:

postscript("ranking-exp-all.eps", horizontal=TRUE, onefile=FALSE,
   paper="special", height=8, width=12, family="Helvetica")
# plot stuff
dev.off()

since R does not embed font, I then use:

embedFonts(file="indegdistr.eps", outfile="indegdistrEMB.eps",
   fontpaths="System/Library/Fonts")

I think Simone intended to use a different filename here, probably

  embedFonts(file="ranking-exp-all.eps",
 outfile="ranking-exp-all-EMB.eps",
 fontpaths="System/Library/Fonts")

in line with his previous command above. This is not important here.


the problem is that the second file, with font embedded, is cutted
near the end, and the very last part of the plots and the border are
off the page...

In fact the bottom of the graphic is slightly clipped when viewed
in ghostview, and the righthand side is severely clipped.


I use R 2.8.1 on a Mac OSX
any help more than welcome,
regards,
Simone

Ths probl

[R] fitting stated preference econometric data using multinomial logit in R

2009-09-10 Thread Richard Anderson

Hello,

Does anyone know anything about using R to fit stated preference 
econometric data using multinomial logit?  I am not sure that standard 
VGLM/VGAM can handle this, or if it does, how.  This data is different 
than more typical revealed preference data in that it is recorded as in 
the following excerpt, for a 3 attribute problem with 3 levels in which 
the respondent chooses (CHOICE) 1 of 4 alternatives:


ID CHOICE DEAD10 DEAD5 LIVE153 LIVE459  TAX
15  0  0 0   0   1   60
15  0  0 0   0   0  400
15  1  0 1   0   0 1600
15  0  1 0   0   1   60
29  0  0 0   1   0 1600
29  0  0 0   1   0   80
29  0  0 0   1   0  120
29  1  1 0   0   1   80
etc.

thanks in advance...

richard anderson

--


Richard M. Anderson, Assistant Professor
Duke University, Nicholas School of the Environment
A321 LSRC
Box 90328
Durham, NC 27708
919.613.8130 (v), 919.684.8741 (f)
richard.ander...@duke.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] "Read.csv" in R with dynamic file (1st) argument

2009-09-10 Thread Don MacQueen
Alternatives to sprintf() include formatC() or 
prettyNum(), which would have to be used in 
combination with paste().


In Carl's solution, the file.path() function 
should be considered, since it automatically uses 
the correct path separators for the OS. 
Furthermore,  eval() is not necessary.


So, for example,


 x <- formatC(scan(),width=4,flag='0')

1: 23
2:
Read 1 item

 x

[1] "0023"

root.dir <- 'D:\R\Data'

read.csv( 
file.path(root.dir,x,paste(x,'.csv',sep='')))  ## 
those are all single quotes


This isn't necessarily better than the sprintf() 
version, just different, and shows some 
additional useful functions(). This way of using 
formatC() requires that the user input only 
numbers:



 x <- formatC(scan(),width=4,flag='0')

1: jk
1:
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  scan() expected 'a real', got 'jk'

I don't know what sprintf() would do with such input.

-Don

At 7:01 PM -0400 9/10/09, Carl Witthoft wrote:

That will not work (or at least doesn't work for me.

This does work:

fnam<-'thefilename.csv'  #or build the name however you like
fpath <- 'macintoshhd/users/me/myfolder/  # or whatever you need

read.csv(eval(paste(fpath,fnam,sep=""))  #worked for me


Carl



---

Try this:

read.csv(sprintf("D://R//Data//%04d//%04d.csv", x, x), header = TRUE)

On Wed, Sep 9, 2009 at 9:32 PM, Steven Kang wrote:


 Dear R users,


 I have numerous data sets (csv files) saved in the folder which has the
 same
 name as individual data.
 (i.e data x1 saved in x1 folder, data x2 in x2 folder etc)

 I would like to read in the desired data set name using 'scan' function and
 assign this inputted value to an object so that it can be used in the
 'read.csv' function.

 For example,

 x <- scan()
 1: 0708
 2:
 Read 1 item

 dat <- read.csv("D://R//Data//x//x.csv", head=TRUE, sep = ",")
 Error in file(file, "r") : cannot open the connection
 In addition: Warning message:
 In file(file, "r") :
  cannot open file ('D://R//Data//x//x.csv': No such file or directory




--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

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



--
-
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
m...@llnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Exporting the formula for a LOESS fit

2009-09-10 Thread Peter Alspach
Tena koe

Loess uses local fitting: "Fitting is done locally.  That is, for the
fit at point x, the fit is made using points in a neighbourhood of x,
weighted by their distance from x" (from the help).  That is, there is
no single formula to describe the fit.

HTH 

Peter Alspach

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of jrflanders
> Sent: Friday, 11 September 2009 10:11 a.m.
> To: r-help@r-project.org
> Subject: [R] Exporting the formula for a LOESS fit
> 
> 
> I'm at my wit's end, and have searched all of my sources. I 
> need to generate a relatively large number of individual 
> LOESS fits each month of data (I have about 16 months of 
> data). Fitting the polynomial is not my problem, figuring out 
> what the formula that describes that polynomial is. apologies 
> in advance if this is so simple, but I need a hand here. Thanks. 
> --
> View this message in context: 
> http://www.nabble.com/Exporting-the-formula-for-a-LOESS-fit-tp
> 25391878p25391878.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.


[R] Bootstrap simulation

2009-09-10 Thread MarcioRibeiro

Hi listers,
I would like a suggestion. I am working on a bootstrap simulation which I am
calculation the confidence intervals to obtain the coverage probability. I
am applying 3 kind of confidence intervals and 3 coverage probabilities (2
sided, left 5% and left 95%).
I programmed a function for that, but my function is getting to long,
because I am calculating many statistics (mean, median, quantile...). So,
for each statistic I have 9 comands to obtain my results, so for 3
statistics I will get 27 comands... I am searching for a optimal way to
reduce the quantity of formulas... Is that clear... Any suggestions...
BThanks in advance,
Marcio

-- 
View this message in context: 
http://www.nabble.com/Bootstrap-simulation-tp25390390p25390390.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] Exporting the formula for a LOESS fit

2009-09-10 Thread jrflanders

I'm at my wit's end, and have searched all of my sources. I need to generate
a relatively large number of individual LOESS fits each month of data (I
have about 16 months of data). Fitting the polynomial is not my problem,
figuring out what the formula that describes that polynomial is. apologies
in advance if this is so simple, but I need a hand here. Thanks. 
-- 
View this message in context: 
http://www.nabble.com/Exporting-the-formula-for-a-LOESS-fit-tp25391878p25391878.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] memory limit problem

2009-09-10 Thread Steve Lianoglou
Hi,

On Thu, Sep 10, 2009 at 8:24 PM, oleg portnoy wrote:
> Hi,
> I have Win XP 32, 4 gig DDR2 and R 2.9.2.
> I have memory limit problems.
>> memory.limit(4090)
> [1] 4090
>
>> memory.limit()
> [1] 4090
>> a<-trans.matrix.f(7)  # made big matrix of integer 16384*16384
> Error: cannot allocate vector of size 512.0 Mb
> I not have other objects in R memory.
> what I do?

Get  a 64 bit system and ditch windows?
http://thread.gmane.org/gmane.comp.lang.r.general/64637

Or maybe the bigmemory package can help?
http://cran.r-project.org/web/packages/bigmemory/

-steve
-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] memory limit problem

2009-09-10 Thread oleg portnoy
Hi,
I have Win XP 32, 4 gig DDR2 and R 2.9.2.
I have memory limit problems.
> memory.limit(4090)
[1] 4090

> memory.limit()
[1] 4090
> a<-trans.matrix.f(7)  # made big matrix of integer 16384*16384
Error: cannot allocate vector of size 512.0 Mb
I not have other objects in R memory.
what I do?
trans.matrix.f <- function(x){
 tr.mat <- matrix(c(0,1,1,0),2)
 for(i in 2:(2*x))
  tr.mat <- rbind(cbind(tr.mat ,tr.mat+1),
  cbind(tr.mat+1,tr.mat ))
 return(tr.mat)
}

Thanks!
Oleg.

[[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] Complex binning?

2009-09-10 Thread Mark Knecht
Thanks Bert,
   I've used reshape a bit but hadn't considered it for this need.
plyr is new to me so I'll check it out.

   I think the hard part in my case is designing the bins. I have some
continuous signals for which I don't know how many bins I want to
break each into. I'd like to be able to sort of on the fly chose 4, 5,
6 or 7 different values and get bins between each consecutive value,
and also above and below. I'll look at the plyr docs to see if it can
do that.

Thanks again,
Mark

On Thu, Sep 10, 2009 at 4:22 PM, Bert Gunter  wrote:
> packages:
>
> plyr
> reshape  (the package, not the base R function)
>
> There may well be others...
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of Mark Knecht
> Sent: Thursday, September 10, 2009 3:55 PM
> To: r-help
> Subject: [R] Complex binning?
>
> Hi,
>   I need to do some binning which to date I've done just writing
> subset commands. I'm now wondering if there are any good packages that
> have some good pre-designed functions for multi-variable binning using
> say 4 or 5 variables, sometimes binning on 3 or more levels of each
> variable, and then supporting some sort of reporting mechanism to tell
> me how many data points fell into each bin?
>
>   I'm getting sort of tired of writing and debugging long logic equations!
> :-)
>
> Thanks,
> Mark
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] "Read.csv" in R with dynamic file (1st) argument

2009-09-10 Thread Steven Kang
Oh strange, as it worked for me..

Thanks for providing alternative method in solving the problem!

On Fri, Sep 11, 2009 at 9:01 AM, Carl Witthoft  wrote:

> That will not work (or at least doesn't work for me.
>
> This does work:
>
> fnam<-'thefilename.csv'  #or build the name however you like
> fpath <- 'macintoshhd/users/me/myfolder/  # or whatever you need
>
> read.csv(eval(paste(fpath,fnam,sep=""))  #worked for me
>
>
> Carl
>
>
>
> ---
>
> Try this:
>
> read.csv(sprintf("D://R//Data//%04d//%04d.csv", x, x), header = TRUE)
>
> On Wed, Sep 9, 2009 at 9:32 PM, Steven Kang  >wrote:
>
> > Dear R users,
> >
> >
> > I have numerous data sets (csv files) saved in the folder which has the
> > same
> > name as individual data.
> > (i.e data x1 saved in x1 folder, data x2 in x2 folder etc)
> >
> > I would like to read in the desired data set name using 'scan' function
> and
> > assign this inputted value to an object so that it can be used in the
> > 'read.csv' function.
> >
> > For example,
> >
> > x <- scan()
> > 1: 0708
> > 2:
> > Read 1 item
> >
> > dat <- read.csv("D://R//Data//x//x.csv", head=TRUE, sep = ",")
> > Error in file(file, "r") : cannot open the connection
> > In addition: Warning message:
> > In file(file, "r") :
> >  cannot open file ('D://R//Data//x//x.csv': No such file or directory
> >
>
>
>  --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] R 2.9.2 memory max - object vector size

2009-09-10 Thread William Dunlap

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of S. Few
> Sent: Thursday, September 10, 2009 1:46 PM
> To: r-help@r-project.org
> Subject: [R] R 2.9.2 memory max - object vector size
> 
> Me:
> 
> Win XP
> 4 gig ram
> R 2.9.2
> 
> library(foreign) # to read/write SPSS files
> library(doBy) # for summaryBy
> library(RODBC)
> setwd("C:\\Documents and Settings\\00909BR")
> gc()
> memory.limit(size=4000)
> 
> ##  PROBLEM:
> 
> I have memory limit problems. R and otherwise. My dataframes for
> merging or subsetting are about 300k to 900k records.
> I've had errors such as vector size too large. gc() was done.reset
> workspace, etc.
> 
> This fails:
> 
> y$pickseq<-with(y,ave(as.numeric(as.Date(timestamp)),id,FUN=seq))

If any values in id are singletons then the call to
seq(timestamp[id=="singleton"])
returns a vector whose length is timestamp[id=="singleton"] (not the
length
of that, the value of that).  as.numeric(as.Date("2009-09-10")) is 14497
so you
might have a lot of 14497-long vectors being created (and thrown away,
unused
except for their initial value).  Using seq_along instead of seq would
take
care of that potential problem.  E.g.,
   > d1<-data.frame(x=c(2,3,5e9,4,5),id=c("A","B","B","B","A"))
   > d2<-data.frame(x=c(2,3,5e9,4,5),id=c("A","B","C","B","A"))
   > # d1$id has no singletons, d2$id does where d2$x is huge
   > with(d1, ave(x,id,FUN=seq))
   [1] 1 1 2 3 2
   > with(d2, ave(x,id,FUN=seq))
   Error in 1L:from : result would be too long a vector
   > with(d2, ave(x,id,FUN=seq_along))
   [1] 1 1 1 2 2
   
If your intent is to create a vector of within-group sequence numbers
then there are more efficient ways to do it.  E.g., with the following
functions
   withinGroupSeq <- function(x){
  x <- as.factor(x)
  retval <- integer(length(x))
  retval[order(as.integer(x))] <- Sequence(table(x))
  retval
   }
   # Sequence is like base::sequence but should use less memory
   # by avoiding the list that sequence's lapply call makes.
   Sequence <- function(nvec) {
  seq_len(sum(nvec)) - rep(cumsum(c(0L,nvec[-length(nvec)])), nvec)
   }
you can get the same result as ave(FUN=seq_along) in less time and,
I suspect, less memory
   > withinGroupSeq(d1$id)
   [1] 1 1 2 3 2
   > withinGroupSeq(d2$id)
   [1] 1 1 1 2 2

Base R may have a function for that already.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 


> 
> Any clues?
> 
> Is this 2.9.2?
> 
> Skipping forward, should I download version R 2.8 or less?
> 
> Thanks!
> Steve
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Complex binning?

2009-09-10 Thread Bert Gunter
packages:

plyr
reshape  (the package, not the base R function)

There may well be others...

Bert Gunter
Genentech Nonclinical Biostatistics

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Mark Knecht
Sent: Thursday, September 10, 2009 3:55 PM
To: r-help
Subject: [R] Complex binning?

Hi,
   I need to do some binning which to date I've done just writing
subset commands. I'm now wondering if there are any good packages that
have some good pre-designed functions for multi-variable binning using
say 4 or 5 variables, sometimes binning on 3 or more levels of each
variable, and then supporting some sort of reporting mechanism to tell
me how many data points fell into each bin?

   I'm getting sort of tired of writing and debugging long logic equations!
:-)

Thanks,
Mark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] sppolot: fill below minimum legend value

2009-09-10 Thread emorway

In the plot below, there are some grid cells that have values below 10, which
is the lowest "cut" value I have specified.  Is there a way, without
adjusting the number of cuts, to tell R to fill in those cells with the
lowest possible color (in this case greeen)?  There is a white "hole" in the
image about a quarter of the way in from the left side, this is what I would
like to correct.  Thanks...Eric

The code:
pts<-list("sp.points",K.dat,pch=3,col="black")
cuts<-c(10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800,900,1000)
spplot(lzm.krige.dir["var1.pred"],at=cuts,colorkey=list(at=log10(cuts),at=log10(cuts),labels=as.character(cuts)),scales=list(draw=TRUE),
xlab="Easting",ylab="Northing",key.space="right",cex=1.1,col.regions=terrain.colors(30),main="Hydraulic
Conductivity of Layer 2",sp.layout=list(pts))

The image:
http://www.nabble.com/file/p25392472/Image3.jpeg 
-- 
View this message in context: 
http://www.nabble.com/sppolot%3A-fill-below-minimum-legend-value-tp25392472p25392472.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] "Read.csv" in R with dynamic file (1st) argument

2009-09-10 Thread Carl Witthoft

That will not work (or at least doesn't work for me.

This does work:

fnam<-'thefilename.csv'  #or build the name however you like
fpath <- 'macintoshhd/users/me/myfolder/  # or whatever you need

read.csv(eval(paste(fpath,fnam,sep=""))  #worked for me


Carl



---

Try this:

read.csv(sprintf("D://R//Data//%04d//%04d.csv", x, x), header = TRUE)

On Wed, Sep 9, 2009 at 9:32 PM, Steven Kang wrote:

> Dear R users,
>
>
> I have numerous data sets (csv files) saved in the folder which has the
> same
> name as individual data.
> (i.e data x1 saved in x1 folder, data x2 in x2 folder etc)
>
> I would like to read in the desired data set name using 'scan' 
function and

> assign this inputted value to an object so that it can be used in the
> 'read.csv' function.
>
> For example,
>
> x <- scan()
> 1: 0708
> 2:
> Read 1 item
>
> dat <- read.csv("D://R//Data//x//x.csv", head=TRUE, sep = ",")
> Error in file(file, "r") : cannot open the connection
> In addition: Warning message:
> In file(file, "r") :
>  cannot open file ('D://R//Data//x//x.csv': No such file or directory
>


--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Complex binning?

2009-09-10 Thread Mark Knecht
Hi,
   I need to do some binning which to date I've done just writing
subset commands. I'm now wondering if there are any good packages that
have some good pre-designed functions for multi-variable binning using
say 4 or 5 variables, sometimes binning on 3 or more levels of each
variable, and then supporting some sort of reporting mechanism to tell
me how many data points fell into each bin?

   I'm getting sort of tired of writing and debugging long logic equations! :-)

Thanks,
Mark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] numerical integration

2009-09-10 Thread Bert Gunter
My goodness! Did you try ?integrate   ?

Bert Gunter
Genentech Nonclinical Biostatistics

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Roslina Zakaria
Sent: Thursday, September 10, 2009 3:36 PM
To: r-help@r-project.org
Subject: [R] numerical integration

Hi r-users,
 
Can I do a numerical integration in R to solve for F(z)- integral_0^z {f(t)
dt} = 0 where F(z) is the CDF and f(t) is the pdf?  What package can I use?
 
Thank you so much for any help given.




  
[[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] numerical integration

2009-09-10 Thread Roslina Zakaria
Hi r-users,
 
Can I do a numerical integration in R to solve for F(z)- integral_0^z {f(t) dt} 
= 0 where F(z) is the CDF and f(t) is the pdf?  What package can I use?
 
Thank you so much for any help given.




  
[[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] Linux R version: best?

2009-09-10 Thread Marc Schwartz

On Sep 10, 2009, at 4:33 PM, Steve Lianoglou wrote:


Hi,

On Sep 10, 2009, at 4:47 PM, S. Few wrote:


For my Redhat 5.2 Linux box, which version of R would be most stable?

I am doing forecasting, statistics, etc.


I believe the conventional wisdom is to always download the latest  
version ... and also, typically, update your current version to the  
latest version when it's released.


I would just add that the current version available in a binary RPM  
for RHEL 5.x on CRAN is 2.9.2 and the current binary RPM available via  
the EPEL (https://fedoraproject.org/wiki/EPEL) is 2.9.1. I would  
expect to see 2.9.2 on the EPEL soon.


Unlike server operating systems such as RHEL, which have a long multi- 
year support window, most applications do not. R's life cycle is such  
that support (bug fixes, patches, etc.) for released versions is  
essentially limited to the current release. So there are strong  
motivations, as Steve noted, to stay up to date as new R versions are  
released.


HTH,

Marc Schwartz

P.S. to Steve L, I just noted your e-mail address...LOL

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Linux R version: best?

2009-09-10 Thread Steve Lianoglou

Hi,

On Sep 10, 2009, at 4:47 PM, S. Few wrote:


For my Redhat 5.2 Linux box, which version of R would be most stable?

I am doing forecasting, statistics, etc.


I believe the conventional wisdom is to always download the latest  
version ... and also, typically, update your current version to the  
latest version when it's released.


-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Linux R version: best?

2009-09-10 Thread S. Few
For my Redhat 5.2 Linux box, which version of R would be most stable?

I am doing forecasting, statistics, etc.


Thanks!

Steve

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 2.9.2 memory max - object vector size

2009-09-10 Thread S. Few
Me:

Win XP
4 gig ram
R 2.9.2

library(foreign) # to read/write SPSS files
library(doBy) # for summaryBy
library(RODBC)
setwd("C:\\Documents and Settings\\00909BR")
gc()
memory.limit(size=4000)

##  PROBLEM:

I have memory limit problems. R and otherwise. My dataframes for
merging or subsetting are about 300k to 900k records.
I've had errors such as vector size too large. gc() was done.reset
workspace, etc.

This fails:

y$pickseq<-with(y,ave(as.numeric(as.Date(timestamp)),id,FUN=seq))

Any clues?

Is this 2.9.2?

Skipping forward, should I download version R 2.8 or less?

Thanks!
Steve

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] function to solve equations

2009-09-10 Thread Ravi Varadhan
You don't need an equation solver.  This is basic algebra.

The solution is:

X = (log(prob) - log(1 - prob) + 3.33) / 0.0102


Ravi.

---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml

 





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Yash Gandhi
Sent: Thursday, September 10, 2009 3:35 PM
To: r-help@r-project.org
Subject: [R] function to solve equations

Hi, 

I am trying to solve this equation prob = exp(-3.33 + 0.0102*x)/(1+exp(-3.33
+ 0.0102*x)). I want to write a function where I call the function and enter
the 'prob' value and the output should be the 'x'. Im not sure how to write
this. I have a basic structure but im not sure if its correct. 

calc <- function(prob){
prob <- exp(-3.33+0.0102*x)/(1+exp(-3.33 + 0.0102*x))
solve(prob)
x
}

Thanks

Yash Gandhi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] ggplot2: mixing colour and linetype in geom_lin e

2009-09-10 Thread Matthieu Dubois
Hi Benoit, 

I'm not a specialist of ggplot2, but I will try to help. 
You may obtain more --interesting-- answers on the ggplot2 
mailing list. This said, let's go. 

To solve your problem, I would suggest to 
1. change the form of the data frame (using the reshape library) 
in order to have one variable for Temp, one for the different Xs, 
and one for their y values. 
2. add a new variable for the different molecules.
3. then plot


# change the format of the data frame
library(reshape)
mdat <- melt(THT_N2_ATGMS, id="Temp")

# add the molecule variable 
mdat$mol <- 'other'
mdat$mol[mdat$variable %in% c('X22','X44')] <- 'CO2'
mdat$mol[mdat$variable %in% c('X43','X45')] <- 'AA'

#plot
library(ggplot2)
p <- ggplot(data=mdat, aes(x=Temp, y=value, colour=mol, 
linetype=variable)) + 
geom_line()
p

that's it. HTH

Matthieu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] function to solve equations

2009-09-10 Thread Yash Gandhi
Hi, 

I am trying to solve this equation prob = exp(-3.33 + 0.0102*x)/(1+exp(-3.33 + 
0.0102*x)). I want to write a function where I call the function and enter the 
'prob' value and the output should be the 'x'. Im not sure how to write this. I 
have a basic structure but im not sure if its correct. 

calc <- function(prob){
prob <- exp(-3.33+0.0102*x)/(1+exp(-3.33 + 0.0102*x))
solve(prob)
x
}

Thanks

Yash Gandhi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Order a vector and move to new vector

2009-09-10 Thread Nandi
Try the following:

Data <- read.table('Sample.txt', header=T)
> Data
 IDUNAV
1  1694  999.89
2  1696  999.90
3  1694  999.87
4  1696  999.88
5  1694  999.84
6  1696  999.86
7  1694  999.82
8  1696  999.84
9  1694  999.79
10 1696  999.82
11 1694  999.71
12 1696  999.75
13 1694  999.69
14 1696  999.73
15 1694  999.66
16 1696  999.71
17 1694  999.64
18 1696  999.69
19 1694  999.61
20 1696  999.67
21 1694  999.54
22 1696  999.70
23 1694  999.51
24 1696 1002.24
25 1694  999.48
26 1696 1012.14
27 1694  999.46
28 1696 1003.38
29 1694  999.43

Then type:
Data_Ordered <- Data[order(Data$ID),]
> Data_Ordered
 IDUNAV
1  1694  999.89
3  1694  999.87
5  1694  999.84
7  1694  999.82
9  1694  999.79
11 1694  999.71
13 1694  999.69
15 1694  999.66
17 1694  999.64
19 1694  999.61
21 1694  999.54
23 1694  999.51
25 1694  999.48
27 1694  999.46
29 1694  999.43
2  1696  999.90
4  1696  999.88
6  1696  999.86
8  1696  999.84
10 1696  999.82
12 1696  999.75
14 1696  999.73
16 1696  999.71
18 1696  999.69
20 1696  999.67
22 1696  999.70
24 1696 1002.24
26 1696 1012.14
28 1696 1003.38

Not sure if this is what you were looking for.

-Nandi



On Sep 10, 4:06 am, Conrad Addo  wrote:
> I currently have a data frame with a Fund ID and NAV value.  Is it possible
> to order the data frame and move to separate columns in a new data frame or
> matrix in R without using a for loop?  I suppose I'd like to use a built in
> function to make it faster because I will have around 60,000 entries to sort
> and my current program takes too long to do this.  I know how to use order,
> but is there a way to separate the result and place into new vectors of a
> matrix or data frame?
>
> Thanks
>
> Conrad
>
> Here are my vectors which I import from a csv file:
>
>  ID UNAV  #1694 999.89  #1696 999.9  #1694 999.87  #1696 999.88  #1694
> 999.84  #1696 999.86  #1694 999.82  #1696 999.84  #1694 999.79  #1696 999.82
> #1694 999.71  #1696 999.75  #1694 999.69  #1696 999.73  #1694 999.66  #1696
> 999.71  #1694 999.64  #1696 999.69  #1694 999.61  #1696 999.67  #1694 999.54
> #1696 999.7  #1694 999.51  #1696 1002.24  #1694 999.48  #1696 1012.14  #1694
> 999.46  #1696 1003.38  #1694 999.43
>
>         [[alternative HTML version deleted]]
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://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] index of min elements in matrix

2009-09-10 Thread annie Zhang
Thanks for all your help. Yes, it's very helpful.

Annie

On Thu, Sep 10, 2009 at 11:42 AM, Marc Schwartz wrote:

>  On Sep 10, 2009, at 1:34 PM, annie Zhang wrote:
>
> Hi, All,
>>
>> How can I get the indices of the minimum elements in a matrix without
>> using
>> a loop?
>>
>> For example, if the matrix is
>>
>> 4 5 2
>> 2 8 9
>> 5 2 3
>>
>> Then I want to output (1,3), (2,1), (3,2).
>>
>> Thanks,
>>
>> Annie
>>
>
>
> mat <- matrix(c(4, 2, 5, 5, 8, 2, 2, 9, 3), 3)
>
> > mat
> [,1] [,2] [,3]
> [1,]452
> [2,]289
> [3,]523
>
>
> > which(mat == min(mat), arr.ind = TRUE)
> row col
> [1,]   2   1
> [2,]   3   2
> [3,]   1   3
>
>
> See ?which and take note of the arr.ind argument.
>
> HTH,
>
> Marc Schwartz
>
>

[[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] index of min elements in matrix

2009-09-10 Thread Marc Schwartz

On Sep 10, 2009, at 1:34 PM, annie Zhang wrote:


Hi, All,

How can I get the indices of the minimum elements in a matrix  
without using

a loop?

For example, if the matrix is

4 5 2
2 8 9
5 2 3

Then I want to output (1,3), (2,1), (3,2).

Thanks,

Annie



mat <- matrix(c(4, 2, 5, 5, 8, 2, 2, 9, 3), 3)

> mat
 [,1] [,2] [,3]
[1,]452
[2,]289
[3,]523


> which(mat == min(mat), arr.ind = TRUE)
 row col
[1,]   2   1
[2,]   3   2
[3,]   1   3


See ?which and take note of the arr.ind argument.

HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] index of min elements in matrix

2009-09-10 Thread Henrique Dallazuanna
Try this:

m <- rbind(c(4,5,2), c(2,8,9), c(5,2,3))
cbind(1:NROW(m), apply(m, 1, which.min))


On Thu, Sep 10, 2009 at 3:34 PM, annie Zhang wrote:

> Hi, All,
>
> How can I get the indices of the minimum elements in a matrix without using
> a loop?
>
> For example, if the matrix is
>
> 4 5 2
> 2 8 9
> 5 2 3
>
> Then I want to output (1,3), (2,1), (3,2).
>
> Thanks,
>
> Annie
>
>[[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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] index of min elements in matrix

2009-09-10 Thread annie Zhang
Hi, All,

How can I get the indices of the minimum elements in a matrix without using
a loop?

For example, if the matrix is

4 5 2
2 8 9
5 2 3

Then I want to output (1,3), (2,1), (3,2).

Thanks,

Annie

[[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] Order of multiple plots

2009-09-10 Thread Nandi
'Layout' is the way to go. You can define a layout as:

LO <- layout(matrix(c(1, 2, 3, 4), ncol=2))

In your case, you would probably want to use:
layout(matrix(c(2, 1), ncol=2))
Then, the first plot will be drawn in space number 2, and then the
second plot will be drawn in space number 1.

Hope this helps.
-Nandi


On Sep 9, 11:49 pm, legen  wrote:
> Hello all,
>
> I have a problem and need your help.
> I am going to draw two plots in one row and two columns by using
> “par(mfrow=c(1,2))”, but I want to first draw the right plot and then draw
> the left plot. Does anybody can show me how to do it please? Thanks in
> advance.
>
> Legen
>
> --
> View this message in 
> context:http://www.nabble.com/Order-of-multiple-plots-tp25377235p25377235.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://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] AIC and goodness of prediction - was: Re: goodness of "prediction" using a model (lm, glm, gam, brt,

2009-09-10 Thread Corrado
Dear Kingsford,

I apologise for breaking the thread, but I thought there were some more people 
who would be interested.

What you propose is what I am using at the moment: the sum of the squares of 
the residuals, plus  variance / stdev. I am not really satisfied. I have also 
tried using R2, and it works well  but some people go a bit wild eyed when 
they see a negative R2 (which is perfectly reasonable when you use R2 as a 
measure of goodness of fit on prediction on a dataset different from the 
training set).

I was then wondering whether it would make sense to use AIC: the K in the 
formula will still be the number of parameters of the trained model, the "sum 
of square residuals" would be the (predicted - observed)^2, N would be the 
number of samples in the test dataset. I think it should work well.

What do you / other R list members think?

Regards

On Thursday 03 September 2009 15:06:14 Kingsford Jones wrote:
> There are many ways to measure prediction quality, and what you choose
> depends on the data and your goals.  A common measure for a
> quantitative response is mean squared error (i.e. 1/n * sum((observed
> - predicted)^2)) which incorporates bias and variance.  Common terms
> for what you are looking for are "test error" and "generalization
> error".
>
>
> hth,
> Kingsford
>
> On Wed, Sep 2, 2009 at 11:56 PM, Corrado wrote:
> > Dear R-friends,
> >
> > How do you test the goodness of prediction of a model, when you predict
> > on a set of data DIFFERENT from the training set?
> >
> > I explain myself: you train your model M (e.g. glm,gam,regression tree,
> > brt) on a set of data A with a response variable Y. You then predict the
> > value of that same response variable Y on a different set of data B (e.g.
> > predict.glm, predict.gam and so on). Dataset A and dataset B are
> > different in the sense that they contain the same variable, for example
> > temperature, measured in different sites, or on a different interval
> > (e.g. B is a subinterval of A for interpolation, or a different interval
> > for extrapolation). If you have the measured values for Y on the new
> > interval, i.e. B, how do you measure how good is the prediction, that is
> > how well model fits the Y on B (that is, how well does it predict)?
> >
> > In other words:
> >
> > Y~T,data=A for training
> > Y~T,data=B for predicting
> >
> > I have devised a couple of method based around 1) standard deviation 2)
> > R^2, but I am unhappy with them.
> >
> > Regards
> > --
> > Corrado Topi
> >
> > Global Climate Change & Biodiversity Indicators
> > Area 18,Department of Biology
> > University of York, York, YO10 5YW, UK
> > Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html and provide commented,
> > minimal, self-contained, reproducible code.



-- 
Corrado Topi

Global Climate Change & Biodiversity Indicators
Area 18,Department of Biology
University of York, York, YO10 5YW, UK
Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Negative AIC

2009-09-10 Thread Corrado
I think the problem is trying to compare different models trained don the same 
dataset.

1) If I compare for example gam (from gam package) with and without intercept, 
is that a valid comparison?

For example: model with intercept has explained dev 24%, with AIC -2217146, 
model without intercept has explained dev 85.5% with AIC 217488.1

The results sound incredibly strange, but there is actually no difference in 
the model but the removal of the intercept  :(. So which model is "better" 
at fitting the data

2) If I compare for example gam from gam package with let's say gam from mgcv 
(using tpsp), then I get two completely analogous AIC, but are they 
comparable?

gam from mgcv package: -2195000
gam from gam package: -2217000

3) I would like to compare those AIC to the AIC obtained by running BRT on the 
same dataset. I was thinking of simply recalculating manually the AIC using 
the formula:

AIC=2K+N*log(rss/N)

where K is the number of parameters of the regression (i.e. the coefficient 
that 
are not zero, I would think) and N is the number of samples.

What do you think? Would that be reasonable?

Regards

On Thursday 10 September 2009 16:39:32 Ben Bolker wrote:
>   If all the models are fitted to the same data set, using the same
> modeling tools (you have to be careful e.g. comparing lmer models to
> glm models, because they use different additive constants), and
> everything seems to make sense (!!!), then yes.  I would be a little
> surprised, and think that something was wrong, if you have some AIC
> values that are on the order of -20,000 (as below) and others that are
> +20,000 ...
>
>   Ben Bolker
>
> Corrado wrote:
> > My worry is: can I compare negative AIC with positive AIC? does the
> > comparison still hold?
> >
> > On Thursday 10 September 2009 15:57:01 Ben Bolker wrote:
> >> Corrado-5 wrote:
> >>> Dear R list,
> >>>
> >>> I just obtained a negative AIC for two models (-221.7E+4
> >>>  and -230.2E+4). Is that normal?
> >>
> >> It's not necessarily wrong.  See 



-- 
Corrado Topi

Global Climate Change & Biodiversity Indicators
Area 18,Department of Biology
University of York, York, YO10 5YW, UK
Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Merge data frames but prefer values in one

2009-09-10 Thread Henrique Dallazuanna
Try this:

xy <- merge(x, y, by = c("a","b"),all = TRUE)
xy$c <- ifelse(rowSums(!is.na(.x <- xy[, c('c.x', 'c.y')])) > 1, .x[,1],
rowSums(.x, na.rm = TRUE))
xy

On Thu, Sep 10, 2009 at 12:21 PM, JiHO  wrote:

> Hello everyone,
>
> My problem is better explained with an example:
>
> > x=data.frame(a=1:4,b=1:4,c=rnorm(4))
> > x
>  a b  c
> 1 1 1 -0.8821089
> 2 2 2 -0.7082583
> 3 3 3 -0.5948835
> 4 4 4 -1.8571443
> > y=data.frame(a=c(1,3),b=3,c=rnorm(2))
> > y
>  a bc
> 1 1 3 -0.273155973
> 2 3 3  0.009517862
>
> Now I want to merge x and y by columns a and b, hence creating a data.frame
> with all a:b combinations observed in x and y. That's easily done with
> merge:
>
> > merge(x,y,by=c("a","b"),all=T)
>  a bc.x  c.y
> 1 1 1 -0.8821089   NA
> 2 1 3 NA -0.273155973
> 3 2 2 -0.7082583   NA
> 4 3 3 -0.5948835  0.009517862
> 5 4 4 -1.8571443   NA
>
> But rather than two c columns I would want the merge to:
> - keep the value in x if there is no corresponding value in y
> - keep the value in y if there is no corresponding value in x
> - prefer the value in y when the a:b combination exists in both x and y
>
> So basically I want my result to look like:
>  a b  c
> 1 1 1 -0.8821089
> 2 1 3 -0.2731559
> 3 2 2 -0.7082583
> 4 3 3  0.0095178
> 5 4 4 -1.8571443
>
> I can't find a combinations of options for merge that does this. Is there
> another fonction that would do that or do I have to resort to some
> post-processing after merge? It seems that it might be something like a
> "right merge" for data bases but I don't know this world at all. I would be
> happy to look into sqldf if that allows to do things like that.
>
> Thanks in advance. Sincerely,
>
> JiHO
> ---
> http://maururu.net
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] tranform a table?

2009-09-10 Thread David Hajage
I think you could use reshape and ascii package here.

Create a file ("code.Rnw") with this code :

John and Jane
=

<<>>=
df <- data.frame(names = c("John", "Jane"), field1 = c("value1", "value2"),
field2 = c("value3", "value4"))
library(reshape)
cdf <- cast(melt(df, id = "names"), variable ~ . | names)
@

<>=
library(ascii)
ascii(cdf$Jane)
ascii(cdf$John)
@

Then from R, run :
Sweave("code.Rnw", RweaveAsciidoc)

Finally, use asciidoc  to convert the
new file "code.txt" into html :
asciidoc code.txt

David


On Thu, Sep 10, 2009 at 15:10, bbimber  wrote:

>
> hello everyone,
>
> i'm new to R, so i hope you dont mind a fairly basic R question.  we're
> using R to manipulate the results of SQL queries and create an HTML output.
> I'm starting with a table that looks essentially like this:
>
> NameField1 Field2
> John  value1 value2
> Jane  value3 value4
>
> My table is stored as a dataframe.  I'd like to efficiently produce an
> output that iterates through each row, transposes it and outputs an HTML
> table (one per row).  like this:
>
> Name: John
> Field1: value1
> Field2: value2
>
> Name: Jane
> Field1: value3
> Field2: value4
>
> I can accomplish this by looping through each row, then outputting that
> row's table.  This gets the job done, but it seems there must be a better
> way.  I'm going to need to do this sort of conversion a lot,
> so the simpler the better.  is there a better way to approach it than the
> code below?  is there a more general term for the sort of transformation
> i'm
> trying to make that might help guide my searching?
>
> i realize i need to look into better methods of outputting HTML tables
> (like
> r2html).
>
> here's the basic idea.  'labkey.data' is the data frame produced by my SQL
> query:
>
> D<-labkey.data
> H<-colnames(D)
> T<-t(D)
> L<-length(D$id)
>
> output <- ""
>
> for(i in 1:L) {
> R<-my.row <- D[i, ]
> R<-t(R)
> Len<-length(R)
>
> output <- paste(output, "")
> for(j in 1:Len) {
> output <- paste(output,"", H[j],":", R[j], "")
> }
>
> output <- paste(output, "")
>
> }
>
> write(output, file="${htmlout:output}")
>
> Thanks for any help.
> --
> View this message in context:
> http://www.nabble.com/tranform-a-table--tp25382806p25382806.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] Negative AIC

2009-09-10 Thread John C Frain
Enders (2004), Applied Econometric time series, Wiley,  Exercise 10,
page 102, sets out some of the variations of the AIC and SBC and
contains a good definition.  As these are all monotonic
transformations of one another they lead to the same maximum
(minimum).  I say maximum/minimum because I have seen some persons who
define the information criterion as the negative or other definitions.
  You may even find different definitions used in different functions
in the same software.  The only thing to do is to check the
documentaion to see what definition is being used by each function in
that software.

Best Regards

John Frain

2009/9/10 Corrado :
> My worry is: can I compare negative AIC with positive AIC? does the comparison
> still hold?
>
> On Thursday 10 September 2009 15:57:01 Ben Bolker wrote:
>> Corrado-5 wrote:
>> > Dear R list,
>> >
>> > I just obtained a negative AIC for two models (-221.7E+4
>> >  and -230.2E+4). Is that normal?
>>
>> It's not necessarily wrong.  See 
>
>
>
> --
> Corrado Topi
>
> Global Climate Change & Biodiversity Indicators
> Area 18,Department of Biology
> University of York, York, YO10 5YW, UK
> Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
John C Frain
Economics Department
Trinity College Dublin
Dublin 2
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@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] How to do rotation for polygon?

2009-09-10 Thread William Dunlap
Try representing the pentagon as a set of complex
numbers.  Translate them by adding a complex
number and multiply by exp(1i*angle) to rotate them
around the origin.  E.g. to rotate them around their
center of gravity, mean(p), do

> p<-complex(real=c(4,5,7,8,6), imag=c(5,3,3,5,7))
> plot(p, xlim=c(0,10), ylim=c(0,10), type="n")
> for(k in 0:10)polygon(border=k, lwd=k+1,
(p-mean(p))*exp(k*1i/10*pi)+mean(p))

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Hemavathi Ramulu
> Sent: Thursday, September 10, 2009 1:44 AM
> To: Greg Snow
> Cc: r-help@r-project.org
> Subject: Re: [R] How to do rotation for polygon?
> 
> Hi everyone,
> I still couldn't get the diagram as I mentioned before. I try Grey and
> Milton suggestion but
> it confusing.
> I hope anyone helped me.
> 
> Thanks in advance.
> 
> Regards,
> Hema.
> 
> On Thu, Sep 3, 2009 at 11:39 PM, Greg Snow 
>  wrote:
> 
> > The my.symbols and ms.polygon functions in the 
> TeachingDemos package may
> > help.
> >
> > --
> > Gregory (Greg) L. Snow Ph.D.
> > Statistical Data Center
> > Intermountain Healthcare
> > greg.s...@imail.org
> > 801.408.8111
> >
> >
> > > -Original Message-
> > > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> > > project.org] On Behalf Of Hemavathi Ramulu
> > > Sent: Wednesday, September 02, 2009 11:05 PM
> > > To: r-help@r-project.org
> > > Subject: [R] How to do rotation for polygon?
> > >
> > > Hi everyone,
> > > I have coding for repeating pentagon as below:
> > >
> > > plot(0:11,type="n")
> > > for (i in 1:10 )polygon(rep(c(4,5,7,8,6)), 
> i*c(.5,.3,.3,.5,.7), bor=2)
> > >
> > > which are increasing vertically.
> > >
> > > Now, I want to know how to rotate the pentagon, so that I will get
> > > pattern
> > > like flower.
> > > Basicly, repeating pentagon in circle.
> > >
> > > Thanks alot for helping me to solve this problem.
> > > --
> > > Hemavathi
> > >
> > >   [[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.
> >
> 
> 
> 
> -- 
> Hemavathi Ramulu
> 
>   [[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] Negative AIC

2009-09-10 Thread Murilo Doi

Hi,

yes the AIC can be negative. To choose the model we use the criteria of
lower AIC (-230.2E+4).

Murilo Doi


Corrado-5 wrote:
> 
> Dear R list,
> 
> I just obtained a negative AIC for two models (-221.7E+4
>  and -230.2E+4). Is that normal?
> 
> Regards
> -- 
> Corrado Topi
> 
> Global Climate Change & Biodiversity Indicators
> Area 18,Department of Biology
> University of York, York, YO10 5YW, UK
> Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 


-

Murilo Eiji Doi
http://twitter.com/murilodoi
http://pt.beezzer.com/rproject (help do R-project em português)

-- 
View this message in context: 
http://www.nabble.com/Negative-AIC-tp25383791p25385341.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] Negative AIC

2009-09-10 Thread Ben Bolker
  If all the models are fitted to the same data set, using the same
modeling tools (you have to be careful e.g. comparing lmer models to
glm models, because they use different additive constants), and
everything seems to make sense (!!!), then yes.  I would be a little
surprised, and think that something was wrong, if you have some AIC
values that are on the order of -20,000 (as below) and others that are
+20,000 ...

  Ben Bolker

Corrado wrote:
> My worry is: can I compare negative AIC with positive AIC? does the 
> comparison 
> still hold?
> 
> On Thursday 10 September 2009 15:57:01 Ben Bolker wrote:
>> Corrado-5 wrote:
>>> Dear R list,
>>>
>>> I just obtained a negative AIC for two models (-221.7E+4
>>>  and -230.2E+4). Is that normal?
>> It's not necessarily wrong.  See 
> 
> 
> 


-- 
Ben Bolker
Associate professor, Biology Dep't, Univ. of Florida
bol...@ufl.edu / www.zoology.ufl.edu/bolker
GPG key: www.zoology.ufl.edu/bolker/benbolker-publickey.asc



signature.asc
Description: OpenPGP digital signature
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Insall package

2009-09-10 Thread Cedrick Johnson
Try downloading the rscproxy-.ZIP file on windows. Extension tar.gz 
is used (mostly) on linux


or

install.packages('rscproxy')

-c


wesley mathew wrote:

Dear Sir

Subject: - *Install " rscproxy_1.3-1.tar.gz "*

 I am working in Windows system.  I was try  to install *rscproxy* package
in  two way.
 *1.* install.packages ("rscproxy_1.3-1.tar.gz"),  It shows the Warning:
unable to access index for repository
http://cran.pt.r-project.org/bin/windows/contrib/2.9
 *2. * install.packages("C:/Program Files/R/rscproxy_1.3-1.tar.gz", repos =
NULL) It also show warning ( Error in gzfile(file, "r") : cannot open the
connection In addition: Warning   messages: 1: In unzip(zipname, exdir =
dest) : error 1 in extracting from zip file 2: In gzfile(file, "r") :
cannot open compressed file 'rscproxy_1.3-1.tar.gz/DESCRIPTION', probable
reason 'No such file or directory'  )

 Could you please suggest, how to solve this problem,











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


[R] Merge data frames but prefer values in one

2009-09-10 Thread JiHO

Hello everyone,

My problem is better explained with an example:

> x=data.frame(a=1:4,b=1:4,c=rnorm(4))
> x
 a b  c
1 1 1 -0.8821089
2 2 2 -0.7082583
3 3 3 -0.5948835
4 4 4 -1.8571443
> y=data.frame(a=c(1,3),b=3,c=rnorm(2))
> y
 a bc
1 1 3 -0.273155973
2 3 3  0.009517862

Now I want to merge x and y by columns a and b, hence creating a  
data.frame with all a:b combinations observed in x and y. That's  
easily done with merge:


> merge(x,y,by=c("a","b"),all=T)
 a bc.x  c.y
1 1 1 -0.8821089   NA
2 1 3 NA -0.273155973
3 2 2 -0.7082583   NA
4 3 3 -0.5948835  0.009517862
5 4 4 -1.8571443   NA

But rather than two c columns I would want the merge to:
- keep the value in x if there is no corresponding value in y
- keep the value in y if there is no corresponding value in x
- prefer the value in y when the a:b combination exists in both x and y

So basically I want my result to look like:
 a b  c
1 1 1 -0.8821089
2 1 3 -0.2731559
3 2 2 -0.7082583
4 3 3  0.0095178
5 4 4 -1.8571443

I can't find a combinations of options for merge that does this. Is  
there another fonction that would do that or do I have to resort to  
some post-processing after merge? It seems that it might be something  
like a "right merge" for data bases but I don't know this world at  
all. I would be happy to look into sqldf if that allows to do things  
like that.


Thanks in advance. Sincerely,

JiHO
---
http://maururu.net

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Negative AIC

2009-09-10 Thread Corrado
My worry is: can I compare negative AIC with positive AIC? does the comparison 
still hold?

On Thursday 10 September 2009 15:57:01 Ben Bolker wrote:
> Corrado-5 wrote:
> > Dear R list,
> >
> > I just obtained a negative AIC for two models (-221.7E+4
> >  and -230.2E+4). Is that normal?
>
> It's not necessarily wrong.  See 



-- 
Corrado Topi

Global Climate Change & Biodiversity Indicators
Area 18,Department of Biology
University of York, York, YO10 5YW, UK
Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] tranform a table?

2009-09-10 Thread Don MacQueen
One could probably use one of the apply family of functions (apply, 
lapply, sapply), but having looked into it a bit, I think it's 
simpler to use an explicit loop. I doubt you'll encounter a need for 
greater efficiency, in the cpu time sense, unless your tables are 
huge.


But the looping can be written more simply:


require(xtable)

df <- data.frame(nm=letters[1:4], val1=1:4, val2=round(runif(4)))

for (i in seq(nrow(df))) {
  print( xtable( t(df[i,])) , type='html', include.colnames=FALSE)
  cat('')
}


One of the other packages for writing html from R objects might have 
a function that will automatically subset a dataframe in this 
particular way, but it strikes me as somewhat unlikely.


-Don


At 6:10 AM -0700 9/10/09, bbimber wrote:

hello everyone,

i'm new to R, so i hope you dont mind a fairly basic R question.  we're
using R to manipulate the results of SQL queries and create an HTML output.
I'm starting with a table that looks essentially like this:

NameField1 Field2
John  value1 value2
Jane  value3 value4

My table is stored as a dataframe.  I'd like to efficiently produce an
output that iterates through each row, transposes it and outputs an HTML
table (one per row).  like this:

Name: John
Field1: value1
Field2: value2

Name: Jane
Field1: value3
Field2: value4

I can accomplish this by looping through each row, then outputting that
row's table.  This gets the job done, but it seems there must be a better
way.  I'm going to need to do this sort of conversion a lot,
so the simpler the better.  is there a better way to approach it than the
code below?  is there a more general term for the sort of transformation i'm
trying to make that might help guide my searching?

i realize i need to look into better methods of outputting HTML tables (like
r2html).

here's the basic idea.  'labkey.data' is the data frame produced by my SQL
query:

D<-labkey.data
H<-colnames(D)
T<-t(D)
L<-length(D$id)

output <- ""

for(i in 1:L) {
R<-my.row <- D[i, ]
R<-t(R)
Len<-length(R)

output <- paste(output, "")
for(j in 1:Len) {
output <- paste(output,"", H[j],":", R[j], "")
}

output <- paste(output, "")

}

write(output, file="${htmlout:output}")

Thanks for any help.
--
View this message in context: 
http://*www.*nabble.com/tranform-a-table--tp25382806p25382806.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.



--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Negative AIC

2009-09-10 Thread Ben Bolker



Corrado-5 wrote:
> 
> Dear R list,
> 
> I just obtained a negative AIC for two models (-221.7E+4
>  and -230.2E+4). Is that normal?
> 
> 

It's not necessarily wrong.  See 
-- 
View this message in context: 
http://www.nabble.com/Negative-AIC-tp25383791p25384865.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] Running R in Windows server

2009-09-10 Thread Barry Rowlingson
On Thu, Sep 10, 2009 at 3:07 PM, srpd TCLTK wrote:
>
> Hi,
>
>
>
> I'm trying to set up a server which allows different users to use R 
> simultaneously. Is it possible in Windows?
> I know that a LINUX Server is probably a better option, but I had already 
> created a GUI with Tcl/tk in Windows. So some of the events don't work in 
> LINUX.

  You need Windows Terminal Server 2008 (or 2003) plus the right
client access licenses (CALs) depending on how you expect the machine
to be used. A thousand dollars gets you a single server license plus 5
CALs. Then your 5 users connect to it from their Windows PCs using the
Windows Remote Desktop Connection program. So your users will need
Windows XP (or Vista, or 7) licenses as well, unless they have
linux/mac desktops in which case they can use rdesktop to connect.

  Is it a thousand dollars worth of hassle to make your Tcl/Tk program
OS-independent? Plus the time it takes to learn how to set up and
admin a Windows TS 2008 box...

Barry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Running R in Windows server

2009-09-10 Thread Uwe Ligges



srpd TCLTK wrote:

Hi,

 


I'm trying to set up a server which allows different users to use R 
simultaneously. Is it possible in Windows?


Yes, I guess you want to use some Terminal Server. As for any other 
software, each user can start own instances of R.


Uwe Ligges






I know that a LINUX Server is probably a better option, but I had already 
created a GUI with Tcl/tk in Windows. So some of the events don't work in LINUX.
 
Thanks in advance,
 
Srpd   
 

 


_

m só local.

rk-connector.aspx
[[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] lean text label below barplot table

2009-09-10 Thread Sunil Suchindran
#Example data

df <- data.frame(trt = factor(c("A long label", "Another long \n label")),
outcome = c(1,4))

#Install ggplot2 if needed

library(ggplot2)
p <- ggplot(df, aes(y=outcome, x=trt))
p <- p + geom_bar(position="dodge", stat="identity")
p <- p + opts(axis.text.x = theme_text(angle = 45, hjust=1))
p



On Mon, Sep 7, 2009 at 5:03 PM, Xiaogang Yang  wrote:

> Hi, everyone:
> I am plotting an graph with bar plot, but the label after every bar is too
> long, I wanna if I can draw the label lean to an angle
> thanks
>
> --
> Xiaogang Yang
> Sensorweb Research Laboratory
> http://sensorweb.vancouver.wsu.edu/
> Washington State University Vancouver
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] fit arima long period alternatives

2009-09-10 Thread Matteo Bertini
I'd like to fit a SARIMA model on a timeseries but the period I'd like to
use is too big (7 day in 15min samples = 672) for the algorithm used in R.

Some suggested alternatives?

Thanks,
Matteo Bertini

[[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] executing rscript from VB

2009-09-10 Thread Duncan Murdoch

On 9/10/2009 9:25 AM, H Rao wrote:

Hi,
I am looking to execute an R script from VB as  below.
The script runs fine but the redirection doesnt seem to happen. The
redirection operator and the out file seem to be treated as arguments
to the R script. Is there a way to get the > operator working


That's a VB question.  You should ask Microsoft.

Duncan Murdoch



thanks, R

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "E:/R/bin/Rscript.exe";
proc.StartInfo.Arguments = "E:/R/bin/test.r > test.out";
proc.StartInfo.UseShellExecute = true;
proc.Start();

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Running R in Windows server

2009-09-10 Thread srpd TCLTK

Hi,

 

I'm trying to set up a server which allows different users to use R 
simultaneously. Is it possible in Windows?
I know that a LINUX Server is probably a better option, but I had already 
created a GUI with Tcl/tk in Windows. So some of the events don't work in LINUX.
 
Thanks in advance,
 
Srpd   
 

 

_

m só local.

rk-connector.aspx
[[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] Intercept=0 in gam from gam package

2009-09-10 Thread Gavin Simpson
On Thu, 2009-09-10 at 14:58 +0100, Corrado wrote:
> Dear R list,
> 
> is it possible to force the intercept to assume the value of 0 (that is no 
> intercept) in gam from gam package?

Just like you would in lm or glm for example, by adding -1 to your
formula. ?gam suggests you look at ?lm to see about the formulas for
example.

data(airquality)
mod0 <- gam(Ozone^(1/3) ~ lo(Solar.R) + lo(Wind, Temp) - 1, 
data = airquality, na = na.gam.replace)
mod1 <- gam(Ozone^(1/3) ~ lo(Solar.R) + lo(Wind, Temp), 
data = airquality, na = na.gam.replace)

summary(mod0)
summary(mod1)

HTH

G

> 
> Regards
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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-pkgs] new version of R-package mice

2009-09-10 Thread mgko
Dear R-users,

Version V2.0 of the package mice is now available on CRAN for Windows, Linux 
and Apple users.

Multivariate Imputation by Chained Equations (MICE) is the name of software for 
imputing incomplete multivariate data by Fully Conditional Specifcation (FCS). 
MICE V1.0 appeared in the year 2000 as an S-PLUS library, and in 2001 as an R 
package. MICE V1.0 introduced predictor selection, passive imputation and 
automatic pooling. 

MICE V2.0, which extends the functionality of MICE V1.0 in several ways. In 
MICE V2.0, the analysis of imputed data is made completely general, whereas the 
range of models under which pooling works is substantially extended. MICE V2.0 
adds new functionality for imputing multilevel data, automatic predictor 
selection, data handling, post-processing imputed values, specialized pooling 
and model selection. Imputation of categorical data is improved in order to 
bypass problems caused by perfect prediction.Special attention to 
transformations, sum scores, indices and interactions using passive imputation, 
and to the proper setup of the predictor matrix. 

We have written also a complete new manual for mice, which can be downloaded 
from http://www.stefvanbuuren.nl/publications/MICE%20in%20R%20-%20Draft.pdf 

 

This article/manual provides a hands-on, stepwise approach to using mice for 
solving incomplete data problems in real data.

Best Regards,

Karin Groothuis-Oudshoorn & Stef van Buuren

 

   

C.G.M. (Karin) Groothuis-Oudshoorn, Phd

Assistent Professor University of Twente / Biostatistician Roessingh Research 
and Development

c.g.m.oudsho...@utwente.nl   / 
k.grooth...@rrd.nl  


[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Order of multiple plots

2009-09-10 Thread S Ellison
Rather than use par(mfro...) you should probably take a look at the alternative 
"layout" approach. That allows you to give R a matrix (corresponding to panels 
in the plot) containing the number of the plot to be placed in each panel.
It also allows unequal panel sizes.

See ?layout for details.

Steve E
>>> legen  10/09/2009 05:49:04 >>>

Hello all,

I have a problem and need your help.
I am going to draw two plots in one row and two columns by using
“par(mfrow=c(1,2))”, but I want to first draw the right plot and then draw
the left plot. Does anybody can show me how to do it please? Thanks in
adv

***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Intercept=0 in gam from gam package

2009-09-10 Thread Corrado
Dear R list,

is it possible to force the intercept to assume the value of 0 (that is no 
intercept) in gam from gam package?

Regards
-- 
Corrado Topi

Global Climate Change & Biodiversity Indicators
Area 18,Department of Biology
University of York, York, YO10 5YW, UK
Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Negative AIC

2009-09-10 Thread Corrado
Dear R list,

I just obtained a negative AIC for two models (-221.7E+4
 and -230.2E+4). Is that normal?

Regards
-- 
Corrado Topi

Global Climate Change & Biodiversity Indicators
Area 18,Department of Biology
University of York, York, YO10 5YW, UK
Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Listing all data instead of only k-elements when using combn-function

2009-09-10 Thread Sarah Moens
Hi dear reader,

 

I've been searching the help-archive and found many topics with regard to
the use of combinations, but I can't seem to make sense out of the advice
given. So I posted my question here, my apologies that this has come up for
many times before.

 

 

Example data-set:

Group  Scores

A5

A10

A9

B 2

B 3

 

I have 5 subjects. Those subjects are each assigned to a particular group,
group A or group B. Each subject gets a score on a test (dependant
variable).

 

Now instead of just getting the mean of group A and group B of the sample
I've drawn, I want to list all possible combinations (in this case 10
combinations, to eventually be able to compute for each combination, the
mean of group A and group B.

That is:

Group  [,1]   [,2] .
[,10]

A5 5
9

A10   10
2

A9 2
3

B 2 9
5

B 3 3
10

 

combn does provide me with 10 possible combinations, but it only lists a
part of the data:

[,1] [,2] [,3] [,4] [,5]
[,6] [,7] [,8] [,9] [,10]

[1,] 5 5 5 5 5
5 10   10   10   9

[2,] 10   10   10   9 9
2 9 9 2 2

[3,] 9 2 3 2 3
3 2 3 3 3

 

 

 

Thanks a lot!!

 

Sarah


[[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] tranform a table?

2009-09-10 Thread bbimber

hello everyone,

i'm new to R, so i hope you dont mind a fairly basic R question.  we're
using R to manipulate the results of SQL queries and create an HTML output. 
I'm starting with a table that looks essentially like this:

NameField1 Field2
John  value1 value2
Jane  value3 value4

My table is stored as a dataframe.  I'd like to efficiently produce an
output that iterates through each row, transposes it and outputs an HTML
table (one per row).  like this:

Name: John
Field1: value1
Field2: value2

Name: Jane
Field1: value3
Field2: value4

I can accomplish this by looping through each row, then outputting that
row's table.  This gets the job done, but it seems there must be a better
way.  I'm going to need to do this sort of conversion a lot,
so the simpler the better.  is there a better way to approach it than the
code below?  is there a more general term for the sort of transformation i'm
trying to make that might help guide my searching?

i realize i need to look into better methods of outputting HTML tables (like
r2html).

here's the basic idea.  'labkey.data' is the data frame produced by my SQL
query:

D<-labkey.data
H<-colnames(D)
T<-t(D)
L<-length(D$id)

output <- ""

for(i in 1:L) {
R<-my.row <- D[i, ]
R<-t(R)
Len<-length(R)

output <- paste(output, "")
for(j in 1:Len) {
output <- paste(output,"", H[j],":", R[j], "")
}

output <- paste(output, "")

}

write(output, file="${htmlout:output}")

Thanks for any help. 
-- 
View this message in context: 
http://www.nabble.com/tranform-a-table--tp25382806p25382806.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] executing rscript from VB

2009-09-10 Thread H Rao
Hi,
I am looking to execute an R script from VB as  below.
The script runs fine but the redirection doesnt seem to happen. The
redirection operator and the out file seem to be treated as arguments
to the R script. Is there a way to get the > operator working

thanks, R

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "E:/R/bin/Rscript.exe";
proc.StartInfo.Arguments = "E:/R/bin/test.r > test.out";
proc.StartInfo.UseShellExecute = true;
proc.Start();

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Build a connectivity between .NET and R without using any interface

2009-09-10 Thread Gabor Grothendieck
System.Diagnostics.Process in .Net can launch any program
such as Rscript.  If that is not enough of a pointer to get you
going you need to post to a .Net group since this really is
about .Net programming, not about R programming.

On Thu, Sep 10, 2009 at 8:40 AM, Amitava1 M  wrote:
> Dear All
>
> I like to develop an application using .NET and R. The front end would be
> .NET and statistical analysis would be done in R in the back end. So I
> want to integrate .NET(VB) with R without using any interface (e.g., R
> (D)com) to control. Secondly, I like to use Rscript (by calling .R files)
> from VB .NET environment for the analysis. Finally, I want to display the
> R-outputs including graphs on .NET controls (UI).
>
> Please help me out. Thank you in advance.
>
> Regards
> Amitava
> =-=-=
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Xyplot, multi line title via main, all lines left justified

2009-09-10 Thread Deepayan Sarkar
On Wed, Sep 9, 2009 at 2:53 PM, Afshartous, David
 wrote:
>
> All,
>
> Below is an xyplot plot with multiple panels and a title produced via main:
>
> library("lattic")
> data.ex = data.frame(y = rnorm(10), t = rep(1:5, 2), group = rep(c(0,1),
> each = 5))
>
> xyplot(y ~ t | as.factor(group), data = data.ex,
>    main = list("Put figure caption here xx
>    want this line left justified" ))
>
> I must be mis-interpreting the help description for main under xyplot, and
> the descriptions of just, hjust, and vjust in textGrob, since manipulation
> of these arguments do not seem to produce the desired result of having the
> second line of text left-justified.

This seems to work. You need to choose a suitable value of 'x', as the
default will be to start at the center.

xyplot(y ~ t | as.factor(group), data = data.ex,
   main = textGrob("Put figure caption here
xx
want this line left justified", x = 0, hjust = 0))

-Deepayan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Insall package

2009-09-10 Thread Duncan Murdoch

On 9/10/2009 6:44 AM, wesley mathew wrote:

Dear Sir

Subject: - *Install " rscproxy_1.3-1.tar.gz "*

 I am working in Windows system.  I was try  to install *rscproxy* package
in  two way.
 *1.* install.packages ("rscproxy_1.3-1.tar.gz"),  It shows the Warning:
unable to access index for repository
http://cran.pt.r-project.org/bin/windows/contrib/2.9
 *2. * install.packages("C:/Program Files/R/rscproxy_1.3-1.tar.gz", repos =
NULL) It also show warning ( Error in gzfile(file, "r") : cannot open the
connection In addition: Warning   messages: 1: In unzip(zipname, exdir =
dest) : error 1 in extracting from zip file 2: In gzfile(file, "r") :
cannot open compressed file 'rscproxy_1.3-1.tar.gz/DESCRIPTION', probable
reason 'No such file or directory'  )

 Could you please suggest, how to solve this problem,


rscproxy is available on CRAN, so you could just use

install.packages("rscproxy")

and it would download and install the right version for you.

If you really want to build from source, here are some instructions:

On Windows, install.packages() assumes you're installing a binary 
package.  ".tar.gz" indicates a source package, so you need to add 
type="source" to the args to install.packages(), as well as repos=NULL.


You don't mention installing the Rtools, so you may find even this 
doesn't work:  installing a package needs a lot of tools that don't come 
with Windows.  You can get them from www.murdoch-sutherland.com/Rtools.


BTW, installing packages from source is rarely needed in Windows:  you 
can get Uwe Ligges' system to convert the source to a binary for you, if 
it's straightforward.  See http://win-builder.r-project.org/.  (I have a 
feeling that rscproxy isn't a straightforward package, but I've never 
tried to build it.)


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Build a connectivity between .NET and R without using any interface

2009-09-10 Thread Duncan Murdoch

On 9/10/2009 8:40 AM, Amitava1 M wrote:

Dear All

I like to develop an application using .NET and R. The front end would be 
.NET and statistical analysis would be done in R in the back end. So I 
want to integrate .NET(VB) with R without using any interface (e.g., R 
(D)com) to control. Secondly, I like to use Rscript (by calling .R files) 
from VB .NET environment for the analysis. Finally, I want to display the 
R-outputs including graphs on .NET controls (UI).


Please help me out. Thank you in advance.


Those seem to be mostly questions about .NET  -- you may be better off 
asking Microsoft.  R's interface is described in the Writing R 
Extensions manual, assuming that a front-end would be written in C or 
some similar language.  If you want to avoid the DCOM interface, you're 
going to have to work out how to make .NET act the way described in that 
manual.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Issue displaying DATES on a plot with two ordinates

2009-09-10 Thread clair.crossup...@googlemail.com
Dear all,

I am having an issue with displaying the dates on a plot with two
ordinates (i.e. two differently scaled y-axes). Instead of dates
appearing on the x-axis I am instead seeing a string of numbers
(14460, 14465, 14470 and 14475).

example R code:

library(plotrix)
x.Left <- as.Date(c('2009-08-04', '2009-08-08', '2009-08-11',
'2009-08-15', '2009-08-18'), format="%Y-%m-%d")
x.Right <- as.Date(c('2009-08-05', '2009-08-09', '2009-08-12',
'2009-08-16', '2009-08-19'), format="%Y-%m-%d")
y.Left <- c(70.13, 75.1, 74.35, 78.9, 80.92)
y.Right <- c(35, 45, 50, 47, 53)
twoord.plot(x.Left, y.Left, x.Right, y.Right, xlab="Date", ylab="Trend
1", rylab="Trend 2", lwd=2, lcol='blue')


Thanks in advance for any help,
C.C.

P.S. I am aware of the criticisms of these sort of graphs, but they
are pretty. Also, they seem to be used a lot in meetings i've attended
recently.


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

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

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

other attached packages:
[1] plotrix_2.7

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Insall package

2009-09-10 Thread wesley mathew
Dear Sir

Subject: - *Install " rscproxy_1.3-1.tar.gz "*

 I am working in Windows system.  I was try  to install *rscproxy* package
in  two way.
 *1.* install.packages ("rscproxy_1.3-1.tar.gz"),  It shows the Warning:
unable to access index for repository
http://cran.pt.r-project.org/bin/windows/contrib/2.9
 *2. * install.packages("C:/Program Files/R/rscproxy_1.3-1.tar.gz", repos =
NULL) It also show warning ( Error in gzfile(file, "r") : cannot open the
connection In addition: Warning   messages: 1: In unzip(zipname, exdir =
dest) : error 1 in extracting from zip file 2: In gzfile(file, "r") :
cannot open compressed file 'rscproxy_1.3-1.tar.gz/DESCRIPTION', probable
reason 'No such file or directory'  )

 Could you please suggest, how to solve this problem,








-- 
Wesley C Mathew

[[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] Order a vector and move to new vector

2009-09-10 Thread Conrad Addo
I currently have a data frame with a Fund ID and NAV value.  Is it possible
to order the data frame and move to separate columns in a new data frame or
matrix in R without using a for loop?  I suppose I'd like to use a built in
function to make it faster because I will have around 60,000 entries to sort
and my current program takes too long to do this.  I know how to use order,
but is there a way to separate the result and place into new vectors of a
matrix or data frame?

Thanks

Conrad

Here are my vectors which I import from a csv file:

 ID UNAV  #1694 999.89  #1696 999.9  #1694 999.87  #1696 999.88  #1694
999.84  #1696 999.86  #1694 999.82  #1696 999.84  #1694 999.79  #1696 999.82
#1694 999.71  #1696 999.75  #1694 999.69  #1696 999.73  #1694 999.66  #1696
999.71  #1694 999.64  #1696 999.69  #1694 999.61  #1696 999.67  #1694 999.54
#1696 999.7  #1694 999.51  #1696 1002.24  #1694 999.48  #1696 1012.14  #1694
999.46  #1696 1003.38  #1694 999.43

[[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] lag a data.frame column?

2009-09-10 Thread Angel Spassov
Mark Knecht wrote (09.Sep.2009 at 10:43 -0700):
> Sometimes it's the simple things...
> 
> Why doesn't this lag X$x by 3 and place it in X$x1? (i.e. - Na's in
> the first 3 rows and then values showing up...)
> 
> The help page does talk about time series. If lag doesn't work on
> data.frame columns then what would be the right function to use to lag
> by a variable amount?
> 
> Thanks,
> Mark
> 
> 
> X=data.frame(x=seq(1:10))
> X$x1=lag(X$x, 3)
> X
> 

I think the embed function might be helpful for you, 

embed(1:10 , dimension = 3)

Best,
AS

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Build a connectivity between .NET and R without using any interface

2009-09-10 Thread Amitava1 M
Dear All

I like to develop an application using .NET and R. The front end would be 
.NET and statistical analysis would be done in R in the back end. So I 
want to integrate .NET(VB) with R without using any interface (e.g., R 
(D)com) to control. Secondly, I like to use Rscript (by calling .R files) 
from VB .NET environment for the analysis. Finally, I want to display the 
R-outputs including graphs on .NET controls (UI).

Please help me out. Thank you in advance.

Regards
Amitava 
=-=-=
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



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

2009-09-10 Thread Jim Lemon

On 09/10/2009 08:10 PM, rajesh j wrote:

Hi,

I need my plot to occupy a thin strip-like area but the plot area in R is a
square so when I save it and reduce its height to a strip in my document the
font in the graph looks flattened. Is there someway i can do this in R
itself?..so that my plot is a strip but the font looks normal

   

Hi Rajesh,
Just start the device with the aspect you want:

x11(height=2)

OR

png(myplot.png",height=150)

Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Order of multiple plots

2009-09-10 Thread Henrique Dallazuanna
I think you can try this:

par(mfrow=c(1,2))
plot(1, type = 'n', axes = FALSE, xlab = '', ylab = '')
plot(1, type = 'n', axes = FALSE, xlab = '', ylab = '')
par(mfg = c(1, 2))
plot(rnorm(10))


On Thu, Sep 10, 2009 at 1:49 AM, legen  wrote:

>
> Hello all,
>
> I have a problem and need your help.
> I am going to draw two plots in one row and two columns by using
> “par(mfrow=c(1,2))”, but I want to first draw the right plot and then draw
> the left plot. Does anybody can show me how to do it please? Thanks in
> advance.
>
> Legen
>
> --
> View this message in context:
> http://www.nabble.com/Order-of-multiple-plots-tp25377235p25377235.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] Help on percentage of random numbers for different classes

2009-09-10 Thread KABELI MEFANE
Dear Robert
 
Thank you very much for all the help, now i am enjoying working with all of you 
as you make R look simple and interesting.

--- On Thu, 10/9/09, Robert Baer  wrote:


From: Robert Baer 
Subject: Re: [R] Help on percentage of random numbers for different classes
To: "KABELI MEFANE" , R-help@r-project.org
Date: Thursday, 10 September, 2009, 8:46 AM


> I am sorry for asking this stupid question, but i have been running in 
> circles. I want to randomly generate a scaling point of between 1 and 10, for 
> say hundred entries, where the first 10% percent is has rates between 2 and 
> 7, the next 15% 3 and 7, 20% between 3 and 9, 20% between 3 and  10, 35% 
> between 5 and 10. The problem is that i can only generate the usual 100 using 
> runif function

Something like this might work for you:
# set total sample size to greater than or equal to 100
# and mod 0 wrt 100 to preserve the percentages
# here say 200
ss=200

# Create a vector with the desired properties
vector=c(
sample(2:7,ss/10,replace=TRUE),
sample(3:7,ss/15,replace=TRUE),
sample(3:9,ss/20,replace=TRUE),
sample(3:10,ss/20,replace=TRUE),
sample(5:10,ss/10,replace=TRUE))

# print out the vector
vector



> 
>  > y<-c(ceiling(10*runif(100)))
>> y
>   [1] 10  8  5  2  4  1  6  7  1  6  8  8  8  9  7  7  8  8  2  7  3 10  1 7  
>1
>  [26] 10  4  8  8  8  9  3  7  8  4  6  7  2  3  1  9  8  2  6  7  4  8  8 9  
>7
>  [51]  6  5  4  1  8  7  9  8 10  5  3  7  5  5  4  4  7  4 10  4  9  1  5 10 
>10
>  [76]  5  5 10  7  3  4  4  9 10  6  2  6  6  6  3  8  2  2  4  4 10  6  9 4  
>3
> 
> I just want to try to avoid small numbers as much as possible. I am open to 
> suggestions, please please please.
> 
> Kabeli
> 
> 
> 
> [[alternative HTML version deleted]]
> 
> 



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



  
[[alternative HTML version deleted]]

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


Re: [R] Color index in image function

2009-09-10 Thread Bernardo Rangel Tura
On Wed, 2009-09-09 at 02:33 -0700, FMH wrote:
> Thank you for the hints, but how could i add the grid lines which have 
> numbers, representing the height of the volcano on the image.
> 
> Thank you
> 

So I think this script  is what you need


Brazilan.Pallete <- colorRampPalette(c("green","yellow", "blue"))
require(fileds)
image.plot(volcano, col = Brazilan.Pallete(50), axes = FALSE) 
contour(volcano, levels = seq(90, 200, by = 5), add = TRUE)

-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil


> 
> 
> - Original Message 
> From: Bernardo Rangel Tura 
> To: FMH 
> Sent: Tuesday, September 8, 2009 10:14:07 AM
> Subject: Re: [R] Color index in image function
> 
> On Mon, 2009-09-07 at 07:59 -0700, FMH wrote:
> > Thank you for the tips. I have manage to run your script, but  was still 
> > never get the way to include the color index beside the image which could 
> > explain the intensity of the color from the lower index(green) to the 
> > higher index(blue). This color index might be represented by  an increasing 
> > of color index in another table beside the image, started from green 
> > followed by green-yellow, yellow, yellow-blue and blue?
> > 
> > Could someone please advice on this matter?
> > 
> > Cheers
> > Fir
> > 
> 
> Hi FHM,
> 
> Well If you desire one color index in a imageplot  I don't know solve
> your problem.
> 
> But in your scirptyou use image and 
> 
> image(x, y, volcano, col = terrain.colors(100), axes = FALSE)
> contour(x, y, volcano, levels = seq(90, 200, by = 5),
> add = TRUE, col = "peru")
> 
> In this case I suggest you use 
> 
> Brazilan.Pallete <- colorRampPalette(c("green","yellow", "blue"))
> filled.contour(volcano, color = Brazilan.Pallete)

-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Joining Characters in R {issue with paste}

2009-09-10 Thread Michael Dewey

At 22:13 09/09/2009, Abhishek Pratap wrote:

I did try ?paste and paste(a,b,separator=""). same result


Your second example pastes three strings together. "a" "b" and " ", 
the third of which you have named separator which is not the same as sep.



Thanks,
-Abhi

On Wed, Sep 9, 2009 at 5:11 PM, milton ruser  wrote:

> You not tryed ?paste  :-)
>
> paste(a,b,sep="")
>
> bests
>
> milton
>
> On Wed, Sep 9, 2009 at 5:08 PM, Abhishek Pratap 
wrote:

>
>> Hi Guys
>> I am want to join to strings in R. I am using paste but not getting
>> desirable result.
>>
>> For the sake of clarity, a quick example:
>>
>> > a="Bio"
>> > b="iology"
>> > paste(a,b)
>> [1] "Bio iology"
>>
>>
>> *There is a SPACE in the word biology which is what I dont want *
>>
>>
>> Thanks,
>> -Abhi
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> 
http://www.R-project.org/posting-guide.html

>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]


Michael Dewey
http://www.aghmed.fsnet.co.uk

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 area reduction

2009-09-10 Thread rajesh j
Hi,

I need my plot to occupy a thin strip-like area but the plot area in R is a
square so when I save it and reduce its height to a strip in my document the
font in the graph looks flattened. Is there someway i can do this in R
itself?..so that my plot is a strip but the font looks normal

-- 
Rajesh.J

[[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] SPSS Statistics-R Integration Plug-In

2009-09-10 Thread Michael Bibo

> . The links are: R Sources -> Windows -> base -> 
> Previous Releases.  The direct link is: http://cran.at.r-
> project.org/bin/windows/base/old/

 That should of course read "R Binaries -> Windows -> base -> Previous 
Releases".

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Facing error in loading dababase table

2009-09-10 Thread Uwe Ligges



Abbas R. Ali wrote:


Hi
 
Facing error in loading dababase table. Folowing is my code:
 
library('RODBC') 
channel = odbcConnect("dsn", "", "")

data1 = sqlQuery(channel, "SELECT * FROM TABLE", as.is = TRUE)
odbcClose(channel)  


The object data1 is there, you do not need to load it from a file!

Uwe Ligges



load(data1) # it is giving me error here that "In data(data1) : data set 'data1' 
not found"

Can anyone tell its solution?
 
Thanks
 
Abbas




  
	[[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] How should a SelfStart function handle illegal parameter values?

2009-09-10 Thread Keith Jewell
Hi Everyone,

I'm trying to write selfStart non-linear models for use with nls. In these 
models some combinations of parameter values are illegal; the function value 
is undefined.

That's OK when calling the function directly [e.g.  SSmodel(x, pars...)]; I 
return an appropriate non-value such as NA or Inf.

However, when called from nls [e.g. nls(y~SSmodel(x, pars...), ...)] those 
non-values lead to errors such as (but not limited to):
Error in numericDeriv(form[[3L]], names(ind), env) :
  Missing value or an infinity produced when evaluating the model
or (if I provide a gradient attribute)
Error in qr.default(.swts * attr(rhs, "gradient")) :
  NA/NaN/Inf in foreign function call (arg 1)

A toy example demonstrating my problem (legal values of param are >1):
#---
SSexample<-selfStart(
 model=function(x, param) x^log(param-1),
 initial = function(mCall, data, LHS){
   val<- 1.001
   names(val) <- mCall[c("param")]
   val
   },
 parameters=c("param")
)
#
nls(y~SSexample(x, par), data=data.frame(x=1:10,y=rnorm(10)))
#-

(repeat the last line a few times and you'll get the error).

I can't see a way of making nls either stick to legal parameter values, or 
accept NA/NaN/Inf as indicating "bad" parameter values.

I really do want to use nls rather than a bounded optimisation tool (such as 
optim) because this fits into a much bigger picture predicated on nls.

I'd appreciate any suggestions.

Keith Jewell

> sessionInfo()
R version 2.9.1 (2009-06-26)
i386-pc-mingw32

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

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

other attached packages:
[1] xlsReadWrite_1.3.3 svSocket_0.9-43svMisc_0.9-48  TinnR_1.0.3
R2HTML_1.59-1  Hmisc_3.6-1

loaded via a namespace (and not attached):
[1] cluster_1.12.0  grid_2.9.1  lattice_0.17-25 stats4_2.9.1
VGAM_0.7-9

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Facing error in loading dababase table

2009-09-10 Thread Abbas R. Ali


Hi
 
Facing error in loading dababase table. Folowing is my code:
 
library('RODBC') 
channel = odbcConnect("dsn", "", "")
data1 = sqlQuery(channel, "SELECT * FROM TABLE", as.is = TRUE)
odbcClose(channel)  
load(data1) # it is giving me error here that "In data(data1) : data set 
'data1' not found"

Can anyone tell its solution?
 
Thanks
 
Abbas



  
[[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] Order of multiple plots

2009-09-10 Thread legen

Hello all,

I have a problem and need your help.
I am going to draw two plots in one row and two columns by using
“par(mfrow=c(1,2))”, but I want to first draw the right plot and then draw
the left plot. Does anybody can show me how to do it please? Thanks in
advance.

Legen

-- 
View this message in context: 
http://www.nabble.com/Order-of-multiple-plots-tp25377235p25377235.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] How to do rotation for polygon?

2009-09-10 Thread Hemavathi Ramulu
Hi everyone,
I still couldn't get the diagram as I mentioned before. I try Grey and
Milton suggestion but
it confusing.
I hope anyone helped me.

Thanks in advance.

Regards,
Hema.

On Thu, Sep 3, 2009 at 11:39 PM, Greg Snow  wrote:

> The my.symbols and ms.polygon functions in the TeachingDemos package may
> help.
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
>
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> > project.org] On Behalf Of Hemavathi Ramulu
> > Sent: Wednesday, September 02, 2009 11:05 PM
> > To: r-help@r-project.org
> > Subject: [R] How to do rotation for polygon?
> >
> > Hi everyone,
> > I have coding for repeating pentagon as below:
> >
> > plot(0:11,type="n")
> > for (i in 1:10 )polygon(rep(c(4,5,7,8,6)), i*c(.5,.3,.3,.5,.7), bor=2)
> >
> > which are increasing vertically.
> >
> > Now, I want to know how to rotate the pentagon, so that I will get
> > pattern
> > like flower.
> > Basicly, repeating pentagon in circle.
> >
> > Thanks alot for helping me to solve this problem.
> > --
> > Hemavathi
> >
> >   [[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.
>



-- 
Hemavathi Ramulu

[[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] Help on percentage of random numbers for different classes

2009-09-10 Thread Robert Baer
I am sorry for asking this stupid question, but i have been running in 
circles. I want to randomly generate a scaling point of between 1 and 10, 
for say hundred entries, where the first 10% percent is has rates between 
2 and 7, the next 15% 3 and 7, 20% between 3 and 9, 20% between 3 and  10, 
35% between 5 and 10. The problem is that i can only generate the usual 
100 using runif function


Something like this might work for you:
# set total sample size to greater than or equal to 100
# and mod 0 wrt 100 to preserve the percentages
# here say 200
ss=200

# Create a vector with the desired properties
vector=c(
sample(2:7,ss/10,replace=TRUE),
sample(3:7,ss/15,replace=TRUE),
sample(3:9,ss/20,replace=TRUE),
sample(3:10,ss/20,replace=TRUE),
sample(5:10,ss/10,replace=TRUE))

# print out the vector
vector





 > y<-c(ceiling(10*runif(100)))

y
  [1] 10  8  5  2  4  1  6  7  1  6  8  8  8  9  7  7  8  8  2  7  3 10  1 
7  1
 [26] 10  4  8  8  8  9  3  7  8  4  6  7  2  3  1  9  8  2  6  7  4  8  8 
9  7
 [51]  6  5  4  1  8  7  9  8 10  5  3  7  5  5  4  4  7  4 10  4  9  1  5 
10 10
 [76]  5  5 10  7  3  4  4  9 10  6  2  6  6  6  3  8  2  2  4  4 10  6  9 
4  3


I just want to try to avoid small numbers as much as possible. I am open 
to suggestions, please please please.


Kabeli



[[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] [R-pkgs] new package MLCM: Maximum Likelihood Conjoint Measurement

2009-09-10 Thread Ken Knoblauch


This is to announce a new package MLCM on CRAN.
The package provides functions for estimating perceptual scales
by maximum likelihood from data collected in a conjoint measurement
experiment. Data for conjoint measurement are typically collected
using a psychophysical procedure. The stimuli vary along 2 or more
dimensions.  The observer views pairs of stimuli and judges which
stimulus of each pair is higher on a specified dimension.
For example, stimuli may be goods baskets containing amounts of
milk and honey (dimensions) and the subject may order each pair
of baskets by subjective desirability.  This package contains
tools to estimate the additive contribution of the n scales
to the judgment by a maximum likelihood method under several
hypotheses of how the perceptual dimensions interact.

--
Ken Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] ggplot2: mixing colour and linetype in geom_line

2009-09-10 Thread Benoit Boulinguiez

many thanks Felipe

I didn't know the melt function.
I'll have a close look at it.


Regards/Cordialement


Benoit Boulinguiez 


-Message d'origine-
De : Felipe Carrillo [mailto:mazatlanmex...@yahoo.com] 
Envoyé : mercredi 9 septembre 2009 20:40
À : r-help@r-project.org; Benoit Boulinguiez
Objet : Re: [R] ggplot2: mixing colour and linetype in geom_line

Is this what you want?

x <- structure(list(Temp = c(25.9765, 26.57025, 27.164, 27.7565, 28.34892,
28.94142, 29.53125, 30.12233, 30.71483, 31.30983, 31.90233, 32.49475,
33.08458, 33.67575, 34.26558, 34.85933, 35.45183, 36.04683, 36.63933,
37.23042, 37.82417, 38.414), X22 = c(4.62e-12, 4.73e-12, 4.62e-12, 4.57e-12,
4.64e-12, 4.71e-12, 4.7e-12, 4.64e-12, 4.71e-12, 4.51e-12, 4.52e-12,
4.47e-12, 4.58e-12, 4.56e-12, 4.53e-12, 4.54e-12, 4.55e-12, 4.54e-12,
4.53e-12, 4.5e-12, 4.55e-12, 4.57e-12), X43 = c(6.14e-11, 6.11e-11,
6.04e-11, 6.06e-11, 6.01e-11, 6.01e-11, 5.93e-11, 5.91e-11, 5.91e-11,
5.88e-11, 5.8e-11, 5.8e-11, 5.79e-11, 5.75e-11, 5.74e-11, 5.7e-11, 5.67e-11,
5.66e-11, 5.61e-11, 5.57e-11, 5.58e-11, 5.57e-11 ), X44 = c(3.93e-10,
3.91e-10, 3.91e-10, 3.9e-10, 3.89e-10, 3.88e-10, 3.87e-10, 3.86e-10,
3.85e-10, 3.85e-10, 3.85e-10, 3.83e-10, 3.83e-10, 3.82e-10, 3.8e-10,
3.8e-10, 3.79e-10, 3.78e-10, 3.77e-10, 3.77e-10, 3.76e-10, 3.75e-10), X45 =
c(1.29e-11, 1.28e-11, 1.27e-11, 1.27e-11, 1.28e-11, 1.27e-11, 1.27e-11,
1.26e-11, 1.25e-11, 1.23e-11, 1.23e-11, 1.24e-11, 1.23e-11, 1.22e-11,
1.23e-11, 1.22e-11, 1.21e-11, 1.2e-11, 1.19e-11, 1.21e-11, 1.19e-11,
1.2e-11), X48 = c(2.05e-10, 2.05e-10, 2.05e-10, 2.03e-10, 2.03e-10,
2.02e-10, 2.02e-10, 2.01e-10, 2.01e-10, 2e-10, 1.99e-10, 1.99e-10, 1.98e-10,
1.97e-10, 1.97e-10, 1.96e-10, 1.96e-10, 1.95e-10, 1.94e-10, 1.94e-10,
1.94e-10, 1.92e-10), 
X58 = c(6.78e-12, 6.8e-12, 6.87e-12, 6.79e-12, 6.75e-12, 
6.67e-12, 6.65e-12, 6.63e-12, 6.59e-12, 6.54e-12, 6.6e-12, 
6.57e-12, 6.57e-12, 6.43e-12, 6.42e-12, 6.48e-12, 6.38e-12, 
6.37e-12, 6.45e-12, 6.35e-12, 6.29e-12, 6.3e-12), X60 = c(9.31e-12, 
9.43e-12, 9.28e-12, 9.26e-12, 9.18e-12, 9.24e-12, 9.2e-12, 
9.11e-12, 9.17e-12, 9e-12, 9.09e-12, 8.95e-12, 9.02e-12, 
8.89e-12, 8.97e-12, 8.93e-12, 8.86e-12, 8.9e-12, 8.85e-12, 
8.82e-12, 8.86e-12, 8.8e-12)), .Names = c("Temp", "X22", "X43", "X44",
"X45", "X48", "X58", "X60"), class = "data.frame", row.names = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22"))

attach(x)
 xmelt <- melt(x,id.vars="Temp");head(xmelt)
 qplot(Temp,value,colour=variable,linetype=variable,data=xmelt,geom="line")

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA


--- On Wed, 9/9/09, Benoit Boulinguiez 
wrote:

> From: Benoit Boulinguiez 
> Subject: [R]  ggplot2: mixing colour and linetype in geom_line
> To: r-help@r-project.org
> Date: Wednesday, September 9, 2009, 8:24 AM Hi all,
>  
> I try to represent a multiple curve graphic where the x-axis is the 
> temperature and the different y-axes are the different X
> (X22,X43,X44...)
> some X corresponds to the same molecule (22 and 44 are for
> CO2 for instance)
> so I use the same colour for them.
>  
> I wanna mix the linetype with the colour to be able to visually see 
> the difference between X43 and X45 The best I have done up to now is 
> this code but it crashes with :"Error in col2rgb(colour, TRUE) : 
> invalid color name 'AA'"
>  
> if I skip the linetype in geom it works perfectly of course
>  
>  
> THT_N2_ATGMS_plot<-ggplot(THT_N2_ATGMS,aes(x=Temp)) +
>  
> # geom_line(aes(y=X22,colour="CO2")) + # 
> geom_line(aes(y=X44,colour="CO2")) +
>  
>  geom_line(aes(y=X43,colour="AA",linetype="43")) +
>  geom_line(aes(y=X45,colour="AA",linetype="45"))
>  
>  
>  
> data set looks like:
>          Temp
>   X22      X43
> X44      X45      X48
>     X58      X60
> 1    25.97650 4.62e-12 6.14e-11 3.93e-10 1.29e-11 2.05e-10 6.78e-12 
> 9.31e-12
> 2    26.57025 4.73e-12 6.11e-11 3.91e-10 1.28e-11 2.05e-10 6.80e-12 
> 9.43e-12
> 3    27.16400 4.62e-12 6.04e-11 3.91e-10 1.27e-11 2.05e-10 6.87e-12 
> 9.28e-12
> 4    27.75650 4.57e-12 6.06e-11 3.90e-10 1.27e-11 2.03e-10 6.79e-12 
> 9.26e-12
> 5    28.34892 4.64e-12 6.01e-11 3.89e-10 1.28e-11 2.03e-10 6.75e-12 
> 9.18e-12
> 6    28.94142 4.71e-12 6.01e-11 3.88e-10 1.27e-11 2.02e-10 6.67e-12 
> 9.24e-12
> 7    29.53125 4.70e-12 5.93e-11 3.87e-10 1.27e-11 2.02e-10 6.65e-12 
> 9.20e-12
> 8    30.12233 4.64e-12 5.91e-11 3.86e-10 1.26e-11 2.01e-10 6.63e-12 
> 9.11e-12
> 9    30.71483 4.71e-12 5.91e-11 3.85e-10 1.25e-11 2.01e-10 6.59e-12 
> 9.17e-12 10   31.30983 4.51e-12 5.88e-11 3.85e-10
> 1.23e-11 2.00e-10 6.54e-12 9.00e-12
> 11   31.90233 4.52e-12 5.80e-11 3.85e-10
> 1.23e-11 1.99e-10 6.60e-12 9.09e-12
> 12   32.49475 4.47e-12 5.80e-11 3.83e-10
> 1.24e-11 1.99e-10 6.57e-12 8.95e-12
> 13   33.08458 4.58e-12 5.79e-11 3.83e-10
> 1.23e-11 1.98e-10 6.57e-12 9.02e-12
> 14   33.67575 4.56e-12 5.