Re: [R] eval(parse(...)) only once in a function

2012-09-17 Thread David Winsemius

On Sep 16, 2012, at 11:27 PM, Christof Kluß wrote:

> Hi
> 
> I would like to have something like
> 
> str <- "df$JT == 12"
> 
> fun <- function(df) {
> 
>  b <- eval(parse(str))
> 
>  return(b)
> }
> 

What are you trying to do?

str <- quote(df$JT == 12)

> but for performance "eval(parse(a))" should not be evaluated at each
> function call, but should work as
> 
> fun <- function(df) {
> 
>  b <- df$JT == 12
> 
>  return(b)
> }
> 
> Do you have an idea how I can implement this?

Implement what?  And what issues regarding "performance" are relevant? What 
does it mean to "not evaluate at each function call"?

str <- quote(df$JT == 12)
fun <- function(df) {
b<-eval(str)
return(b)
   }

df3 <- data.frame(JT=12)
fun(df3)
#[1] TRUE

-- 



David Winsemius, MD
Alameda, CA, USA

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


Re: [R] Using paste to create and evaluate a variable expression

2012-09-17 Thread David Winsemius

On Sep 16, 2012, at 9:04 PM, Bryan Keller wrote:

> Is it possible to use "paste" to write out an expression and evaluate it?

Of course.

?as.expression
?parse
?eval

> Suppose I want to add two vectors X1 and X2, defined as follows:
> 
> X1 <- 1:6
> X2 <- 6:1
> 
> If I write the following it looks like what I want but is a character:
> noquote(paste(paste("X", 1, sep = ""), paste("X", 2, sep = ""), sep = "+"))

Instead of noquote, you might want to look at bquote.

> 
> Is there a way to tell R that I want to evaluate the text, not just print
> it out as a character?

Evaluate in what context? It looks as though you are building a formula.

parse(text= paste(paste("X", 1, sep = ""), paste("X", 2, sep = ""), sep = "+") )
expression(X1+X2)

-- 
David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Boxplot lattice vs standard graphics

2012-09-17 Thread Massimo Bressan

thank you for the help, bert

unfortunately, for reasons I can not understand (yet) I can not put to 
wortk it all

(I'm always in trouble with the panel functions);

max

Il 14/09/2012 18:38, Bert Gunter ha scritto:

Thanks for the example. Makes it easy to see what you mean.

Yes, if I understand you correctly, you are right:
boxplot() (base) transforms the axes, so ?boxplot.stats, which is the
function that essentially computes the boxplot, does so on the
original data.
bwplot(lattice) transforms the data first, as the documentation for
the "log" component of the scales list makes clear, and **then** calls
boxplot.stats.

Although I think the latter makes more sense then the former, I think
the way to do it is to modify the "stats" function in an explicit call
to panel.bwplot to something like (UNTESTED!)
mystats <- function(x){
out <- boxplot.stats(10^x)
out$stats <- log10(out$stats)
out$conf <- log10(out$conf) ## Omit if you don't want notches
out$out <- log10(out$out)
out ## With the boxplot statistics converted to the log10 scale
}

I leave it to you to test and modify as necessary.

Cheers,
Bert

On Fri, Sep 14, 2012 at 2:37 AM, maxbre  wrote:

Given my reproducible example

test<-structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L), .Label = c("A",
"B", "C", "D", "E"), class = "factor"), conc = c(2.32, 0.902,
0.468, 5.51, 1.49, 0.532, 0.72, 0.956, 0.887, 20, 30, 2.12, 0.442,
10, 50, 110, 3.36, 2.41, 20, 70, 3610, 100, 4.79, 20, 0.0315,
30, 60, 1, 3.37, 80, 1.21, 0.302, 0.728, 1.29, 30, 40, 90, 30,
0.697, 6.25, 0.576, 0.335, 20, 10, 620, 40, 9.98, 4.76, 2.61,
3.39, 20, 4.59)), .Names = c("site", "conc"), row.names = c(NA,
52L), class = "data.frame")



And the following code

#standard graphics
with(test,boxplot(conc~site, log="y"))

#lattice
bwplot(conc~site, data=test,
scales=list(y=list(log=10))
)

There is an evident difference for site A, B, D in the way some outliers are
plotted by comparing the plot produced by lattice vs. the standard graphics

I think to understand this might be due to the different treatment of data:
i.e. log transformation (before or after the plotting?)

Is it possible to achieve the same plotting result with both graphic
facilities?
I would like to show the outliers also in lattice…

Thank you

http://r.789695.n4.nabble.com/file/n4643121/standard.png

http://r.789695.n4.nabble.com/file/n4643121/lattice.png





--
View this message in context: 
http://r.789695.n4.nabble.com/Boxplot-lattice-vs-standard-graphics-tp4643121.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] eval(parse(...)) only once in a function

2012-09-17 Thread Heramb Gadgil
If you have a data frame "df" with a column "JT"

Try this one:
str <- "df$JT == 12"

fun<-function(str){b<-eval(parse(text=str))
return(b)}

fun(str)

On Mon, Sep 17, 2012 at 11:57 AM, Christof Kluß wrote:

> Hi
>
> I would like to have something like
>
> str <- "df$JT == 12"
>
> fun <- function(df) {
>
>   b <- eval(parse(str))
>
>   return(b)
> }
>
> but for performance "eval(parse(a))" should not be evaluated at each
> function call, but should work as
>
> fun <- function(df) {
>
>   b <- df$JT == 12
>
>   return(b)
> }
>
> Do you have an idea how I can implement this?
>
> Thx
> Christof
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Zip a file

2012-09-17 Thread Rantony
Hi Arun,

 

I tried this way, but getting an error like

 

Using Eclips:

“Error in .rj.originals$help(..., help_type = "html") : 'topic' should be a 
name, length-one character vector or reserved word”

 

Using R:

Error: could not find function "zip"

 

So, is it required to install any package for zip functioning ?

 

 

 

From: arun kirshna [via R] [mailto:ml-node+s789695n4643049...@n4.nabble.com] 
Sent: Thursday, September 13, 2012 11:55 PM
To: Akkara, Antony (GE Energy, Non-GE)
Subject: Re: Zip a file

 

HI, 

If you look ?zip(), the usage is: 
 zip(zipfile, files, flags = "-r9X", extras = "", 
 zip = Sys.getenv("R_ZIPCMD", "zip")) 
 
A.K. 




- Original Message - 
From: Rantony <[hidden email]> 
To: [hidden email] 
Cc: 
Sent: Thursday, September 13, 2012 8:10 AM 
Subject: [R] Zip a file 

Hi, 

How to zip a csv file ? i tried with "zipfile.ZipFile" - but it showing 
function could not find. 
Is there have any other way to zip files without installing any package ? 

- Thanks in advance 
Antony 



-- 
View this message in context: 
http://r.789695.n4.nabble.com/Zip-a-file-tp4643012.html
Sent from the R help mailing list archive at Nabble.com. 

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


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





If you reply to this email, your message will be added to the discussion below:

http://r.789695.n4.nabble.com/Zip-a-file-tp4643012p4643049.html 

To unsubscribe from Zip a file, click here 

 .
NAML 

  





--
View this message in context: 
http://r.789695.n4.nabble.com/Zip-a-file-tp4643012p4643344.html
Sent from the R help mailing list archive at Nabble.com.
[[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] LoadLibrary failure: : %1 is not a valid Win32 application although arch x64 has been specified

2012-09-17 Thread Franckx Laurent
Dear all,

I have problems loading a library in the 64 version of R.

The following happens:


· I have a file, equildistC.cpp, which contains a few lines of C++ code.

· I have compiled the file using the following commands:
PATH =  
c:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin;C:\Rtools\gcc-4.6.3\bin64;C:\Rtools\gcc-4.6.3\i686-w64-mingw32;C:\R-2.15.1\bin\i386;C:\R-2.15.1\bin\x64;c:\windows;c:\windows\system32;C:\Windows\SysWOW64
R --arch x64 CMD SHLIB equildistC.cpp

· I have received no messages indicating problem during compilation, 
and both the equildistC.o and the equildistC.dll have been created.

· When I load the dll in the 32bit version of R with 
dyn.load("C:\\Ccodefortransortmodel\\equildistC.dll"), things appear to go well.

· However, in the 64 bit version, I get the message:
Error in inDL(x, as.logical(local), as.logical(now), ...) :
  unable to load shared object 'C:/Ccodefortransortmodel/equildistC.dll':
  LoadLibrary failure:  %1 is not a valid Win32 application.


I have googled the error message. Initially I had omitted “--arch x64” when 
compiling the file, but even after specifying the architecture, the error 
persists.
However, I definitely need to be able to run my code on the 64 version.


Kind regards
Laurent


[http://www.vito.be/e-maildisclaimer/bsds.png] 
VITO Disclaimer: http://www.vito.be/e-maildisclaimer

[[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] Adding legends on plots using Lattice package

2012-09-17 Thread jpm miao
To dear Dr Sarkar and anyone that knows about Lattice package,

   I make 4 graphs by Lattice package. Each of the graphs has two time
series. All the series are plotted in plain lines by default, and I would
like one series to be in plain line and the other to be in dotted line in
each graph. How can I modify the command of xyplot in the following line to
achieve this? It seems that "key" or "auto.key"  parameters are needed, but
I don't know how to do it. Thank you very much!


require(graphics)
library(lattice)
data1<-read.csv(file="G_Results_3FX1.csv", header=TRUE)
xts<-ts(data1[,2:9],frequency = 4, start = c(1983, 1))
xyplot(xts, screen=list("a","a","b","b","c","c","d","d"), layout=c(2,2),
scales=list(x="same",y="same"))



Miao

[[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] LoadLibrary failure: : %1 is not a valid Win32 application although arch x64 has been specified

2012-09-17 Thread Duncan Murdoch

On 12-09-17 3:56 AM, Franckx Laurent wrote:

Dear all,

I have problems loading a library in the 64 version of R.

The following happens:


· I have a file, equildistC.cpp, which contains a few lines of C++ code.

· I have compiled the file using the following commands:
PATH =  
c:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin;C:\Rtools\gcc-4.6.3\bin64;C:\Rtools\gcc-4.6.3\i686-w64-mingw32;C:\R-2.15.1\bin\i386;C:\R-2.15.1\bin\x64;c:\windows;c:\windows\system32;C:\Windows\SysWOW64
R --arch x64 CMD SHLIB equildistC.cpp


That runs the 32 bit version of R (since you list it first in your 
path).  I don't see any docs that state that it will pay attention to 
the --arch directive.  (The docs say that syntax is supported under 
Unix-alikes, not under Windows.)







· I have received no messages indicating problem during compilation, 
and both the equildistC.o and the equildistC.dll have been created.

· When I load the dll in the 32bit version of R with 
dyn.load("C:\\Ccodefortransortmodel\\equildistC.dll"), things appear to go well.

· However, in the 64 bit version, I get the message:
Error in inDL(x, as.logical(local), as.logical(now), ...) :
   unable to load shared object 'C:/Ccodefortransortmodel/equildistC.dll':
   LoadLibrary failure:  %1 is not a valid Win32 application.


I have googled the error message. Initially I had omitted “--arch x64” when 
compiling the file, but even after specifying the architecture, the error 
persists.
However, I definitely need to be able to run my code on the 64 version.


Then you should take the 32 bit version out of your path.

Duncan Murdoch




Kind regards
Laurent


[http://www.vito.be/e-maildisclaimer/bsds.png] 
VITO Disclaimer: http://www.vito.be/e-maildisclaimer

[[alternative HTML version deleted]]



This body part will be downloaded on demand.



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

2012-09-17 Thread Tagmarie
Even though I work with R since a year or so I still struggle with simple
problems. I hope someone can help me with this. Been trying for days and am
a little frustrated now. 

I have a data frame somewhat like the one bellow:

dattrial<-data.frame(a=c(1,NA,rnorm(4,10)), Week=c(3,3,3,4,4,4))

I want to know how many NAs I have in week 3 and in week 4. 



--
View this message in context: 
http://r.789695.n4.nabble.com/count-NAs-per-week-tp4643351.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] download truncating large files

2012-09-17 Thread Ian Shannon
Hi there,

I have had a problem with loading the package XLConnectJars_0.2-0.zip from the 
CRAN mirrors. The problem occurs when executing
utils:::menuInstallPkgs()
I have traced the problem down to the "download" internal command.  It appears 
that files over approx 15 MB are being truncated.  The exact point of 
truncation varies slightly but the truncation is on a 4096-byte boundary.

I am running =>


R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)

I have also run the code using the -- vanilla  start-up parameter with no 
change in outcome.

I am using  "internet2"  to get past our proxy server.  I have isolated the 
problem using the following script
derived from a code fragment called by the menuInstallPkgs() function.

options(timeout = 120)   makes no difference because the failure occurs before 
the timeout of 60 (or 120) seconds elapses.


## sample R code sequence to reproduce error
setInternet2(TRUE);
url <- "http://cran.csiro.au/bin/windows/contrib/2.15/";;
dir <- "U:\\";

## This download being reasonable small works OK
file <- "XLConnect_0.2-1.zip";
status <- .Internal(download(paste0(url, file), paste0(dir, file), quiet=FALSE, 
mode="wb", cacheOK=FALSE));
cat(paste("the value of status for",  file, "is", status, "\n\n"));


## This big download fails - a progress indicator quickly progresses to 99% and 
stops
file <- "XLConnectJars_0.2-0.zip";
status <- .Internal(download(paste0(url, file), paste0(dir, file), quiet=FALSE, 
mode="wb", cacheOK=FALSE));
cat(paste("the value of status for",  file, "is", status, "\n\n"));



This produces the following output -


trying URL 'http://cran.csiro.au/bin/windows/contrib/2.15/XLConnect_0.2-1.zip'
Content type 'application/zip' length 1358587 bytes (1.3 Mb)
opened URL
downloaded 1.3 Mb

the value of status for XLConnect_0.2-1.zip is 0

trying URL 
'http://cran.csiro.au/bin/windows/contrib/2.15/XLConnectJars_0.2-0.zip'
Content type 'application/zip' length 16486857 bytes (15.7 Mb)
opened URL
downloaded 15.6 Mb

the value of status for XLConnectJars_0.2-0.zip is 0

Warning message:
In eval(expr, envir, enclos) :
  downloaded length 16355328 != reported length 16486857
>



Any suggestions on what is needed to get this going?

Thanks,


Ian
Ian Shannon
Landscape Modelling & Decision Support
Scientific Services
Office of Environment and Heritage
Department of Premier and Cabinet
PO Box A290
Sydney South
NSW  1232
+61 2 99 955 490
Ian dot Shannon at Environment dot nsw dot gov dot au
--
This email is intended for the addressee(s) named and may contain confidential 
and/or privileged information. 
If you are not the intended recipient, please notify the sender and then delete 
it immediately.
Any views expressed in this email are those of the individual sender except 
where the sender expressly and with authority states them to be the views of 
the Office of Environment and Heritage, NSW Department of Premier and Cabinet.

PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS EMAIL

[[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] multi-column factor

2012-09-17 Thread Hadley Wickham
If you have a million levels is it really necessary to use a factor? I'm
not sure what advantages it will to have to a string in this circumstance
(especially since you don't seem to know the levels a priori but have to
learn them from the data).

Hadley

On Sunday, September 16, 2012, Sam Steingold wrote:

> I have a data frame with columns which draw on the same underlying
> universe, so I want them to be factors with the same level set:
>
> --8<---cut here---start->8---
> > z <- data.frame(a=c("a","b","c"),b=c("b","c","d"),stringsAsFactors=FALSE)
> > str(z)
> 'data.frame':   3 obs. of  2 variables:
>  $ a: chr  "a" "b" "c"
>  $ b: chr  "b" "c" "d"
> > z$a <- factor(z$a,levels=union(z$a,z$b))
> > z$b <- factor(z$b,levels=union(z$a,z$b))
> > str(z)
> 'data.frame':   3 obs. of  2 variables:
>  $ a: Factor w/ 4 levels "a","b","c","d": 1 2 3
>  $ b: Factor w/ 4 levels "a","b","c","d": 2 3 4
> --8<---cut here---end--->8---
> factor(z$a,levels=union(z$a,z$b))
> is factor(z$a,levels=union(z$a,z$b)) the right way to handle this?
> maybe there is a better way to extract levels than union()?
> (bear in mind that I have ~10M rows and ~1M levels, so performance is an
> issue).
>
> Thanks!
>
> --
> Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X
> 11.0.11103000
> http://www.childpsy.net/ http://iris.org.il http://honestreporting.com
> http://camera.org http://www.memritv.org http://jihadwatch.org
> When you talk to God, it's prayer; when He talks to you, it's
> schizophrenia.
>
> __
> R-help@r-project.org  mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
RStudio / Rice University
http://had.co.nz/

[[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] Can anyone help why the errors are coming and rectify it?

2012-09-17 Thread Sri krishna Devarayalu Balanagu
Hi Everyone,

Can anyone help why the errors are coming and rectify it?


invalid.ids <- c(1,3,5)
if (length(invalid.ids)==0)   {

cat("No Errors found")
   }
else  {

cat(paste(invalid.ids), sep="\n")
  }

Error: unexpected 'else' in "else"
Error: unexpected '}' in "}"

Thank you in advance

Warm Regards
Rayalu
Notice: The information contained in this electronic mail message is intended 
only for the use of the designated recipient. This message is privileged and 
confidential. and the property of GVK BIO or its affiliates and subsidiaries. 
If the reader of this message is not the intended recipient or an agent 
responsible for delivering it to the intended recipient, you are hereby 
notified that you have received this message in error and that any review, 
dissemination, distribution, or copying of this message is strictly prohibited. 
If you have received this communication in error, please notify us immediately 
by telephone +91-40-6692 and destroy any and all 
copies of this message in your possession (whether hard copies or 
electronically stored copies).

[[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] LoadLibrary failure: : %1 is not a valid Win32 application although arch x64 has been specified

2012-09-17 Thread Franckx Laurent
Problem solved, thank you.

-Original Message-
From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com]
Sent: maandag 17 september 2012 13:05
To: Franckx Laurent
Cc: 'r-help@r-project.org'
Subject: Re: [R] LoadLibrary failure: : %1 is not a valid Win32 application 
although arch x64 has been specified

On 12-09-17 3:56 AM, Franckx Laurent wrote:
> Dear all,
>
> I have problems loading a library in the 64 version of R.
>
> The following happens:
>
>
> * I have a file, equildistC.cpp, which contains a few lines of C++ 
> code.
>
> * I have compiled the file using the following commands:
> PATH =
> c:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin;C:\Rtools\gcc-4.6.3\bin64;C:\Rto
> ols\gcc-4.6.3\i686-w64-mingw32;C:\R-2.15.1\bin\i386;C:\R-2.15.1\bin\x6
> 4;c:\windows;c:\windows\system32;C:\Windows\SysWOW64
> R --arch x64 CMD SHLIB equildistC.cpp

That runs the 32 bit version of R (since you list it first in your path).  I 
don't see any docs that state that it will pay attention to the --arch 
directive.  (The docs say that syntax is supported under Unix-alikes, not under 
Windows.)




>
> * I have received no messages indicating problem during compilation, 
> and both the equildistC.o and the equildistC.dll have been created.
>
> * When I load the dll in the 32bit version of R with 
> dyn.load("C:\\Ccodefortransortmodel\\equildistC.dll"), things appear to go 
> well.
>
> * However, in the 64 bit version, I get the message:
> Error in inDL(x, as.logical(local), as.logical(now), ...) :
>unable to load shared object 'C:/Ccodefortransortmodel/equildistC.dll':
>LoadLibrary failure:  %1 is not a valid Win32 application.
>
>
> I have googled the error message. Initially I had omitted "--arch x64" when 
> compiling the file, but even after specifying the architecture, the error 
> persists.
> However, I definitely need to be able to run my code on the 64 version.

Then you should take the 32 bit version out of your path.

Duncan Murdoch

>
>
> Kind regards
> Laurent
>
> 
> [http://www.vito.be/e-maildisclaimer/bsds.png] 
> VITO Disclaimer: http://www.vito.be/e-maildisclaimer
>
>   [[alternative HTML version deleted]]
>
>
>
> This body part will be downloaded on demand.
>


 [http://www.vito.be/e-maildisclaimer/bsds.png]  

VITO Disclaimer: http://www.vito.be/e-maildisclaimer

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


Re: [R] Can anyone help why the errors are coming and rectify it?

2012-09-17 Thread Duncan Murdoch

On 12-09-17 5:47 AM, Sri krishna Devarayalu Balanagu wrote:

Hi Everyone,

Can anyone help why the errors are coming and rectify it?


invalid.ids <- c(1,3,5)
if (length(invalid.ids)==0)   {
 
cat("No Errors found")
}


The lines above are two complete statements.


else  {


The "else" is not allowed to start a statement.  You need to make sure 
the "if" is incomplete when you start the line containing else.  The 
usual style is


if (cond) {
  stmt1

# The if is still incomplete, because the closing brace is missing

} else {

# now the else will be accepted

  stmt2
}

Duncan Murdoch


 
cat(paste(invalid.ids), sep="\n")
   }

Error: unexpected 'else' in "else"
Error: unexpected '}' in "}"

Thank you in advance

Warm Regards
Rayalu
Notice: The information contained in this electronic mail message is intended only 
for the use of the designated recipient. This message is privileged and confidential. 
and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this 
message is not the intended recipient or an agent responsible for delivering it to 
the intended recipient, you are hereby notified that you have received this message 
in error and that any review, dissemination, distribution, or copying of this message 
is strictly prohibited. If you have received this communication in error, please 
notify us immediately by telephone +91-40-6692 and 
destroy any and all copies of this message in your possession (whether hard copies or 
electronically stored copies).

[[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] count NAs per week

2012-09-17 Thread R. Michael Weylandt
On Mon, Sep 17, 2012 at 11:03 AM, Tagmarie  wrote:
> Even though I work with R since a year or so I still struggle with simple
> problems. I hope someone can help me with this. Been trying for days and am
> a little frustrated now.
>
> I have a data frame somewhat like the one bellow:
>
> dattrial<-data.frame(a=c(1,NA,rnorm(4,10)), Week=c(3,3,3,4,4,4))
>
> I want to know how many NAs I have in week 3 and in week 4.
>
>

Thanks for the reproducible example: there are many ways to do this
(aggregate, tapply, ave, etc.) but they are all based on the paradigm
of: break up your data by "Week" --> apply the function "function(x)
sum(is.na(x))" --> recombine. (See, inter alia, the JSS paper on the
plyr package) I'm not at a computer with R right now so this is a
little untested, but one way might be:

with(dattrial, tapply(a, Week, function(x) sum(is.na(x

Cheers,
Michael

>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/count-NAs-per-week-tp4643351.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] Can anyone help why the errors are coming and rectify it?

2012-09-17 Thread Ted Harding
On 17-Sep-2012 09:47:41 Sri krishna Devarayalu Balanagu wrote:
> Hi Everyone,
> Can anyone help why the errors are coming and rectify it?
> 
> invalid.ids <- c(1,3,5)
> if (length(invalid.ids)==0)   {
>  
> cat("No Errors found")
>}
> else  {
>  
> cat(paste(invalid.ids), sep="\n")
>   }
> 
> Error: unexpected 'else' in "else"
> Error: unexpected '}' in "}"
> 
> Thank you in advance
> 
> Warm Regards
> Rayalu

Reformatting your code (for readability) but preserving your
line breaks:

  invalid.ids <- c(1,3,5)
  if (length(invalid.ids)==0) {
cat("No Errors found")
  }
  else {
cat(paste(invalid.ids), sep="\n")
  } }

  Error: unexpected 'else' in "else"
  Error: unexpected '}' in "}"

First:

The first four lines are a completed command, given the way
that R parses input. After encountering the end-of-line at
the fourth line, R considers that it has seen a complete command
and therefore executes it.

 invalid.ids <- c(1,3,5)
  if (length(invalid.ids)==0) {
cat("No Errors found")
  }

Therefore the "else {" on the next line is not interpreted as
if it were part of the preceding "if()" statement, since that
has been considered complete and has been executed. So that
"else" is an "else" with no matching "if". Henc the the first
error message.

Second: if you count the opening "{" and closing "}", you will
see that there is one "}" too many, at the end, hence the second
error message.

The way to avoid the first error message is to put the "else"
on the same line as the close of the "if" statement. Then R will
recognise that it has an incomplete commend, and continue to parse
further input until it has built up a complete command. So you
should write:

  invalid.ids <- c(1,3,5)
  if (length(invalid.ids)==0) {
cat("No Errors found")
  } else {
cat(paste(invalid.ids), sep="\n")
  }

(Note that the extra "}" has been omitted too).

Hoping this helps,
Ted.


-
E-Mail: (Ted Harding) 
Date: 17-Sep-2012  Time: 12:29:46
This message was sent by XFMail

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


Re: [R] possible TZ bug in parseISO8601 - "Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year, : [...]"

2012-09-17 Thread Bit Rocker
I think I've sorted this out now.  Debugging an R program is certainly
quite a feat but I think I'm getting there.  It's worth it for the power
yielded.




On Sun, Sep 16, 2012 at 7:16 PM, Bit Rocker  wrote:

> Just found a typo elsewhere in the code which looks like it's the culprit.
>
> I'm not sure if the report below is still relevant.  Will advise if so.
>
>
> On Sun, Sep 16, 2012 at 6:59 PM, Bit Rocker wrote:
>
>> Hey all,
>>
>> Virgin post to this list - hope I've got it right ;o)
>>
>> I've been learning R intensively the last two weeks and gone from newbie
>> status to *reasonably* comfortable with it.
>>
>> Here's an issue I just cannot solve however as it appears to be some kind
>> of bug in R itself.  But I won't claim that for sure.
>>
>> I have a function as follows:
>>
>>
>> FindHighRow <- function(searchVector, highColumnIndex, thisDate, nextDate)
>> {
>>   dateFilter <- GetDateRangeString(thisDate,nextDate)
>>   filtered <- searchVector[dateFilter]
>>   returnRow <- filtered[which.max(filtered[,highColumnIndex])]
>>   returnRow
>> }
>>
>>
>> Running the lines BY HAND works fine.  But as soon as I call it as a
>> function (passing in *exactly* the same values - and I have definitely
>> checked and double-checked), the second line (filtered <-
>> searchVector[dateFilter]) throws this error .
>>
>> Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year,
>> :
>>
>>   missing value where TRUE/FALSE needed
>>
>> In addition: Warning messages:
>>
>> 1: In as_numeric() : NAs introduced by coercion
>>
>> 2: In as_numeric() : NAs introduced by coercion
>>
>>
>> Checking with debugger() reveals this
>>
>> > debugger()
>>
>> Message:  Error in if (length(c(year, month, day, hour, min, sec)) == 6
>> && c(year,  :
>>
>>   missing value where TRUE/FALSE needed
>>
>> Available environments had calls:
>>
>> 1: FindHighRow(dateTable, theTimeSeries, 2, 3)
>>
>> 2: #4: searchVector[dateFilter]
>>
>> 3: #4: `[.xts`(searchVector, dateFilter)
>>
>> 4: .parseISO8601(ii, .index(x)[1], .index(x)[nr], tz = tz)
>>
>> 5: as.POSIXlt(do.call(lastof, parse.side(intervals[2], intervals[1])))
>>
>> 6: do.call(lastof, parse.side(intervals[2], intervals[1]))
>>
>> 7: function (year = 1970, month = 12, day = 31, hour = 23, min = 59, sec
>> = 59, subsec = 0.9, tz = "")
>>
>> {
>>
>> if (!missing(sec) && sec%%1 != 0)
>>
>> subsec <- 0
>>
>> I then came across this post
>>
>>
>> http://r-forge.r-project.org/tracker/index.php?func=detail&aid=2116&group_id=118&atid=516
>>
>> While running demo/macd.R in the quantstrat package with --vanilla, I got
>> the following error:
>>
>> Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year,
>> :
>> missing value where TRUE/FALSE needed
>>
>> It appears that this error is generated by .parse8061(), because there is
>> no TZ defined. Although there is a test for TZ=='' in the .parse8061()
>> function, that does not seem to work  (didn't look any deeper, sorry
>> ;-) )
>>
>> Setting TZ to eg. "UTC" fixes the problem.
>>
>> I've tried setting TZ (timezone) to both "UTC" and "GMT"
>>
>> > Sys.getenv("TZ")
>>
>> [1] ""
>>
>> > Sys.setenv(TZ='UTC')
>>
>> > Sys.getenv("TZ")
>>
>> [1] "UTC"
>>
>> > Sys.getenv("TZ") %in% c("", "GMT", "UTC")
>>
>> [1] TRUE
>>
>> But running my function again I still get the same error
>>
>> > FindHighRow(filteredDates,theTimeSeries,2,3)
>>
>> Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year,
>> :
>>
>>   missing value where TRUE/FALSE needed
>>
>> In addition: Warning messages:
>>
>> 1: In as_numeric() : NAs introduced by coercion
>>
>> 2: In as_numeric() : NAs introduced by coercion
>>
>> > FindHighRow
>>
>> function(searchVector, highColumnIndex, thisDate, nextDate)
>>
>> {
>>
>>   dateFilter <- GetDateRangeString(thisDate,nextDate)
>>
>>   filtered <- searchVector[dateFilter]
>>
>>   returnRow <- filtered[which.max(filtered[,highColumnIndex])]
>>
>>   returnRow
>>
>> }
>>
>> > dateFilter <- GetDateRangeString(thisDate,nextDate)
>>
>> > dateFilter
>>
>> [1] "2007-10-01::2008-01-01"
>>
>> > filtered <- searchVector[dateFilter]
>>
>> > returnRow <- filtered[which.max(filtered[,highColumnIndex])]
>>
>> > head(returnRow,10)
>>
>>  Open  High Low   Close
>>
>> 2007-10-10   1564.72   1576.09  1546.72   1554.41
>>
>>
>> So as I hope you can see, it works by hand but not within a function.
>>
>> That's why I think it's a bug.
>>
>>
>> Just for replicability (I hope)
>>
>> GetDateRangeString <- function(thisDate,nextDate)
>> {
>>   GetDateRangeString <-
>> paste(EnsureDate(thisDate),"::",EnsureDate(nextDate),sep="")
>> }
>>
>> EnsureDate <- function(maybeWrongFormat)
>> {
>>   as.POSIXct(strptime(maybeWrongFormat, "%Y-%m-%d"))
>> }
>>
>>
>>
>> And theTimeSeries is
>>
>> theTimeSeries <- getSymbols(tckr, from="2000-01-01",
>> to="2013-01-01",auto.assign=FALSE)
>>
>>
>> I'm too much of a newbie to suggest how to fix this (or what else it
>> might be) so I thou

Re: [R] Count based on 2 conditions [Beginner Question]

2012-09-17 Thread Stephen Politzer-Ahles
Most of your counting needs can be handled elegantly with the xtabs()
function (cross-tabulation). This'll work a lot faster than an iterative
method. For your data I would suggest something like this:

# Create a column indicating whether or not the value in Col2 is above 5
dataset$Col2greaterthan5 <- dataset$Col2 > 5
# Cross-tabulate
xtabs(~ Col1 + Col2greaterthan5, dataset)



> Message: 2
> Date: Sun, 16 Sep 2012 03:41:45 -0700 (PDT)
> From: SirRon 
> To: r-help@r-project.org
> Subject: [R] Count based on 2 conditions [Beginner Question]
> Message-ID: <1347792105574-4643282.p...@n4.nabble.com>
> Content-Type: text/plain; charset=us-ascii
>
> Hello,
> I'm working with a dataset that has 2 columns and 1000 entries. Column 1
> has
> either value 0 or 1, column 2 has values between 0 and 10. I would like to
> count how often Column 1 has the value 1, while Column 2 has a value
> greater
> 5.
>
> This is my attempt, which works but doesn't seem to be very efficient,
> especially when testing different values or columns.
>
> count=0
> for (i in 1:1000) { if(dataset[i,2]>5 && ind[i,1]==1) { count=count+1}}
>
> I'm looking for a more efficient/elegant way to do this!
>
> Thanks!
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Count-based-on-2-conditions-Beginner-Question-tp4643282.html
> Sent from the R help mailing list archive at Nabble.com.
>

[[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] download truncating large files

2012-09-17 Thread jim holtman
Try downloading the zip file using the browser interface to see if it
might be something with your proxy.  Do this outside of R to see if
you have the same problem.  After that, you can just install from a
local zip file.

On Mon, Sep 17, 2012 at 5:21 AM, Ian Shannon
 wrote:
> Hi there,
>
> I have had a problem with loading the package XLConnectJars_0.2-0.zip from 
> the CRAN mirrors. The problem occurs when executing
> utils:::menuInstallPkgs()
> I have traced the problem down to the "download" internal command.  It 
> appears that files over approx 15 MB are being truncated.  The exact point of 
> truncation varies slightly but the truncation is on a 4096-byte boundary.
>
> I am running =>
>
>
> R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
> Copyright (C) 2012 The R Foundation for Statistical Computing
> ISBN 3-900051-07-0
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> I have also run the code using the -- vanilla  start-up parameter with no 
> change in outcome.
>
> I am using  "internet2"  to get past our proxy server.  I have isolated the 
> problem using the following script
> derived from a code fragment called by the menuInstallPkgs() function.
>
> options(timeout = 120)   makes no difference because the failure occurs 
> before the timeout of 60 (or 120) seconds elapses.
>
>
> ## sample R code sequence to reproduce error
> setInternet2(TRUE);
> url <- "http://cran.csiro.au/bin/windows/contrib/2.15/";;
> dir <- "U:\\";
>
> ## This download being reasonable small works OK
> file <- "XLConnect_0.2-1.zip";
> status <- .Internal(download(paste0(url, file), paste0(dir, file), 
> quiet=FALSE, mode="wb", cacheOK=FALSE));
> cat(paste("the value of status for",  file, "is", status, "\n\n"));
>
>
> ## This big download fails - a progress indicator quickly progresses to 99% 
> and stops
> file <- "XLConnectJars_0.2-0.zip";
> status <- .Internal(download(paste0(url, file), paste0(dir, file), 
> quiet=FALSE, mode="wb", cacheOK=FALSE));
> cat(paste("the value of status for",  file, "is", status, "\n\n"));
>
>
>
> This produces the following output -
>
>
> trying URL 'http://cran.csiro.au/bin/windows/contrib/2.15/XLConnect_0.2-1.zip'
> Content type 'application/zip' length 1358587 bytes (1.3 Mb)
> opened URL
> downloaded 1.3 Mb
>
> the value of status for XLConnect_0.2-1.zip is 0
>
> trying URL 
> 'http://cran.csiro.au/bin/windows/contrib/2.15/XLConnectJars_0.2-0.zip'
> Content type 'application/zip' length 16486857 bytes (15.7 Mb)
> opened URL
> downloaded 15.6 Mb
>
> the value of status for XLConnectJars_0.2-0.zip is 0
>
> Warning message:
> In eval(expr, envir, enclos) :
>   downloaded length 16355328 != reported length 16486857
>>
>
>
>
> Any suggestions on what is needed to get this going?
>
> Thanks,
>
>
> Ian
> Ian Shannon
> Landscape Modelling & Decision Support
> Scientific Services
> Office of Environment and Heritage
> Department of Premier and Cabinet
> PO Box A290
> Sydney South
> NSW  1232
> +61 2 99 955 490
> Ian dot Shannon at Environment dot nsw dot gov dot au
> --
> This email is intended for the addressee(s) named and may contain 
> confidential and/or privileged information.
> If you are not the intended recipient, please notify the sender and then 
> delete it immediately.
> Any views expressed in this email are those of the individual sender except 
> where the sender expressly and with authority states them to be the views of 
> the Office of Environment and Heritage, NSW Department of Premier and Cabinet.
>
> PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS EMAIL
>
> [[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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] Using paste to create and evaluate a variable expression

2012-09-17 Thread Jean V Adams
Bryan,

Try this.

char <- paste("X", 1:2, sep="", collapse="+")
eval(parse(text=char))

Jean


Bryan Keller  wrote on 09/16/2012 11:04:19 PM:
> 
> Is it possible to use "paste" to write out an expression and evaluate 
it?
> Suppose I want to add two vectors X1 and X2, defined as follows:
> 
> X1 <- 1:6
> X2 <- 6:1
> 
> If I write the following it looks like what I want but is a character:
> noquote(paste(paste("X", 1, sep = ""), paste("X", 2, sep = ""), sep = 
"+"))
> 
> Is there a way to tell R that I want to evaluate the text, not just 
print
> it out as a character?
> 
> Bryan

[[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] Can anyone help why the errors are coming and rectify it?

2012-09-17 Thread R. Michael Weylandt
And now it is easy to see why we should all the one true brace style ;-)

Michael

On Mon, Sep 17, 2012 at 12:29 PM, Ted Harding  wrote:
> On 17-Sep-2012 09:47:41 Sri krishna Devarayalu Balanagu wrote:
>> Hi Everyone,
>> Can anyone help why the errors are coming and rectify it?
>>
>> invalid.ids <- c(1,3,5)
>> if (length(invalid.ids)==0)   {
>>
>> cat("No Errors found")
>>}
>> else  {
>>
>> cat(paste(invalid.ids), sep="\n")
>>   }
>>
>> Error: unexpected 'else' in "else"
>> Error: unexpected '}' in "}"
>>
>> Thank you in advance
>>
>> Warm Regards
>> Rayalu
>
> Reformatting your code (for readability) but preserving your
> line breaks:
>
>   invalid.ids <- c(1,3,5)
>   if (length(invalid.ids)==0) {
> cat("No Errors found")
>   }
>   else {
> cat(paste(invalid.ids), sep="\n")
>   } }
>
>   Error: unexpected 'else' in "else"
>   Error: unexpected '}' in "}"
>
> First:
>
> The first four lines are a completed command, given the way
> that R parses input. After encountering the end-of-line at
> the fourth line, R considers that it has seen a complete command
> and therefore executes it.
>
>  invalid.ids <- c(1,3,5)
>   if (length(invalid.ids)==0) {
> cat("No Errors found")
>   }
>
> Therefore the "else {" on the next line is not interpreted as
> if it were part of the preceding "if()" statement, since that
> has been considered complete and has been executed. So that
> "else" is an "else" with no matching "if". Henc the the first
> error message.
>
> Second: if you count the opening "{" and closing "}", you will
> see that there is one "}" too many, at the end, hence the second
> error message.
>
> The way to avoid the first error message is to put the "else"
> on the same line as the close of the "if" statement. Then R will
> recognise that it has an incomplete commend, and continue to parse
> further input until it has built up a complete command. So you
> should write:
>
>   invalid.ids <- c(1,3,5)
>   if (length(invalid.ids)==0) {
> cat("No Errors found")
>   } else {
> cat(paste(invalid.ids), sep="\n")
>   }
>
> (Note that the extra "}" has been omitted too).
>
> Hoping this helps,
> Ted.
>
>
> -
> E-Mail: (Ted Harding) 
> Date: 17-Sep-2012  Time: 12:29:46
> This message was sent by XFMail
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Server R

2012-09-17 Thread R. Michael Weylandt
On Sun, Sep 16, 2012 at 9:42 PM, Bazman76  wrote:
> Hi there,
>
> I used the command
>
> sudo apt-get install r-base
>
> to install R on an EC2 server as shown below:
>
> http://www.r-bloggers.com/ec2-micro-instance-of-rstudio/
>
> It works but the version of R installed is:
>
>  R.version.string
> [1] "R version 2.12.1 (2010-12-16)"
>
> I want to the latest version with package parallel included.
>
> How can I change the commend to ensure the latest version of R is installed?
>
>

I presume EC2 runs Ubuntu:

http://cran.r-project.org/bin/linux/ubuntu/README

Cheers,
Michael


>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Server-R-tp4643319.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] Using paste to create and evaluate a variable expression

2012-09-17 Thread Bryan Keller
This is perfect, thanks!

On Mon, Sep 17, 2012 at 7:16 AM, arun  wrote:

> Hi,
> Try this:
> expr1<-parse(text=paste(paste0("X",1:2),collapse="+"))
>  eval(expr1)
> #[1] 7 7 7 7 7 7
> A.K.
>
>
>
>
> - Original Message -
> From: Bryan Keller 
> To: r-help@r-project.org
> Cc:
> Sent: Monday, September 17, 2012 12:04 AM
> Subject: [R] Using paste to create and evaluate a variable expression
>
> Is it possible to use "paste" to write out an expression and evaluate it?
> Suppose I want to add two vectors X1 and X2, defined as follows:
>
> X1 <- 1:6
> X2 <- 6:1
>
> If I write the following it looks like what I want but is a character:
> noquote(paste(paste("X", 1, sep = ""), paste("X", 2, sep = ""), sep = "+"))
>
> Is there a way to tell R that I want to evaluate the text, not just print
> it out as a character?
>
> Bryan
>
> [[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.
>
>


-- 
Bryan Keller
(608) 658 - 4292

[[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] Correlation between random effects in the package coxme

2012-09-17 Thread Terry Therneau



On 09/14/2012 05:00 AM, r-help-requ...@r-project.org wrote:

Hello,

Why the correlation between the random effects is negative?
library(coxme)
rats1<- coxme(Surv(time, status) ~ (1|litter), rats)
random.effects(rats1)[[1]] #one value for each of the 50 litters
print(rats1)

rats2<- lmekin(time ~ (1|litter), rats)
fixed.effects(rats2)
random.effects(rats2)[[1]] #one value for each of the 50 litters
print(rats2)

cor(random.effects(rats1)[[1]],random.effects(rats2)[[1]])

Thanks


Because coxph models the death rate, so large coefficients indicate bad news, and lme is 
modeling the surival time where large coefficients are good news.


Terry T

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


Re: [R] [newbie] aggregating table() results and simplifying code with loop

2012-09-17 Thread John Kane
Comments in-line below.

Sorry to be so long getting back to you but sleep intervened. 

> -Original Message-
> From: ridav...@gmail.com
> Sent: Sun, 16 Sep 2012 21:24:15 +0200
> To: jrkrid...@inbox.com
> Subject: Re: [R] [newbie] aggregating table() results and simplifying
> code with loop
> 
> Thank you John,
> 
> you are giving me two precious tips (in addition, well explained!):
> 1. to use the package plyr (I didn't know it before, but it seems to
> make the deal!)
> 2. a smart and promising way to use it
> 
> I can finally plot the partial results, to have a first glance and
> compare to them
> 
> ==
> 
> # once the sequences for a given crop have been assembled in a
> dataframe (e.g., maizedata)
> library(latticeExtra) # load the package for "improved" graphics
> dotplot(mzcount$crop_pattern) # to plot the occurrence of all the
> retrieved sequences
> 
> #once the target pattern have been subset (e.g., m51)
> dotplot(m51$WS ~ m51$count) # to plot the occurrence of the target
> pattern(s) per watershed

Ah, so that's what WS stands for!  Do you have an abstract or short summary of 
what you are doing in English or French?  My Itallian is limited to about 3 
words or what I can guess from French/Latin.

I think that you are misunderstanding what is happening in m51. It is just 
summarizing the total counts across those two conditions.  I think either I 
made a logic error or was not understanding what was needed. In any case the 
dotplot is not plotting the actual occurances but the number of times the 
crop_pattern was found.  The count is the actual number of occurances per WS 
per crop_pattern


Have a look at my new effort.  it is still ugly but I think it more accurately 
supplies some of what you want.

Two caveats : 1.  This is still very rough and an better programer may have a 
better approach.
2. I used the package ggplot2 to do the graphs. One more thing to learn but I 
am not used to lattice and I am used to ggplot2. Rather than spend a lot of 
time with lattice or 
2. The last faceted plots are not intended to be of real use, just my quick 
look to see if anything looked like I expected. A bit of thinking probably 
would give somethimg much better






> ==
> 
> This help me retrieving all the possible patterns for the different
> land covers. Hence, you made me able to improve the subset of
> patterns.
> 
> Tomorrow morning I'm going to test the tips for all the land covers
> for all the 5years time-periods. Even if still labour-intensive, the
> solution you propose it's surely a steady improvement.

> Now only the second question remains: is there a way "to clean" this
> approach?... or probably not ?...

Yes I suspect that there are lots of ways to 'clean' the process and automate 
it so that it would apply to all three data sets quite easily.  Some I think I 
can help with and some you may need other people's  help.

For example, once we have a working model to handle one or two conditions It 
should be relatively easy to use an apply() or a loop to handle all of them and 
so on.. 

Well, I'm off to work now so I probably won't be able to get back to much 
before late evening my time ( probably after you are asleep) I think I'm 6 
hours ahead of you.

##===Revised approach
# load the various packages (plyr, latticeExtra, ggplot2, reshape2)
library(plyr)
library(latticeExtra)
library(ggplot2)
library(reshape2)

# sample data
T80<- read.csv("/home/john/rdata/sample.csv",  header = TRUE, sep = ";")
# Davide's actual read statement
# T80<-read.table(file="C:/sample.txt", header=T, sep=";")

# Looking for Maize
pattern  <-  c("2Ma", "2Ma","2Ma", "2Ma","2Ma")

# one row examples to see that is happening
T80[1,3:7]
T80[1, 3:7] == pattern

T80[405, 3:7]
T80[405, 3:7] == pattern

T80[55, 3:7] == pattern

# now we apply the patterns to the entire data set.
pp1  <-  T80[, 3:7] == pattern

# paste the TRUEs and FALSEs together to form a single variable
concatdat  <-  paste(pp1[, 1], pp1[, 2], pp1[, 3], pp1[, 4],pp1[,5] ,  sep = 
"+")

# Assmble new data frame. 
maizedata  <-  data.frame(T80$WS, concatdat)
names(maizedata)  <-  c("WS", "crop_pattern")
str(maizedata)

maizedata$crop_pattern  <-  as.character(maizedata$crop_pattern)

pattern_count  <-  ddply(maizedata, .(crop_pattern), summarize, npattern = 
length(crop_pattern))
str(pattern_count)
head(pattern_count);  dim(pattern_count) #  quick look at data.frame and  
its size.

# FALSE+FALSE+FALSE+FALSE+FALSE accounts for 21,493 values.

 
which(pattern_count$npattern == max(pattern_count$npattern))  # this does the 
same as looking at the data
  

Re: [R] Can anyone help why the errors are coming and rectify it?

2012-09-17 Thread Jessica Streicher
Now i know why using else never worked for me - really, i'd consider this more 
of a bug than a feature of the language ;)

On 17.09.2012, at 14:35, R. Michael Weylandt wrote:

> And now it is easy to see why we should all the one true brace style ;-)
> 
> Michael
> 
> On Mon, Sep 17, 2012 at 12:29 PM, Ted Harding  
> wrote:
>> On 17-Sep-2012 09:47:41 Sri krishna Devarayalu Balanagu wrote:
>>> Hi Everyone,
>>> Can anyone help why the errors are coming and rectify it?
>>> 
>>> invalid.ids <- c(1,3,5)
>>> if (length(invalid.ids)==0)   {
>>> 
>>> cat("No Errors found")
>>>   }
>>> else  {
>>> 
>>> cat(paste(invalid.ids), sep="\n")
>>>  }
>>> 
>>> Error: unexpected 'else' in "else"
>>> Error: unexpected '}' in "}"
>>> 
>>> Thank you in advance
>>> 
>>> Warm Regards
>>> Rayalu
>> 
>> Reformatting your code (for readability) but preserving your
>> line breaks:
>> 
>>  invalid.ids <- c(1,3,5)
>>  if (length(invalid.ids)==0) {
>>cat("No Errors found")
>>  }
>>  else {
>>cat(paste(invalid.ids), sep="\n")
>>  } }
>> 
>>  Error: unexpected 'else' in "else"
>>  Error: unexpected '}' in "}"
>> 
>> First:
>> 
>> The first four lines are a completed command, given the way
>> that R parses input. After encountering the end-of-line at
>> the fourth line, R considers that it has seen a complete command
>> and therefore executes it.
>> 
>> invalid.ids <- c(1,3,5)
>>  if (length(invalid.ids)==0) {
>>cat("No Errors found")
>>  }
>> 
>> Therefore the "else {" on the next line is not interpreted as
>> if it were part of the preceding "if()" statement, since that
>> has been considered complete and has been executed. So that
>> "else" is an "else" with no matching "if". Henc the the first
>> error message.
>> 
>> Second: if you count the opening "{" and closing "}", you will
>> see that there is one "}" too many, at the end, hence the second
>> error message.
>> 
>> The way to avoid the first error message is to put the "else"
>> on the same line as the close of the "if" statement. Then R will
>> recognise that it has an incomplete commend, and continue to parse
>> further input until it has built up a complete command. So you
>> should write:
>> 
>>  invalid.ids <- c(1,3,5)
>>  if (length(invalid.ids)==0) {
>>cat("No Errors found")
>>  } else {
>>cat(paste(invalid.ids), sep="\n")
>>  }
>> 
>> (Note that the extra "}" has been omitted too).
>> 
>> Hoping this helps,
>> Ted.
>> 
>> 
>> -
>> E-Mail: (Ted Harding) 
>> Date: 17-Sep-2012  Time: 12:29:46
>> This message was sent by XFMail
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Can anyone help why the errors are coming and rectify it?

2012-09-17 Thread R. Michael Weylandt
On Mon, Sep 17, 2012 at 2:54 PM, Jessica Streicher
 wrote:
> Now i know why using else never worked for me - really, i'd consider this 
> more of a bug than a feature of the language ;)

If it makes you feel any better (I can't imagine it would), javascript
has the same 'feature' for much the same reason.  Python doesn't, but
then again, they don't have braces so the parsing is easier (i.e.,
there exist universalizable rules)

Michael

>
> On 17.09.2012, at 14:35, R. Michael Weylandt wrote:
>
>> And now it is easy to see why we should all the one true brace style ;-)
>>
>> Michael

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

2012-09-17 Thread William Dunlap
> with(dattrial, table(A_is_missing=is.na(a), Week))
Week
A_is_missing 3 4
   FALSE 2 3
   TRUE  1 0
> with(dattrial, table(A_is_missing=is.na(a), Week))["TRUE", ] # extract the 
> missing="TRUE" row, note quotes
3 4 
1 0

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of Tagmarie
> Sent: Monday, September 17, 2012 3:03 AM
> To: r-help@r-project.org
> Subject: [R] count NAs per week
> 
> Even though I work with R since a year or so I still struggle with simple
> problems. I hope someone can help me with this. Been trying for days and am
> a little frustrated now.
> 
> I have a data frame somewhat like the one bellow:
> 
> dattrial<-data.frame(a=c(1,NA,rnorm(4,10)), Week=c(3,3,3,4,4,4))
> 
> I want to know how many NAs I have in week 3 and in week 4.
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/count-NAs-per-week-
> tp4643351.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] [newbie] aggregating table() results and simplifying code with loop

2012-09-17 Thread Rui Barradas

Hello,

Now I believe I've got it. (So-so believe.)
ddply is a good idea, in my first post I was using xtabs to the same 
effect, but ddply makes it a lot easier.
I had made a big mistake, though. I thought that only sequences of FALSE 
were valid, hence rle(). In a follow-up post, Davide listed all 
combinations of T/F that matter. The code below uses them to create a df 
of cases to count with ddply. The creation is done by merge, on the T/F 
columns (function f1) and the rest is just to apply to 6 periods of 5 
years each, after applying to covers, after applying to years of crop type.
Sounds confusing, and it probably is but I've separated all of it in 
small functions.
Each of the functions is in fact very simple, and all one needs is to 
remember that the inner most function is reached after a series of 
*apply statements, doing one thing at a time.



#--
# data.frame of target sequences of T/F per crop type and years
# (from an earlier post)

wanted <-
structure(list(V2 = c(TRUE, FALSE, TRUE, FALSE, FALSE, TRUE,
FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE), V3 = c(FALSE, FALSE, FALSE, TRUE, FALSE,
FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE,
FALSE, TRUE, TRUE, TRUE), V4 = c(FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, FALSE), V5 = c(FALSE, FALSE, FALSE, FALSE,
TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE,
FALSE, TRUE, FALSE, TRUE, TRUE), V6 = c(FALSE, TRUE, TRUE, FALSE,
FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE,
TRUE, TRUE, FALSE, FALSE, TRUE), V7 = c(" return", " return",
" return", " return", " return", " return", " return", " return",
" return", " return", " mono-succession", " mono-succession",
" mono-succession", " mono-succession", " mono-succession", " mono-succession",
" mono-succession", " mono-succession", " crops"), V8 = c(5L,
5L, 4L, 4L, 4L, 3L, 3L, 3L, 2L, 2L, 5L, 4L, 4L, 3L, 3L, 3L, 3L,
3L, 2L)), .Names = c("V2", "V3", "V4", "V5", "V6", "V7", "V8"
), row.names = c(NA, -19L), class = "data.frame")

want <- split(wanted, wanted$V7)

#
# The functions go from f5 down to f1 (f5 calls f4, f4 calls f3, etc.)
#
f1 <- function(DF, Mat, currcols, WS){
mcols <- names(T80[, ycols])[currcols]  # names for 'merge'
names(DF)[1:5] <- mcols
m <- merge(DF, data.frame(Mat[, mcols], WS = WS))
ddply(m, .(WS), summarize, length(V8))
}
f2 <- function(w, tf, WS){
l1 <- lapply(yrs, function(yy) t(f1(w, tf, yy, WS)))
l2 <- lapply(l1, function(x){
nms <- as.character(x["WS",])
resline[ nms ] <- x[2, ]
resline})
res <- do.call(rbind, l2)
data.frame(res)
}
f3 <- function(Cover, w){
tf <- T80[, ycols] == Cover
inx <- as.vector(apply(tf, 1, function(.x) any(.x)))
tf <- tf[inx, ]
WS <- T80$WS[inx]
# Special care with empty sets
if(sum(tf) > 0){
res <- f2(w, tf, WS)
na <- as.vector(apply(res, 1, function(.x) all(is.na(.x
res <- res[!na, ]
if(!is.null(res) && nrow(res) > 0){
res$Cover <- Cover
res$Period <- (1:6)[!na]
}else res <- NULL
}else res <- NULL
res
}
f4 <- function(w){
res <- do.call(rbind, lapply(covers, f3, w))
# Special care with empty sets
if(!is.null(nrow(res)) && nrow(res) > 0){
res <- data.frame(res)
res$Years <- w$V8[1]
}else res <- NULL
res
}
f5 <- function(w){
sp <- split(w, w$V8)
res <- do.call( rbind, lapply(sp, f4) )
res <- data.frame(res)
res
}

T80 <- read.table("sample.txt", header = TRUE, sep = ";")

ycols <- grep("y", names(T80))
ws <- unique(T80$WS)
covers <- as.character(unique(unlist(T80[ycols])))
yrs <- lapply(0:5, `+`, 1:5)
resline <- rep(NA, length(ws))
names(resline) <- ws

result <- lapply(want, f5)


(Ok, maybe two or three things at a time.)

I hope this is it!
Have fun.

Rui Barradas

Em 17-09-2012 14:19, John Kane escreveu:

Comments in-line below.

Sorry to be so long getting back to you but sleep intervened.


-Original Message-
From: ridav...@gmail.com
Sent: Sun, 16 Sep 2012 21:24:15 +0200
To: jrkrid...@inbox.com
Subject: Re: [R] [newbie] aggregating table() results and simplifying
code with loop

Thank you John,

you are giving me two precious tips (in addition, well explained!):
1. to use the package plyr (I didn't know it before, but it seems to
make the deal!)
2. a smart and promising way to use it

I can finally plot the partial results, to have a first glance and
compare to them

==

# once the s

Re: [R] Using paste to create and evaluate a variable expression

2012-09-17 Thread arun
Hi,
Try this:
expr1<-parse(text=paste(paste0("X",1:2),collapse="+"))
 eval(expr1)
#[1] 7 7 7 7 7 7
A.K.




- Original Message -
From: Bryan Keller 
To: r-help@r-project.org
Cc: 
Sent: Monday, September 17, 2012 12:04 AM
Subject: [R] Using paste to create and evaluate a variable expression

Is it possible to use "paste" to write out an expression and evaluate it?
Suppose I want to add two vectors X1 and X2, defined as follows:

X1 <- 1:6
X2 <- 6:1

If I write the following it looks like what I want but is a character:
noquote(paste(paste("X", 1, sep = ""), paste("X", 2, sep = ""), sep = "+"))

Is there a way to tell R that I want to evaluate the text, not just print
it out as a character?

Bryan

    [[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] I want to send the vector a into the Object A.......

2012-09-17 Thread Sri krishna Devarayalu Balanagu
a=c(1,2,3)
b=c(23, 24, 25)
x=c("a", "b")
#if (length(x[1]) == 0) {cat("x[1] is having 3 elements")}

Suppose I want to send the vector a into the Object A,
um getting only "a" as the ouput for Object A but not getting required output 
as the vector with the elements 1, 2, 3 with  the following code

A<- x[1]

How to code it?
Can anyone help?
Notice: The information contained in this electronic mail message is intended 
only for the use of the designated recipient. This message is privileged and 
confidential. and the property of GVK BIO or its affiliates and subsidiaries. 
If the reader of this message is not the intended recipient or an agent 
responsible for delivering it to the intended recipient, you are hereby 
notified that you have received this message in error and that any review, 
dissemination, distribution, or copying of this message is strictly prohibited. 
If you have received this communication in error, please notify us immediately 
by telephone +91-40-6692 and destroy any and all 
copies of this message in your possession (whether hard copies or 
electronically stored copies).

[[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] count NAs per week

2012-09-17 Thread arun
Hi,
Try this:
dattrial<-data.frame(a=c(1,NA,rnorm(4,10)), Week=c(3,3,3,4,4,4))
 aggregate(dattrial$a,list(dattrial$Week),function(x) sum(is.na(x)))
#  Group.1 x
#1   3 1
#2   4 0
#or
 ddply(dattrial,.(Week),summarize, sum(is.na(a))) 
#  Week ..1
#1    3   1
#2    4   0

#or
list1<-split(dattrial,dattrial$Week)
 unlist(lapply(lapply(list1,`[`, 1),function(x) sum(is.na(x
#3 4 
#1 0 
A.K. 





- Original Message -
From: Tagmarie 
To: r-help@r-project.org
Cc: 
Sent: Monday, September 17, 2012 6:03 AM
Subject: [R] count NAs per week

Even though I work with R since a year or so I still struggle with simple
problems. I hope someone can help me with this. Been trying for days and am
a little frustrated now. 

I have a data frame somewhat like the one bellow:

dattrial<-data.frame(a=c(1,NA,rnorm(4,10)), Week=c(3,3,3,4,4,4))

I want to know how many NAs I have in week 3 and in week 4. 



--
View this message in context: 
http://r.789695.n4.nabble.com/count-NAs-per-week-tp4643351.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] Boxplot lattice vs standard graphics

2012-09-17 Thread maxbre
here it is, I think (I hope)  I'm getting a little closer with this, but
still there is something  to sort out...
 
error using packet 1
unused argument(s)  (coef =1.5, do.out=TRUE)

by reading the help for panel.bwplot at the argument "stats" it says: "the
function must accept arguments coef and do.out even if they do not use them
(a ... argument is good enough). "
I'm not sure how to couple with this...

any help for this ?

thanks


## start code


mystats <- function(x){
  out <- boxplot.stats(10^x)
  out$stats <- log10(out$stats)
  out$conf <- log10(out$conf) ## Omit if you don't want notches
  out$out <- log10(out$out)
  out$coef<-1.5 #??
  out$do.out<-"TRUE" #??
  out ## With the boxplot statistics converted to the log10 scale
}

bwplot(conc~site, data=test,
   scales=list(y=list(log=10)),
   panel= function(x,y){
 panel.bwplot(x,y,stats=mystats)
   } 
   )


## end code



--
View this message in context: 
http://r.789695.n4.nabble.com/Boxplot-lattice-vs-standard-graphics-tp4643121p4643357.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] count NAs per week

2012-09-17 Thread Tagmarie
Thank you Michael, that worked perfectly! 

Now I wonder, if it is possible to break my data further apart and put it
together again. 
Assume I include a column for an ID in the data frame like this: 

dattrial2<-data.frame(a=c(1,NA,NA,NA,2,3), Week=c(3,3,3,4,4,4),
AnimalID=c("Ernie","Bert", "Ernie", "Bert", "Bert", "Ernie"))

Is it possible to get two different lists in the output, one for Ernie and
one for Bert? Or do I have to do it seperately for each animal?

Thank you again! I learn a lot by doing and by people helping me. Thank you
for the hint with the paper. 





--
View this message in context: 
http://r.789695.n4.nabble.com/count-NAs-per-week-tp4643351p4643371.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] Sweave problem after R update version

2012-09-17 Thread jeff harring
I have been having the same problem. It appears to be linked to setting the
working directory.

<<>>=
setwd("c:...")
@

Then the error arrives.

Any suggestions?





--
View this message in context: 
http://r.789695.n4.nabble.com/Sweave-problem-after-R-update-version-tp4566044p4643363.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] Sweave problem after R update version

2012-09-17 Thread jeff harring
Is there a way to set the echo to be false as the code that was presented (by
the way it worked well) shows up in the document?

Thanks for any help here.





--
View this message in context: 
http://r.789695.n4.nabble.com/Sweave-problem-after-R-update-version-tp4566044p4643366.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] Problem with Stationary Bootstrap

2012-09-17 Thread Hock Ann Lim
Dear R experts,
 
I'm running the following stationary bootstrap programming to find the 
parameters estimate of a linear model:  
 
X<-runif(10,0,10)
Y<-2+3*X
a<-data.frame(X,Y)
coef<-function(fit){
  fit <- lm(Y~X,data=a)
   return(coef(fit))
}
 result<- tsboot(a,statistic=coef(fit),R = 10,n.sim = NROW(a),sim = 
"geom",orig.t = TRUE)
 
Unfortunately, I got this error message from R:
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Can someone tells me what's wrong in the programming.
 
Thank you.
 
Regards,
Lim Hock Ann

[[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] I want to send the vector a into the Object A.......

2012-09-17 Thread Heramb Gadgil
 A<- get("a")

This will work fine

Best,
Heramb

On Mon, Sep 17, 2012 at 5:43 PM, Sri krishna Devarayalu Balanagu <
balanagudevaray...@gvkbio.com> wrote:

> a=c(1,2,3)
> b=c(23, 24, 25)
> x=c("a", "b")
> #if (length(x[1]) == 0) {cat("x[1] is having 3 elements")}
>
> Suppose I want to send the vector a into the Object A,
> um getting only "a" as the ouput for Object A but not getting required
> output as the vector with the elements 1, 2, 3 with  the following code
>
> A<- x[1]
>
> How to code it?
> Can anyone help?
> Notice: The information contained in this electronic mail message is
> intended only for the use of the designated recipient. This message is
> privileged and confidential. and the property of GVK BIO or its affiliates
> and subsidiaries. If the reader of this message is not the intended
> recipient or an agent responsible for delivering it to the intended
> recipient, you are hereby notified that you have received this message in
> error and that any review, dissemination, distribution, or copying of this
> message is strictly prohibited. If you have received this communication in
> error, please notify us immediately by telephone
> +91-40-6692 and destroy any and all copies of this
> message in your possession (whether hard copies or electronically stored
> copies).
>
> [[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] Possible Improvement of the R code

2012-09-17 Thread William Dunlap
Unlike C or C++, subscripting vector or matrix is not almost free.
Also, subscripting a matrix tends to make more time than subscripting a
vector so it can help to pull out the previous row of params once
per iteration, use vector subscripting on the that row to build the new
row, and then insert the new row back into params with one matrix
subscripting call:
f5 <- function(param) {
for(i in 2:11) {
# do matrix subscripting only twice per iteration
prev <- param[i-1, ]
param[i,] <- c(
prev[3] + prev[4]/2,
prev[4]/2 + prev[5],
prev[1] * (prev[3] + prev[4]/2),
prev[1] * (prev[4]/2 + prev[5]) + prev[2] * (prev[3] + prev[4]/2),
prev[2] * (prev[4]/2 + prev[5]))
}
param
}
You can also do as much as possible to not repeat any subscripting or
sums:
f6 <- function(param) {
for(i in 2:11) {
# do any subscripting only twice/iteration and
# repeated sums only once/iteration.
prev <- param[i-1, ]
p1 <- prev[1]
p2 <- prev[2]
p42 <- prev[4]/2
p342 <- prev[3] + p42
p425 <- p42 + prev[5]
param[i,] <- c(
p342,
p425,
p1 * p342,
p1 * p425 + p2 * p342,
p2 * p425)
}
param
}

I was curious about how much the compiler package could replace 
hand-optimization
so I timed these with and without compiling.  (f1 and f3 are Berend's f1 and 
f3; I renamed
his f2 and f4 to f1c and f3c to indicate they were the compiled versions.)
> funs <- list(f1=f1, f1c=f1c, f3=f3, f3c=f3c, f5=f5, f5c=f5c, f6=f6, f6c=f6c)
> z <- vapply(funs, function(f)system.time(for(i in 1:1)f(param))[1:3], 
> numeric(3))
> z
f1  f1c   f3  f3c   f5  f5c   f6 f6c
user.self 5.03 2.82 3.74 1.89 2.73 1.78 1.54 0.9
sys.self  0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.0
elapsed   5.03 2.83 3.75 1.90 2.76 1.77 1.54 0.9
> matrix(z["user.self", ], byrow=TRUE, ncol=2, 
> dimnames=list(c("f1","f3","f5","f6"), c("raw","compiled")))
raw compiled
f1 5.03 2.82
f3 3.74 1.89
f5 2.73 1.78
f6 1.54 0.90
It looks like both hand- and machine-optimization help quite a bit here.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of Berend Hasselman
> Sent: Sunday, September 16, 2012 9:28 PM
> To: li li
> Cc: r-help
> Subject: Re: [R] Possible Improvement of the R code
> 
> 
> On 17-09-2012, at 00:51, li li wrote:
> 
> > Dear all,
> >   In the following code, I was trying to compute each row of the "param"
> > iteratively based
> > on the first row.
> >   This likely is not the best way. Can anyone suggest a simpler way to
> > improve the code.
> >   Thanks a lot!
> > Hannah
> >
> >
> > param <- matrix(0, 11, 5)
> >
> > colnames(param) <- c("p", "q", "r", "2s", "t")
> >
> > param[1,] <- c(0.5, 0.5, 0.4, 0.5, 0.1)
> >
> > for (i in 2:11){
> >
> > param[i,1] <- param[(i-1),3]+param[(i-1),4]/2
> >
> > param[i,2] <- param[(i-1),4]/2+param[(i-1),5]
> >
> > param[i,3] <- param[(i-1),1]*(param[(i-1),3]+param[(i-1),4]/2)
> >
> > param[i,4] <- param[(i-1),1]*(param[(i-1),4]/2+param[(i-1),5])+param[(i-1),2
> > ]*(param[(i-1),3]+param[(i-1),4]/2)
> >
> > param[i,5] <- param[(i-1),2]*(param[(i-1),4]/2+param[(i-1),5])
> >
> > }
> >
> 
> You can use the compiler package.
> It also helps if you don't repeat certain calculations. For example (param[(i-
> 1),3]+param[(i-1),4]/2) is computed three times.
> Once is enough.
> 
> See this example where your code has been put in function f1. The simplified 
> code is in
> function f3.
> Functions f2 and f4 are the compiled versions of f1 and f3.
> 
> library(compiler)
> library(rbenchmark)
> param <- matrix(0, 11, 5)
> colnames(param) <- c("p", "q", "r", "2s", "t")
> param[1,] <- c(0.5, 0.5, 0.4, 0.5, 0.1)
> 
> # your calculation
> f1 <- function(param) {
> for (i in 2:11){
> param[i,1] <- param[(i-1),3]+param[(i-1),4]/2
> param[i,2] <- param[(i-1),4]/2+param[(i-1),5]
> param[i,3] <- param[(i-1),1]*(param[(i-1),3]+param[(i-1),4]/2)
> param[i,4] <- 
> param[(i-1),1]*(param[(i-1),4]/2+param[(i-1),5])+param[(i-
> 1),2]*(param[(i-1),3]+param[(i-1),4]/2)
> param[i,5] <- param[(i-1),2]*(param[(i-1),4]/2+param[(i-1),5])
> }
> 
> param
> }
> 
> f2 <- cmpfun(f1)
> 
> # modified by replacing identical sub-expressions with result
> f3 <- function(param) {
> for (i in 2:11){
> param[i,1] <- param[(i-1),3]+param[(i-1),4]/2
> param[i,2] <- param[(i-1),4]/2+param[(i-1),5]
> param[i,3] <- param[(i-1),1]*param[i,1]
> param[i,4] <- param[(i-1),1]*param[i,2]+param[(i-1),2]*param[i,1]
> param[i,5] <- param[(i-1),2]*param[i,2]
> }
> 
> param
> }
> 
> f4 <- cmpfun(f3)
> 
> z1 <- f1(param)
> z2 <- f2(param)
> z3 <- f3(param)
> z4 <- f4(param)
> 
> Running in R
> 
> > all.equal(z2,z1)
> [

Re: [R] Problem with Stationary Bootstrap

2012-09-17 Thread Rui Barradas
Hello,

The problem is your function calling itself until there's no more stack 
memory left.
Besides, your function doesn't make any sense. You pass an argument 
'fit' then do not used it but change it's value then return itself.
Corrected:

set.seed(1)
X <- runif(10, 0, 10)
Y <- 2 + 3*X
a <- data.frame(X = X, Y = Y)

fun <- function(a){
   fit <- lm(Y ~ X, data=a)
   return(coef(fit))
}
result <- boot::tsboot(a, statistic = fun, R = 10, sim = "geom", l = 10, 
orig.t = TRUE)

Hope this helps,

Rui Barradas

Em 17-09-2012 14:42, Hock Ann Lim escreveu:
> Dear R experts,
>   
> I'm running the following stationary bootstrap programming to find the 
> parameters estimate of a linear model:
>   
> X<-runif(10,0,10)
> Y<-2+3*X
> a<-data.frame(X,Y)
> coef<-function(fit){
>fit <- lm(Y~X,data=a)
> return(coef(fit))
> }
>   result<- tsboot(a,statistic=coef(fit),R = 10,n.sim = NROW(a),sim = 
> "geom",orig.t = TRUE)
>   
> Unfortunately, I got this error message from R:
> Error: evaluation nested too deeply: infinite recursion / 
> options(expressions=)?
> Can someone tells me what's wrong in the programming.
>   
> Thank you.
>   
> Regards,
> Lim Hock Ann
>
>   [[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] Using paste to create and evaluate a variable expression

2012-09-17 Thread peter dalgaard

On Sep 17, 2012, at 06:04 , Bryan Keller wrote:

> Is it possible to use "paste" to write out an expression and evaluate it?
> Suppose I want to add two vectors X1 and X2, defined as follows:
> 
> X1 <- 1:6
> X2 <- 6:1
> 
> If I write the following it looks like what I want but is a character:
> noquote(paste(paste("X", 1, sep = ""), paste("X", 2, sep = ""), sep = "+"))
> 
> Is there a way to tell R that I want to evaluate the text, not just print
> it out as a character?


You need to parse() it first, then eval()uate. (Read the respective help pages 
for details.)


However:

> fortune("parse")

If the answer is parse() you should usually rethink the question.
   -- Thomas Lumley
  R-help (February 2005)



-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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] Can anyone help why the errors are coming and rectify it?

2012-09-17 Thread Patrick Burns

This is Circle 8.1.43 of 'The R Inferno'.

http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

Pat


On 17/09/2012 10:47, Sri krishna Devarayalu Balanagu wrote:

Hi Everyone,

Can anyone help why the errors are coming and rectify it?


invalid.ids <- c(1,3,5)
if (length(invalid.ids)==0)   {
 
cat("No Errors found")
}
else  {
 
cat(paste(invalid.ids), sep="\n")
   }

Error: unexpected 'else' in "else"
Error: unexpected '}' in "}"

Thank you in advance

Warm Regards
Rayalu
Notice: The information contained in this electronic mail message is intended only 
for the use of the designated recipient. This message is privileged and confidential. 
and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this 
message is not the intended recipient or an agent responsible for delivering it to 
the intended recipient, you are hereby notified that you have received this message 
in error and that any review, dissemination, distribution, or copying of this message 
is strictly prohibited. If you have received this communication in error, please 
notify us immediately by telephone +91-40-6692 and 
destroy any and all copies of this message in your possession (whether hard copies or 
electronically stored copies).

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



--
Patrick Burns
pbu...@pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] I want to send the vector a into the Object A.......

2012-09-17 Thread Jean V Adams
Try this.

A <- get(x[1])

Jean


Sri krishna Devarayalu Balanagu  wrote on 
09/17/2012 07:13:51 AM:
> 
> a=c(1,2,3)
> b=c(23, 24, 25)
> x=c("a", "b")
> #if (length(x[1]) == 0) {cat("x[1] is having 3 elements")}
> 
> Suppose I want to send the vector a into the Object A,
> um getting only "a" as the ouput for Object A but not getting 
> required output as the vector with the elements 1, 2, 3 with  the 
> following code
> 
> A<- x[1]
> 
> How to code it?
> Can anyone help?

[[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] Possible Improvement of the R code

2012-09-17 Thread William Dunlap
Getting rid of one more matrix subscripting call trims the
time by another 10-20%.  With the following function the times
for 10^4 reps for a a 11-row input matrix become
  raw compiled
  f1 5.57 3.04
  f3 3.73 2.14
  f5 3.45 1.95
  f6 1.63 0.90
  f7 1.32 0.81

f7 <- function(param) {
prev <- param[1,]
for(i in 2:nrow(param)) {
# do vector and matrix subscripting only once/iteration
# and repeated sums only once/iteration.
p1 <- prev[1]
p2 <- prev[2]
p42 <- prev[4]/2
p342 <- prev[3] + p42
p425 <- p42 + prev[5]
param[i,] <- prev <- c(
p342,
p425,
p1 * p342,
p1 * p425 + p2 * p342,
p2 * p425)
}
param
}
f7c <- cmpfun(f7)




Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: William Dunlap
> Sent: Monday, September 17, 2012 8:53 AM
> To: 'Berend Hasselman'; li li
> Cc: r-help
> Subject: RE: [R] Possible Improvement of the R code
> 
> Unlike C or C++, subscripting vector or matrix is not almost free.
> Also, subscripting a matrix tends to make more time than subscripting a
> vector so it can help to pull out the previous row of params once
> per iteration, use vector subscripting on the that row to build the new
> row, and then insert the new row back into params with one matrix
> subscripting call:
> f5 <- function(param) {
> for(i in 2:11) {
> # do matrix subscripting only twice per iteration
> prev <- param[i-1, ]
> param[i,] <- c(
> prev[3] + prev[4]/2,
> prev[4]/2 + prev[5],
> prev[1] * (prev[3] + prev[4]/2),
> prev[1] * (prev[4]/2 + prev[5]) + prev[2] * (prev[3] + prev[4]/2),
> prev[2] * (prev[4]/2 + prev[5]))
> }
> param
> }
> You can also do as much as possible to not repeat any subscripting or
> sums:
> f6 <- function(param) {
> for(i in 2:11) {
> # do any subscripting only twice/iteration and
> # repeated sums only once/iteration.
> prev <- param[i-1, ]
> p1 <- prev[1]
> p2 <- prev[2]
> p42 <- prev[4]/2
> p342 <- prev[3] + p42
> p425 <- p42 + prev[5]
> param[i,] <- c(
> p342,
> p425,
> p1 * p342,
> p1 * p425 + p2 * p342,
> p2 * p425)
> }
> param
> }
> 
> I was curious about how much the compiler package could replace 
> hand-optimization
> so I timed these with and without compiling.  (f1 and f3 are Berend's f1 and 
> f3; I renamed
> his f2 and f4 to f1c and f3c to indicate they were the compiled versions.)
> > funs <- list(f1=f1, f1c=f1c, f3=f3, f3c=f3c, f5=f5, f5c=f5c, f6=f6, f6c=f6c)
> > z <- vapply(funs, function(f)system.time(for(i in 1:1)f(param))[1:3], 
> > numeric(3))
> > z
> f1  f1c   f3  f3c   f5  f5c   f6 f6c
> user.self 5.03 2.82 3.74 1.89 2.73 1.78 1.54 0.9
> sys.self  0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.0
> elapsed   5.03 2.83 3.75 1.90 2.76 1.77 1.54 0.9
> > matrix(z["user.self", ], byrow=TRUE, ncol=2, 
> > dimnames=list(c("f1","f3","f5","f6"),
> c("raw","compiled")))
> raw compiled
> f1 5.03 2.82
> f3 3.74 1.89
> f5 2.73 1.78
> f6 1.54 0.90
> It looks like both hand- and machine-optimization help quite a bit here.
> 
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
> 
> 
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> > Behalf
> > Of Berend Hasselman
> > Sent: Sunday, September 16, 2012 9:28 PM
> > To: li li
> > Cc: r-help
> > Subject: Re: [R] Possible Improvement of the R code
> >
> >
> > On 17-09-2012, at 00:51, li li wrote:
> >
> > > Dear all,
> > >   In the following code, I was trying to compute each row of the "param"
> > > iteratively based
> > > on the first row.
> > >   This likely is not the best way. Can anyone suggest a simpler way to
> > > improve the code.
> > >   Thanks a lot!
> > > Hannah
> > >
> > >
> > > param <- matrix(0, 11, 5)
> > >
> > > colnames(param) <- c("p", "q", "r", "2s", "t")
> > >
> > > param[1,] <- c(0.5, 0.5, 0.4, 0.5, 0.1)
> > >
> > > for (i in 2:11){
> > >
> > > param[i,1] <- param[(i-1),3]+param[(i-1),4]/2
> > >
> > > param[i,2] <- param[(i-1),4]/2+param[(i-1),5]
> > >
> > > param[i,3] <- param[(i-1),1]*(param[(i-1),3]+param[(i-1),4]/2)
> > >
> > > param[i,4] <- 
> > > param[(i-1),1]*(param[(i-1),4]/2+param[(i-1),5])+param[(i-1),2
> > > ]*(param[(i-1),3]+param[(i-1),4]/2)
> > >
> > > param[i,5] <- param[(i-1),2]*(param[(i-1),4]/2+param[(i-1),5])
> > >
> > > }
> > >
> >
> > You can use the compiler package.
> > It also helps if you don't repeat certain calculations. For example 
> > (param[(i-
> > 1),3]+param[(i-1),4]/2) is computed three times.
> > Once is enough.
> >
> > See this example where your code has been put in function f1. The 
> > simplified code is in
> > function f3.
> > Functio

[R] Constraint Optimization with constrOptim

2012-09-17 Thread Raimund Grundböck
Hi,

I am having trouble using constrOptim. My target is to do a portfolio 
optimization and there some constraints have to be fulfilled.

1) The weight of each share of the portfolio has to be greater than 0
2) The sum of these weights has to be 1

I am able to fulfill either the first or the second constraint but not both.

One simple way would be to fulfill the first constraint by using optim as I 
have the possibility of using bounds (lower=0, upper=1) but then I am not able 
to implement the second constraint.

Has anybody an idea to implement both constraints. Or, does anybody know the 
fault in the code (I try to solve it since many days)?

Thank you for your help

Raimund


Here is the simplified code:

#Computation of the minimum-variance portfolio

library(tawny)
library(fBasics)

#Rendite - data
dataset <- matrix(c(0.019120,  0.033820, -0.053180,  0.036220, -0.021480,   
-0.029380, -0.012180, -0.076980, -0.060380,
0.038901, -0.032107, -0.034153, -0.031944,  0.006494,   
-0.021062, -0.058497,  0.050473,  0.026086,
0.004916, -0.015996,  0.003968,  0.030721,  0.034774,   
-0.004972,  0.019459,  0.000196, -0.001849), nrow=3, ncol=9, byrow=TRUE)
  
#Computation of the means
tableMeans <- colMeans(dataset)
  
#Computation of the variance-covariance matrix
covarianceMatrix <- ((t(dataset)) %*% dataset) / 3
  
#SOLVER-START-
  
#start estimates
startingEstimates = rep(1/9, 9)
matrixStartingEstimates = matrix(startingEstimates, nrow=1, ncol=9, byrow=TRUE)

matrixStartingEstimatesNegativ = matrix(rep(-1/9, 9), nrow=1, ncol=9, 
byrow=TRUE)
  
#The function which should be minimized
x <- matrixStartingEstimates
fkt <- function(x) {t(x) %*% covarianceMatrix %*% x}
  
#The constraints
#The results should be greater 0!DOES NOT WORK!
constraint1 <- x[1:9]
#The summ of the results should be between 0.999 and 1.001
constraint2 <- sum(matrixStartingEstimatesNegativ)
constraint3 <- sum(x)
  
constraintMatrix <- rbind(constraint1, constraint2, constraint3)
constraintVektor <- c(0, -1.1, 0.9)
  
#Optimization
constrOptim(startingEstimates, fkt, NULL, ui = constraintMatrix, ci = 
constraintVektor)
  

#SOLVER-END-
[[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] memory leak using XML readHTMLTable

2012-09-17 Thread Duncan Temple Lang
Hi James

  Unfortunately, I am not certain if the "latest version"
of the XML package has the garbage collection activated for the nodes.
It is quite complicated and that feature was turned off in some versions
of the package.  I suggest that you install the version of the package on github

  git@github-omg:omegahat/XML.git

I believe that will handle the garbage collection of nodes, and I'd like
to know if it doesn't.

   Best,
D.

On 9/16/12 8:30 PM, J Toll wrote:
> Hi,
> 
> I'm using the XML package to scrape data and I'm trying to figure out
> how to eliminate the memory leak I'm currently experiencing.  In the
> searches I've done, it sounds like the existence of the leak is fairly
> well known.  What isn't as clear is exactly how to solve it.  The
> general process I'm using is this:
> 
> require(XML)
> 
> myFunction <- function(URL) {
> 
>   html <- readLines(URL)
> 
>   tables <- readHTMLTable(html, stringsAsFactors = FALSE)
> 
>   myData <- data.frame(Value = tables[[1]][, 2],
> row.names = make.unique(tables[[1]][, 1]),
> stringsAsFactors = FALSE)
> 
>  rm(list = c("html", "tables"))   # here, and
>  free(tables)  # here, my attempt to solve the
> memory leak
> 
>   return(myData)
> 
> }
> 
> x <- lapply(myURLs, myFunction)
> 
> 
> I've tried using rm() and free() to try to free up the memory each
> time the function is called, but it hasn't worked as far as I can
> tell.  By the time lapply is finished woking through my list of url's,
> I'm swapping about 3GB of memory.
> 
> I've also tried using gc(), but that seems to also have no effect on
> the problem.
> 
> I'm running RStudio 0.96.330 and latest version of XML.
> R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
> 
> Any suggestions on how to solve this memory issue?  Thanks.
> 
> 
> James
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] I want to send the vector a into the Object A.......

2012-09-17 Thread arun
Hi,After second thought,
May be this:get(A)
[1] 1 2 3
A.K.

- Original Message -

From: Sri krishna Devarayalu Balanagu 
To: "r-help@r-project.org" 
Cc: 
Sent: Monday, September 17, 2012 8:13 AM
Subject: [R] I want to send the vector a into the Object A...

a=c(1,2,3)
b=c(23, 24, 25)
x=c("a", "b")
#if (length(x[1]) == 0) {cat("x[1] is having 3 elements")}

Suppose I want to send the vector a into the Object A,
um getting only "a" as the ouput for Object A but not getting required output 
as the vector with the elements 1, 2, 3 with  the following code

A<- x[1]

How to code it?
Can anyone help?
Notice: The information contained in this electronic mail message is intended 
only for the use of the designated recipient. This message is privileged and 
confidential. and the property of GVK BIO or its affiliates and subsidiaries. 
If the reader of this message is not the intended recipient or an agent 
responsible for delivering it to the intended recipient, you are hereby 
notified that you have received this message in error and that any review, 
dissemination, distribution, or copying of this message is strictly prohibited. 
If you have received this communication in error, please notify us immediately 
by telephone +91-40-6692 and destroy any and all 
copies of this message in your possession (whether hard copies or 
electronically stored copies).

    [[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] count NAs per week

2012-09-17 Thread arun
HI,
May be this is what you wanted.
 res1<-aggregate(dattrial2$a,list(dattrial2$Week,dattrial2$AnimalID),function(x)
 sum(is.na(x)))
> split(res1,res1$Group.2)
#$Bert
#  Group.1 Group.2 x
#1   3    Bert 1
#2   4    Bert 1

#$Ernie
 # Group.1 Group.2 x
#3   3   Ernie 1
#4   4   Ernie 0


A.K.



- Original Message -
From: Tagmarie 
To: r-help@r-project.org
Cc: 
Sent: Monday, September 17, 2012 9:07 AM
Subject: Re: [R] count NAs per week

Thank you Michael, that worked perfectly! 

Now I wonder, if it is possible to break my data further apart and put it
together again. 
Assume I include a column for an ID in the data frame like this: 

dattrial2<-data.frame(a=c(1,NA,NA,NA,2,3), Week=c(3,3,3,4,4,4),
AnimalID=c("Ernie","Bert", "Ernie", "Bert", "Bert", "Ernie"))

Is it possible to get two different lists in the output, one for Ernie and
one for Bert? Or do I have to do it seperately for each animal?

Thank you again! I learn a lot by doing and by people helping me. Thank you
for the hint with the paper. 





--
View this message in context: 
http://r.789695.n4.nabble.com/count-NAs-per-week-tp4643351p4643371.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] FF package & downloading a large file using sqlQuery

2012-09-17 Thread Jan
You can use the read.dbi.ffdf and read.odbc.ffdf function in package
ETLUtils. These allow you to fetch a query directly in an ffdf. See the
examples in their corresponding documentation ?read.dbi.ffdf and
?read.odbc.ffdf or look at this blog post
http://www.bnosac.be/index.php/blog/21-readodbcffdf-a-readdbiffdf-for-fetching-large-corporate-sql-data.

But as you are new to R and package ff might not be the best starting
package when you are a newcomer, I suggest you first try to make a simple
connection using ODBC or using the package RPostgreSQL in order to connect
to your database. Once you can connect, use the same connection parameters
in read.dbi.ffdf or read.odbc.ffdf to fetch your large dataset.

good luck



--
View this message in context: 
http://r.789695.n4.nabble.com/FF-package-downloading-a-large-file-using-sqlQuery-tp4642456p4643393.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] Server R

2012-09-17 Thread Bazman76


Thanks Michael,
I presume that the command
sudo apt-get updatewill do the trick but am emailing the appropriate group to 
get more background on what packages are included in the latest ubuntu version 
of R.Date: Mon, 17 Sep 2012 05:43:56 -0700
From: ml-node+s789695n4643369...@n4.nabble.com
To: h_a_patie...@hotmail.com
Subject: Re: Server R



On Sun, Sep 16, 2012 at 9:42 PM, Bazman76 <[hidden email]> wrote:

> Hi there,

>

> I used the command

>

> sudo apt-get install r-base

>

> to install R on an EC2 server as shown below:

>

> http://www.r-bloggers.com/ec2-micro-instance-of-rstudio/
>

> It works but the version of R installed is:

>

>  R.version.string

> [1] "R version 2.12.1 (2010-12-16)"

>

> I want to the latest version with package parallel included.

>

> How can I change the commend to ensure the latest version of R is installed?

>

>

I presume EC2 runs Ubuntu:


http://cran.r-project.org/bin/linux/ubuntu/README

Cheers,

Michael



>

>

>

>

> --

> View this message in context: 
> http://r.789695.n4.nabble.com/Server-R-tp4643319.html
> Sent from the R help mailing list archive at Nabble.com.

>

> __

> [hidden email] mailing list

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

__

[hidden email] mailing list

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












If you reply to this email, your message will be added to the 
discussion below:
http://r.789695.n4.nabble.com/Server-R-tp4643319p4643369.html



To unsubscribe from Server R, click here.

NAML
  



--
View this message in context: 
http://r.789695.n4.nabble.com/Server-R-tp4643319p4643390.html
Sent from the R help mailing list archive at Nabble.com.
[[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] Zip a file

2012-09-17 Thread arun


Hi Antony,

I don't use the function zip().  I was able to access the R documentation for 
zip() (package:utils). 

 I am using R 2.15 in Ubuntu 12.04.   If I wanted to compress files, I do 
gzip() from linux terminal.  I guess in windows, you can use 7-zip or other 
WinZip.  Is there any specific reason for you to zip files within R?
A.K.        

- Original Message -

From: Rantony 
To: r-help@r-project.org
Cc: 
Sent: Monday, September 17, 2012 3:07 AM
Subject: Re: [R] Zip a file

Hi Arun,



I tried this way, but getting an error like



Using Eclips:

“Error in .rj.originals$help(..., help_type = "html") : 'topic' should be a 
name, length-one character vector or reserved word”



Using R:

Error: could not find function "zip"



So, is it required to install any package for zip functioning ?







From: arun kirshna [via R] [mailto:ml-node+s789695n4643049...@n4.nabble.com] 
Sent: Thursday, September 13, 2012 11:55 PM
To: Akkara, Antony (GE Energy, Non-GE)
Subject: Re: Zip a file



HI, 

If you look ?zip(), the usage is: 
     zip(zipfile, files, flags = "-r9X", extras = "", 
         zip = Sys.getenv("R_ZIPCMD", "zip")) 
    
A.K. 




- Original Message - 
From: Rantony <[hidden email]> 
To: [hidden email] 
Cc: 
Sent: Thursday, September 13, 2012 8:10 AM 
Subject: [R] Zip a file 

Hi, 

How to zip a csv file ? i tried with "zipfile.ZipFile" - but it showing 
function could not find. 
Is there have any other way to zip files without installing any package ? 

- Thanks in advance 
Antony 



-- 
View this message in context: 
http://r.789695.n4.nabble.com/Zip-a-file-tp4643012.html
Sent from the R help mailing list archive at Nabble.com. 

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


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





If you reply to this email, your message will be added to the discussion below:

http://r.789695.n4.nabble.com/Zip-a-file-tp4643012p4643049.html 

To unsubscribe from Zip a file, click here 

 .
NAML 
 
 





--
View this message in context: 
http://r.789695.n4.nabble.com/Zip-a-file-tp4643012p4643344.html
Sent from the R help mailing list archive at Nabble.com.
    [[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] Boxplot lattice vs standard graphics

2012-09-17 Thread David Winsemius

On Sep 17, 2012, at 4:18 AM, maxbre wrote:

> here it is, I think (I hope)  I'm getting a little closer with this, but
> still there is something  to sort out...
> 
> error using packet 1
> unused argument(s)  (coef =1.5, do.out=TRUE)
> 
> by reading the help for panel.bwplot at the argument "stats" it says: "the
> function must accept arguments coef and do.out even if they do not use them
> (a ... argument is good enough). "
> I'm not sure how to couple with this...
> 
> any help for this ?
> 
> thanks
> 
> 
> ## start code
> 
> 
> mystats <- function(x){
>  out <- boxplot.stats(10^x)
>  out$stats <- log10(out$stats)
>  out$conf <- log10(out$conf) ## Omit if you don't want notches
>  out$out <- log10(out$out)
>  out$coef<-1.5 #??
>  out$do.out<-"TRUE" #??
>  out ## With the boxplot statistics converted to the log10 scale
> }
> 
> bwplot(conc~site, data=test,
>   scales=list(y=list(log=10)),
>   panel= function(x,y){
> panel.bwplot(x,y,stats=mystats)
>   } 
>   )

No example data, so no efforts at running code.

?panel.bwplot

# Notice the Usage at the top of the page. The "..." is there for a reason.

# And notice that neither 'do.out' nor 'coef' are passed in the "stats" list

# The message was talking about what arguments your 'mystats' would accept, 
 not what it would return. It's another instance of your needing to 
understand what the "..." formalism is doing.

?boxplot.stats

# I would be making a concerted effort to return a list with exactly the 
components listed there.

> ## end code
> 
> 
-- 

David Winsemius, MD
Alameda, CA, USA

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

2012-09-17 Thread Yihui Xie
I think the correct address for GIT should be
git://github.com/omegahat/XML.git :) Or just
https://github.com/omegahat/XML

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Mon, Sep 17, 2012 at 11:16 AM, Duncan Temple Lang
 wrote:
> Hi James
>
>   Unfortunately, I am not certain if the "latest version"
> of the XML package has the garbage collection activated for the nodes.
> It is quite complicated and that feature was turned off in some versions
> of the package.  I suggest that you install the version of the package on 
> github
>
>   git@github-omg:omegahat/XML.git
>
> I believe that will handle the garbage collection of nodes, and I'd like
> to know if it doesn't.
>
>Best,
> D.

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

2012-09-17 Thread David Winsemius

On Sep 17, 2012, at 6:07 AM, Tagmarie wrote:

> Thank you Michael, that worked perfectly! 
> 
> Now I wonder, if it is possible to break my data further apart and put it
> together again. 
> Assume I include a column for an ID in the data frame like this: 
> 
> dattrial2<-data.frame(a=c(1,NA,NA,NA,2,3), Week=c(3,3,3,4,4,4),
> AnimalID=c("Ernie","Bert", "Ernie", "Bert", "Bert", "Ernie"))
> 
> Is it possible to get two different lists in the output, one for Ernie and
> one for Bert? Or do I have to do it seperately for each animal?

split(dattrial2, dattrial2[['AnimalID']])

> 
> Thank you again! I learn a lot by doing and by people helping me. Thank you
> for the hint with the paper. 
> 
> 
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/count-NAs-per-week-tp4643351p4643371.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.

David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Boxplot lattice vs standard graphics

2012-09-17 Thread Rui Barradas

Hello,

Em 17-09-2012 18:50, David Winsemius escreveu:

On Sep 17, 2012, at 4:18 AM, maxbre wrote:


here it is, I think (I hope)  I'm getting a little closer with this, but
still there is something  to sort out...

error using packet 1
unused argument(s)  (coef =1.5, do.out=TRUE)

by reading the help for panel.bwplot at the argument "stats" it says: "the
function must accept arguments coef and do.out even if they do not use them
(a ... argument is good enough). "
I'm not sure how to couple with this...

any help for this ?

thanks


## start code


mystats <- function(x){
  out <- boxplot.stats(10^x)
  out$stats <- log10(out$stats)
  out$conf <- log10(out$conf) ## Omit if you don't want notches
  out$out <- log10(out$out)
  out$coef<-1.5 #??
  out$do.out<-"TRUE" #??
  out ## With the boxplot statistics converted to the log10 scale
}

bwplot(conc~site, data=test,
   scales=list(y=list(log=10)),
   panel= function(x,y){
 panel.bwplot(x,y,stats=mystats)
   }
   )

No example data, so no efforts at running code.


Actually there is, in the op.



?panel.bwplot

# Notice the Usage at the top of the page. The "..." is there for a reason.

# And notice that neither 'do.out' nor 'coef' are passed in the "stats" list

# The message was talking about what arguments your 'mystats' would accept,  not what 
it would return. It's another instance of your needing to understand what the 
"..." formalism is doing.

?boxplot.stats

# I would be making a concerted effort to return a list with exactly the 
components listed there.


And since I'm terrible at graphics I try to learn as much as possible on 
R-Help. Here it goes.



library(lattice)

test<-structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L), .Label = c("A",
"B", "C", "D", "E"), class = "factor"), conc = c(2.32, 0.902,
0.468, 5.51, 1.49, 0.532, 0.72, 0.956, 0.887, 20, 30, 2.12, 0.442,
10, 50, 110, 3.36, 2.41, 20, 70, 3610, 100, 4.79, 20, 0.0315,
30, 60, 1, 3.37, 80, 1.21, 0.302, 0.728, 1.29, 30, 40, 90, 30,
0.697, 6.25, 0.576, 0.335, 20, 10, 620, 40, 9.98, 4.76, 2.61,
3.39, 20, 4.59)), .Names = c("site", "conc"), row.names = c(NA,
52L), class = "data.frame")


#standard graphics
dev.new()
with(test,boxplot(conc~site, log="y"))

#lattice
mystats <- function(x, ...){ # Here ...
out <- boxplot.stats(10^x, ...)  # ...and here!!!
out$stats <- log10(out$stats)
out$conf <- log10(out$conf) ## Omit if you don't want notches
out$out <- log10(out$out)
out ## With the boxplot statistics converted to the log10 scale
}

dev.new()
bwplot(conc~site, data=test,
   scales = list(y=list(log=10)),
   panel = function(...){
 panel.bwplot(..., stats = mystats)
   }
)

With a median _line_ it would be perfect.
(Not a follow-up, it was already answered some time ago, use pch = "|" 
in panel.bwplot.)


Rui Barradas



## end 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] other files in \inst\doc

2012-09-17 Thread A.I. McLeod
I would like to include a Mathematica notebook and cdf file (both are
ASCII files) in the \inst\doc directory as supporting documentation. These
files are not large, about 340K each one. When I check using
R CMD check --as-cran ...
I get the following warning:

..
* checking data for ASCII and uncompressed saves ... OK
 WARNING
'qpdf' is needed for checks on size reduction of PDFs
* checking examples ... OK
* checking PDF version of manual ... OK

WARNING: There was 1 warning.

This warning disappears when I delete \inst\doc

Is this a bug?
Is it forbidden to include such ASCII files?

Regards, Ian McLeod

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Creating missingness in repeated measurement data

2012-09-17 Thread john james
Dear R users,
 
I have the following problems. My dataset (dat) is as follows: 

a <- c(1,2,3) 
id <- rep(a, c(3,2,3))
stat <- c(1,1,0,1,0,1,1,1)
g <- c(0,0,0,0,0,0,1,0)
stop <- c(1,2,4,2,4,1,1.5,3)
dat <- data.frame(id,stat,g,stop)
 
I want to creat a new dataset (dat2) with missing values 
such that when either g = =1 or stat = =0, the remaining rows for an 
individual subject is set to NA by using a new variable d (that states 
the exact time this 
happened from the stop variable). By this I mean dat2 that looks like,
 
id <- rep(a, c(3,2,3))
sta2<- c(1,1,NA,1,NA,1,NA,NA)
g2<- c(0,0,NA,0,NA,0,NA,NA)
stop2 <- c(1,2,NA,2,NA,1,NA,NA)
d <- c(4,4,NA,4,NA,1.5,NA,NA)
 
dat2 <- data.frame(id=id, stat2=sta2, g2=g2,stop2=stop2,d=d).
 
Thank you very much!
 
John
[[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] Question about R performance on UNIX/LINUX with, different memory/swap configurations

2012-09-17 Thread Paul Gilbert



On 12-09-17 06:00 AM, r-help-requ...@r-project.org wrote:

Date: Sun, 16 Sep 2012 14:41:42 -0500
From: Dirk Eddelbuettel
To: "Eberle, Anthony"
Cc:r-help@r-project.org
Subject: Re: [R] Question about R performance on UNIX/LINUX with
different   memory/swap configurations
Message-ID:<20566.11126.175103.643...@max.nulle.part>
Content-Type: text/plain; charset=us-ascii


On 16 September 2012 at 13:30, Eberle, Anthony wrote:
| Does anyone have any guidance on swap and memory configuration when
| running R v2.15.1 on UNIX/LINUX?  Through some benchmarking across
| multiple hardware (UNIX, LINUX, SPARC, x86, Windows, physical, virtual)
| it "seems" that the smaller memory machines have an advantage.

Would you be able to provide some "empirical proofs" for that conjecture?
Please demonstrate how, say, a X gb ram machine outperforms one with Y gb
where Y > X.

Less memory is/never/  better.


Exceptions to the rule:
There are a couple of unusual situations were less memory can be better. 
As someone else pointed out, if you start swapping then performance 
takes a hit. So, if you have enough physical memory to do your own job, 
but not enough to let other jobs run and push you into swapping, then 
you may get better performance on the single job. Second, if you have 
long recursions that grab lots of memory, then these will use swap. 
Typically one would want the job to succeed, and thus swap is good, but 
slow. However, if your code is bad and doing an infinite recursion, then 
with swap this can take a very long time to fail, whereas with only 
physical memory it fails much more quickly.
Third, there were (are?) situations where 32 bit machines/OSes perform 
(very slightly) faster than 64 bit machines/OSes, and since the former 
typically have less memory, one could have the impression that less 
memory is faster.


Paul


Dirk

-- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.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] Creating missingness in repeated measurement data

2012-09-17 Thread David Winsemius

On Sep 17, 2012, at 11:32 AM, john james wrote:

> Dear R users,
>  
> I have the following problems. My dataset (dat) is as follows: 
> 
> a <- c(1,2,3) 
> id <- rep(a, c(3,2,3))
> stat <- c(1,1,0,1,0,1,1,1)
> g <- c(0,0,0,0,0,0,1,0)
> stop <- c(1,2,4,2,4,1,1.5,3)
> dat <- data.frame(id,stat,g,stop)
>  
> I want to creat a new dataset (dat2) with missing values 
> such that when either g = =1 or stat = =0, the remaining rows for an 
> individual subject is set to NA by using a new variable d (that states 
> the exact time this 
> happened from the stop variable). By this I mean dat2 that looks like,
>  
> id <- rep(a, c(3,2,3))
> sta2<- c(1,1,NA,1,NA,1,NA,NA)
> g2<- c(0,0,NA,0,NA,0,NA,NA)
> stop2 <- c(1,2,NA,2,NA,1,NA,NA)
> d <- c(4,4,NA,4,NA,1.5,NA,NA)
>  
> dat2 <- data.frame(id=id, stat2=sta2, g2=g2,stop2=stop2,d=d).

> suppressidx <- ave(dat$stat==0 | dat$g==1, dat$id, FUN=cumsum)
> suppress <- function(col) { ifelse( suppressidx, NA, col)}
> cbind(dat[1], sapply( dat[-1], function(x) suppress(x) ) )
  id stat  g stop
1  11  01
2  11  02
3  1   NA NA   NA
4  21  02
5  2   NA NA   NA
6  31  01
7  3   NA NA   NA
8  3   NA NA   NA

-- 

David Winsemius, MD
Alameda, CA, USA

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

2012-09-17 Thread J Toll
On Mon, Sep 17, 2012 at 12:51 PM, Yihui Xie  wrote:
> I think the correct address for GIT should be
> git://github.com/omegahat/XML.git :) Or just
> https://github.com/omegahat/XML
>
> Regards,
> Yihui
> --
> Yihui Xie 
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
> On Mon, Sep 17, 2012 at 11:16 AM, Duncan Temple Lang
>  wrote:
>> Hi James
>>
>>   Unfortunately, I am not certain if the "latest version"
>> of the XML package has the garbage collection activated for the nodes.
>> It is quite complicated and that feature was turned off in some versions
>> of the package.  I suggest that you install the version of the package on 
>> github
>>
>>   git@github-omg:omegahat/XML.git
>>
>> I believe that will handle the garbage collection of nodes, and I'd like
>> to know if it doesn't.
>>
>>Best,
>> D.

Hi,

Thanks for your response and I'm sorry, I should have been more
specific regarding the version of XML.  I'm using XML 3.9-4.

As a sort of follow-on question?  Is there a preferable way to install
this version of XML from github?  Do I have to use git to clone it, or
maybe use the install_github function from Hadley's devtools package?
I note that the README indicates that:

"This R package is not in the R package format in the github repository.
It was initially developed in 1999 and was intended for use in both
S-Plus and R and so requires a different structure for each."

So I was wondering what the general procedure is and whether there's
anything special I need to do to install it?  Thanks.


James

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] arima forecast without the first order of auto-regressor

2012-09-17 Thread lornyi
Hi, I want to predict using airma, but I want to predict using t-2 or t-3,
instead of t-1
right now the arima() function doesn't allow me to do that, it will alwasy
return with variable t-1 , 
what is the way to skip that variable?
thanks ®ards



--
View this message in context: 
http://r.789695.n4.nabble.com/arima-forecast-without-the-first-order-of-auto-regressor-tp4643412.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

2012-09-17 Thread Seydou Badiane
HELLO, I SHALL NEED A HELP. It is my official language(tongue) is French,
even if I manage little in English, I shall like understanding(including)
as fast as possible, that is why I asked if there is a page wiki in French,
thank you in advance for your answers

[[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] Any way to get read.table.ffdf() (in the ff package) to pass colClasses or comment.char parameters through to read.fwf() ?

2012-09-17 Thread Jan
Hi Anthony,

You are right, read.table.ffdf does not handle additional arguments passed
on to read.table in the method read.fwf as you expect. read.table.ffdf
checks the arguments of read.fwf and colClasses is not one of them,
colClasses is part of ... which is passed on to read.table.
You should report this to the package author. A way on how to circumvent it
is by using the following code after which read.fwf will work as you expect
it with arguments comment.char and colClasses.

read.fwf.default <- get("read.fwf")
read.fwf <- function(file, widths, header = FALSE, sep = "\t", skip = 0,
row.names, col.names, n = -1, buffersize = 2000, comment.char = "#",
colClasses = NA, ...){
  read.fwf.default(file=file, widths=widths, header=header, sep=sep,
skip=skip, row.names=row.names, col.names=col.names, n=n,  
buffersize=buffersize, comment.char = comment.char, colClasses = colClasses,
...)
}
v <- read.table.ffdf(file=fwffile, FUN="read.fwf", widths=c(1,2,3),
colClasses = 'factor')


hope this helps,
Jan



--
View this message in context: 
http://r.789695.n4.nabble.com/Any-way-to-get-read-table-ffdf-in-the-ff-package-to-pass-colClasses-or-comment-char-parameters-throu-tp4643171p4643413.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] loglogistic survreg

2012-09-17 Thread Jeremy Brown
Hi,

I'm trying to graph the hazard function using the survreg function with the 
distributional assumptions to be loglogistic. If 
h(t)=[lambda*alpha*(lambda*t)^(alpha-1)]/[1+(lambda*t)^alpha], what output from 
R is alpha?

Thanks
[[alternative HTML version deleted]]

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


Re: [R] Creating missingness in repeated measurement data

2012-09-17 Thread Rui Barradas
Hello,

Maybe there are simpler ways of doing it, but try the following.

sp <- lapply(split(dat, dat$id), function(.s){
 i <- min(which(.s$stat == 0), which(.s$g == 1))
 .s$d <- .s$stop[i]
 .s[-1][row(.s[-1]) >= i] <- NA
 .s
})

dat3 <- do.call(rbind, sp)
rownames(dat3) <- seq_len(nrow(dat3))
all.equal(dat2, dat3)  # only names are different


Hope this helps,

Rui Barradas

Em 17-09-2012 19:32, john james escreveu:
> Dear R users,
>   
> I have the following problems. My dataset (dat) is as follows:
>
> a <- c(1,2,3)
> id <- rep(a, c(3,2,3))
> stat <- c(1,1,0,1,0,1,1,1)
> g <- c(0,0,0,0,0,0,1,0)
> stop <- c(1,2,4,2,4,1,1.5,3)
> dat <- data.frame(id,stat,g,stop)
>   
> I want to creat a new dataset (dat2) with missing values
> such that when either g = =1 or stat = =0, the remaining rows for an
> individual subject is set to NA by using a new variable d (that states
> the exact time this
> happened from the stop variable). By this I mean dat2 that looks like,
>   
> id <- rep(a, c(3,2,3))
> sta2<- c(1,1,NA,1,NA,1,NA,NA)
> g2<- c(0,0,NA,0,NA,0,NA,NA)
> stop2 <- c(1,2,NA,2,NA,1,NA,NA)
> d <- c(4,4,NA,4,NA,1.5,NA,NA)
>   
> dat2 <- data.frame(id=id, stat2=sta2, g2=g2,stop2=stop2,d=d).
>   
> Thank you very much!
>   
> John
>   [[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] memory leak using XML readHTMLTable

2012-09-17 Thread Duncan Temple Lang

Thanks Yihui for normalizing my customized git URL.

The version of the package on github is in the
standard R format and that part of the README is
no longer relevant. Sorry for the confusion.

It might be simplest to pick up a tar.gz file of the source at

 http://www.omegahat.org/RSXML/XML_3.94-0.tar.gz


 D

On 9/17/12 12:31 PM, J Toll wrote:
> On Mon, Sep 17, 2012 at 12:51 PM, Yihui Xie  wrote:
>> I think the correct address for GIT should be
>> git://github.com/omegahat/XML.git :) Or just
>> https://github.com/omegahat/XML
>>
>> Regards,
>> Yihui
>> --
>> Yihui Xie 
>> Phone: 515-294-2465 Web: http://yihui.name
>> Department of Statistics, Iowa State University
>> 2215 Snedecor Hall, Ames, IA
>>
>>
>> On Mon, Sep 17, 2012 at 11:16 AM, Duncan Temple Lang
>>  wrote:
>>> Hi James
>>>
>>>   Unfortunately, I am not certain if the "latest version"
>>> of the XML package has the garbage collection activated for the nodes.
>>> It is quite complicated and that feature was turned off in some versions
>>> of the package.  I suggest that you install the version of the package on 
>>> github
>>>
>>>   git@github-omg:omegahat/XML.git
>>>
>>> I believe that will handle the garbage collection of nodes, and I'd like
>>> to know if it doesn't.
>>>
>>>Best,
>>> D.
> 
> Hi,
> 
> Thanks for your response and I'm sorry, I should have been more
> specific regarding the version of XML.  I'm using XML 3.9-4.
> 
> As a sort of follow-on question?  Is there a preferable way to install
> this version of XML from github?  Do I have to use git to clone it, or
> maybe use the install_github function from Hadley's devtools package?
> I note that the README indicates that:
> 
> "This R package is not in the R package format in the github repository.
> It was initially developed in 1999 and was intended for use in both
> S-Plus and R and so requires a different structure for each."
> 
> So I was wondering what the general procedure is and whether there's
> anything special I need to do to install it?  Thanks.
> 
> 
> James
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] loglogistic survreg

2012-09-17 Thread Thomas Lumley
On Tue, Sep 18, 2012 at 7:06 AM, Jeremy Brown  wrote:
> Hi,
>
> I'm trying to graph the hazard function using the survreg function with the 
> distributional assumptions to be loglogistic. If 
> h(t)=[lambda*alpha*(lambda*t)^(alpha-1)]/[1+(lambda*t)^alpha], what output 
> from R is alpha?

  survreg() fits location-scale models, so the model being fitted is
that log(survival time) has a logistic distribution with location
parameter given by the regression model and scale parameter estimated
in each stratum.  I think that means exp(fitted values) is alpha in
your parametrisation.  In a model with only an intercept, that would
be exp(intercept).

   -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] eval(parse(...)) only once in a function

2012-09-17 Thread Thomas Lumley
On Mon, Sep 17, 2012 at 6:27 PM, Christof Kluß  wrote:
> Hi
>
> I would like to have something like
>
> str <- "df$JT == 12"
>
> fun <- function(df) {
>
>   b <- eval(parse(str))
>
>   return(b)
> }
>
> but for performance "eval(parse(a))" should not be evaluated at each
> function call, but should work as
>
> fun <- function(df) {
>
>   b <- df$JT == 12
>
>   return(b)
> }
>
> Do you have an idea how I can implement this?

You can do it with bquote()

> e<-parse(text="df$str==12")[[1]]
> e
df$str == 12
> bquote(function(df) b<-.(e))
function(df) b <- df$str == 12
> eval(bquote(function(df) b<-.(e)))
function (df)
b <- df$str == 12

This saves more time than I expected, about 100ms per evaluation on my
computer.

  -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

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

2012-09-17 Thread Rui Barradas

Google est ton ami:

http://lmgtfy.com/?q=R+statistiques+fran%C3%A7ais

Le deuxième parait prometteur.
Bonne chance,

Rui Barradas
Em 17-09-2012 20:06, Seydou Badiane escreveu:

HELLO, I SHALL NEED A HELP. It is my official language(tongue) is French,
even if I manage little in English, I shall like understanding(including)
as fast as possible, that is why I asked if there is a page wiki in French,
thank you in advance for your answers

[[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] Compiling R2.15.1 on ubuntu with x86-64 architecture and shared library

2012-09-17 Thread Conklin, Mike (GfK Custom Research NA)
I am sure I am providing insufficient information, please ask for more.

I installed R 2.14.2 on my Ubuntu laptop with and AMD64 processor and also 
installed RStudio  and everything worked fine.

Now, I tried to build R 2.15.1 from source and installed it using defaults. 
RStudio now complained that R was not built as a shared library.

Went back and uninstalled, and configured with -enable-R-shlib

Now make fails at:
/usr/bin/ld: CConverters.o: relocation R_X86_64_325 against '.rodata' can not 
be used when making a shared object; recompile with -fPIC

Being new to Linux, I have no idea how to recompile with -fPIC

Any help would be appreciated.

Mike

W. Michael Conklin
Executive Vice President | GfK Marketing Science | Consumer Experiences North 
America
GfK Custom Research, LLC | 8401 Golden Valley Road | Minneapolis, MN, 55427
T +1 763 417 4545 | M +1 612 567 8287
www.gfk.com


[[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] Compiling R2.15.1 on ubuntu with x86-64 architecture and shared library

2012-09-17 Thread Dirk Eddelbuettel

On 17 September 2012 at 23:51, Conklin, Mike (GfK Custom Research NA) wrote:
| I am sure I am providing insufficient information, please ask for more.
| 
| I installed R 2.14.2 on my Ubuntu laptop with and AMD64 processor and also 
installed RStudio  and everything worked fine.
| 
| Now, I tried to build R 2.15.1 from source and installed it using defaults. 
RStudio now complained that R was not built as a shared library.
| 
| Went back and uninstalled, and configured with -enable-R-shlib
| 
| Now make fails at:
| /usr/bin/ld: CConverters.o: relocation R_X86_64_325 against '.rodata' can not 
be used when making a shared object; recompile with -fPIC
| 
| Being new to Linux, I have no idea how to recompile with -fPIC
| 
| Any help would be appreciated.

As I wrote on the r-sig-debian list (which also acts as help for Ubuntu) a
few hours ago:

   Please read the README in the bin/linux/ubuntu/ directory on any CRAN 
mirror, eg

  http://cran.us.r-project.org/bin/linux/ubuntu

   and follow the instructions.  By adding a new and current source of R
   packages, provided by CRAN, you get the current version of R -- ie 2.15.1


Please use that to obtain a _binary_ of R 2.15.1 for your architecture. If
you get stuck, please subscribe to r-sig-debian and ask there.

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.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] "eval" inside a function call in connection with updating the data slot in the call of lmer

2012-09-17 Thread Søren Højsgaard
Dear list,
Given a linear mixed model (from lme4) I want to 1) first change the input 
dataset and then 2) change the model formula. I want this to happen in a 
function call; 
Please see below. Options 1) and 2) below work whereas 3) fails with the 
message 
> foo()
Error in is.data.frame(data) : object 'beets2' not found

Question: What is it one must to in case 3) to have R look "inside" the 
function to figure out what "beets2" is?

Best regards 
Søren


library(pbkrtest)
data(beets)
lgs<- lmer(sugpct~block+sow+harvest+(1|block:harvest), data=beets, REML=F)

foo <- function(){
## 1)
beets2 <- transform(beets, yy = sugpct * yield)
ma1<- lmer(yy~block+sow+harvest+(1|block:harvest), data=beets2, 
REML=F)
ma0<- update(ma1, yy~.)
## 2)
cl <- getCall(lgs)
cl[["data"]] <- beets2
mb1 <- eval(cl)
mb0 <- update(mb1, yy~.)
mb0
## 3)
cl <- getCall(lgs)
cl[["data"]] <- as.name("beets2")
mc1 <- eval(cl)
mc0 <- update(mc1, yy~.)
mc0
}
foo()

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] "eval" inside a function call in connection with updating the data slot in the call of lmer

2012-09-17 Thread David Winsemius

On Sep 17, 2012, at 3:26 PM, Søren Højsgaard wrote:

> Dear list,
> Given a linear mixed model (from lme4) I want to 1) first change the input 
> dataset and then 2) change the model formula. I want this to happen in a 
> function call; 
> Please see below. Options 1) and 2) below work whereas 3) fails with the 
> message 
>> foo()
> Error in is.data.frame(data) : object 'beets2' not found
> 
> Question: What is it one must to in case 3) to have R look "inside" the 
> function to figure out what "beets2" is?

That will depend on how you offer that 6 letter sequence to the interpreter. 
Surrounded by quotes will be quite different than without quotes
> 
> Best regards 
> Søren
> 
> 
> library(pbkrtest)
> data(beets)
> lgs<- lmer(sugpct~block+sow+harvest+(1|block:harvest), data=beets, REML=F)
> 
> foo <- function(){
>   ## 1)
>   beets2 <- transform(beets, yy = sugpct * yield)
>   ma1<- lmer(yy~block+sow+harvest+(1|block:harvest), data=beets2, 
> REML=F)
>   ma0<- update(ma1, yy~.)
>   ## 2)
>   cl <- getCall(lgs)
>   cl[["data"]] <- beets2
>   mb1 <- eval(cl)
>   mb0 <- update(mb1, yy~.)
>   mb0
>   ## 3)
>   cl <- getCall(lgs)
>   cl[["data"]] <- as.name("beets2")

The problem here is that 'beets2' is just a character vector ...  with no 
binding.

I'm wondering if you instead want:
  cl[["data"]] <-  get("beets2")

>   mc1 <- eval(cl)
>   mc0 <- update(mc1, yy~.)
>   mc0
> }
> foo()

No guarantees. I'm not a particularly experienced surgeon of lmer-objects.

> 
-- 

David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 with calculation from dataframe with multiple entries per sample

2012-09-17 Thread Julie Lee-Yaw
Hi 

I have a dataframe similar to:

>Sample<-c(1,1,1,2,2,2,3,3,3)

>Time<-c(1,2,3,1,2,3,1,2,3)

>Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)

>mydata<-as.data.frame(cbind(Sample,Time,Mass))


  Sample Time Mass
1      1    1  3.0
2      1    2  3.1
3      1    3  3.4
4      2    1  4.0
5      2    2  4.3
6      2    3  4.4
7      3    1  3.0
8      3    2  3.2
9      3    3  3.5

where for each sample, I've measured mass at different points in time. 

I now want to calculate the difference between Mass at Time 2 and 3 for each 
unique Sample and store this as a new variable called "Gain2-3". So in my 
example three values of 0.3,0.1,0.3 would be calculated for my three unique 
samples and these values would be repeated in the table according to Sample. I 
am thus expecting:

>mydata #after adding new variable

  Sample Time MassGain2-3
1      1    1  3.00.3
2      1    2  3.1 0.3
3      1    3  3.4 0.3
4      2    1  4.0 0.1
5      2    2  4.3 0.1
6      2    3  4.4 0.1
7      3    1  3.0 0.3
8      3    2  3.2 0.3
9      3    3  3.5 0.3

Does anyone have any suggestions as to how to do this? I've looked at the 
various apply functions but I can't seem to make anything work. I'm fairly new 
to R and would appreciate specific suggestions. 

Thanks!
[[alternative HTML version deleted]]

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


Re: [R] "eval" inside a function call in connection with updating the data slot in the call of lmer

2012-09-17 Thread Duncan Murdoch

On 12-09-17 6:26 PM, Søren Højsgaard wrote:

Dear list,
Given a linear mixed model (from lme4) I want to 1) first change the input 
dataset and then 2) change the model formula. I want this to happen in a 
function call;
Please see below. Options 1) and 2) below work whereas 3) fails with the message


I get the failure in 1), not in 3).  I think it's a bug.  The problem 
appears to be that the update method for mer objects looks in the wrong 
place for its variables.  It is looking in parent.frame() (i.e. in the 
caller), but the caller isn't you.  The method should be looking in 
parent.frame(2).


You can fix this yourself if you have the lme4 source (it's line 1483 of 
lmer.R in version 0.99-0) but you probably want to send your sample 
code to the maintainers.  Making that change might break something else.


Duncan Murdoch







foo()

Error in is.data.frame(data) : object 'beets2' not found

Question: What is it one must to in case 3) to have R look "inside" the function to 
figure out what "beets2" is?

Best regards
Søren


library(pbkrtest)
data(beets)
lgs<- lmer(sugpct~block+sow+harvest+(1|block:harvest), data=beets, REML=F)

foo <- function(){
## 1)
beets2 <- transform(beets, yy = sugpct * yield)
ma1<- lmer(yy~block+sow+harvest+(1|block:harvest), data=beets2, 
REML=F)
ma0<- update(ma1, yy~.)
## 2)
cl <- getCall(lgs)
cl[["data"]] <- beets2
mb1 <- eval(cl)
mb0 <- update(mb1, yy~.)
mb0
## 3)
cl <- getCall(lgs)
cl[["data"]] <- as.name("beets2")
mc1 <- eval(cl)
mc0 <- update(mc1, yy~.)
mc0
}
foo()

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



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


Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread Phil Spector

Julie -
   Since the apply functions operate on one row at a time, they
can't do what you want.  I think the easiest way to solve your 
problem is to reshape the data set, and merge it back with the 
original:



dd = data.frame(Sample=c(1,1,1,2,2,2,3,3,3),

+ Time=c(1,2,3,1,2,3,1,2,3),
+ Mass=c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5))

rdd = reshape(dd,timevar='Time',idvar='Sample',direction='wide')
rdd$"Gain2-3" = rdd$Mass.3 - rdd$Mass.2
merge(dd,subset(rdd,select=c('Sample',"Gain2-3")))

  Sample Time Mass Gain2-3
1  11  3.0 0.3
2  12  3.1 0.3
3  13  3.4 0.3
4  21  4.0 0.1
5  22  4.3 0.1
6  23  4.4 0.1
7  31  3.0 0.3
8  32  3.2 0.3
9  33  3.5 0.3

You may want to avoid using special characters like dashes in variable
names.

Hope this helps.

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu




On Mon, 17 Sep 2012, Julie Lee-Yaw wrote:


Hi?

I have a dataframe similar to:


Sample<-c(1,1,1,2,2,2,3,3,3)



Time<-c(1,2,3,1,2,3,1,2,3)



Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)



mydata<-as.data.frame(cbind(Sample,Time,Mass))



? Sample Time Mass
1 ? ? ?1 ? ?1 ?3.0
2 ? ? ?1 ? ?2 ?3.1
3 ? ? ?1 ? ?3 ?3.4
4 ? ? ?2 ? ?1 ?4.0
5 ? ? ?2 ? ?2 ?4.3
6 ? ? ?2 ? ?3 ?4.4
7 ? ? ?3 ? ?1 ?3.0
8 ? ? ?3 ? ?2 ?3.2
9 ? ? ?3 ? ?3 ?3.5

where for each sample, I've measured mass at different points in time.?

I now want to calculate the difference between Mass at Time 2 and 3 for each unique 
Sample and store this as a new variable called "Gain2-3". So in my example 
three values of 0.3,0.1,0.3 would be calculated for my three unique samples and these 
values would be repeated in the table according to Sample. I am thus expecting:


mydata #after adding new variable


? Sample Time MassGain2-3
1 ? ? ?1 ? ?1 ?3.00.3
2 ? ? ?1 ? ?2 ?3.1 0.3
3 ? ? ?1 ? ?3 ?3.4 0.3
4 ? ? ?2 ? ?1 ?4.0 0.1
5 ? ? ?2 ? ?2 ?4.3 0.1
6 ? ? ?2 ? ?3 ?4.4 0.1
7 ? ? ?3 ? ?1 ?3.0 0.3
8 ? ? ?3 ? ?2 ?3.2 0.3
9 ? ? ?3 ? ?3 ?3.5 0.3

Does anyone have any suggestions as to how to do this? I've looked at the 
various apply functions but I can't seem to make anything work. I'm fairly new 
to R and would appreciate specific suggestions.?

Thanks!
[[alternative HTML version deleted]]




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


Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread Rui Barradas
Hello,

Try the following.

sp <- split(mydata, mydata$Sample)
do.call(rbind, lapply(sp, function(x){x$Gain <- x$Mass[3] - x$Mass[2]; x}))

Hope this helps,

Rui Barradas
Em 18-09-2012 00:15, Julie Lee-Yaw escreveu:
> Hi
>
> I have a dataframe similar to:
>
>> Sample<-c(1,1,1,2,2,2,3,3,3)
>> Time<-c(1,2,3,1,2,3,1,2,3)
>> Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)
>> mydata<-as.data.frame(cbind(Sample,Time,Mass))
>
>Sample Time Mass
> 1  11  3.0
> 2  12  3.1
> 3  13  3.4
> 4  21  4.0
> 5  22  4.3
> 6  23  4.4
> 7  31  3.0
> 8  32  3.2
> 9  33  3.5
>
> where for each sample, I've measured mass at different points in time.
>
> I now want to calculate the difference between Mass at Time 2 and 3 for each 
> unique Sample and store this as a new variable called "Gain2-3". So in my 
> example three values of 0.3,0.1,0.3 would be calculated for my three unique 
> samples and these values would be repeated in the table according to Sample. 
> I am thus expecting:
>
>> mydata #after adding new variable
>Sample Time MassGain2-3
> 1  11  3.00.3
> 2  12  3.1 0.3
> 3  13  3.4 0.3
> 4  21  4.0 0.1
> 5  22  4.3 0.1
> 6  23  4.4 0.1
> 7  31  3.0 0.3
> 8  32  3.2 0.3
> 9  33  3.5 0.3
>
> Does anyone have any suggestions as to how to do this? I've looked at the 
> various apply functions but I can't seem to make anything work. I'm fairly 
> new to R and would appreciate specific suggestions.
>
> Thanks!
>   [[alternative HTML version deleted]]
>
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


[[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 with calculation from dataframe with multiple entries per sample

2012-09-17 Thread David Winsemius

On Sep 17, 2012, at 4:15 PM, Julie Lee-Yaw wrote:

> Hi 
> 
> I have a dataframe similar to:
> 
>> Sample<-c(1,1,1,2,2,2,3,3,3)
> 
>> Time<-c(1,2,3,1,2,3,1,2,3)
> 
>> Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)
> 
>> mydata<-as.data.frame(cbind(Sample,Time,Mass))
> 
Please tell me where you learned that as.data.frame(cbind(.)) construction.

> (
>   Sample Time Mass
> 1  11  3.0
> 2  12  3.1
> 3  13  3.4
> 4  21  4.0
> 5  22  4.3
> 6  23  4.4
> 7  31  3.0
> 8  32  3.2
> 9  33  3.5
> 
> where for each sample, I've measured mass at different points in time. 
> 
> I now want to calculate the difference between Mass at Time 2 and 3 for each 
> unique Sample and store this as a new variable called "Gain2-3". So in my 
> example three values of 0.3,0.1,0.3 would be calculated for my three unique 
> samples and these values would be repeated in the table according to Sample. 
> I am thus expecting:
> 
>> mydata #after adding new variable

mydata$gain2.3 <- with( mydata, ave( Mass , Time, FUN=function(x) 
diff(x[2],x[3]) ) )
> 
>   Sample Time MassGain2-3
> 1  11  3.00.3
> 2  12  3.1 0.3
> 3  13  3.4 0.3
> 4  21  4.0 0.1
> 5  22  4.3 0.1
> 6  23  4.4 0.1
> 7  31  3.0 0.3
> 8  32  3.2 0.3
> 9  33  3.5 0.3
> 

> mydata$gain2.3 <- with( mydata, ave( Mass , Sample, FUN=function(x) 
> (x[3]-x[2]) ) )
> mydata
  Sample Time Mass gain2.3
1  11  3.0 0.3
2  12  3.1 0.3
3  13  3.4 0.3
4  21  4.0 0.1
5  22  4.3 0.1
6  23  4.4 0.1
7  31  3.0 0.3
8  32  3.2 0.3
9  33  3.5 0.3

> Does anyone have any suggestions as to how to do this? I've looked at the 
> various apply functions but I can't seem to make anything work. I'm fairly 
> new to R and would appreciate specific suggestions. 

-- 
David Winsemius, MD
Alameda, CA, USA

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


Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread David Winsemius

On Sep 17, 2012, at 5:00 PM, David Winsemius wrote:

> 
> On Sep 17, 2012, at 4:15 PM, Julie Lee-Yaw wrote:
> 
>> Hi 
>> 
>> I have a dataframe similar to:
>> 
>>> Sample<-c(1,1,1,2,2,2,3,3,3)
>> 
>>> Time<-c(1,2,3,1,2,3,1,2,3)
>> 
>>> Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)
>> 
>>> mydata<-as.data.frame(cbind(Sample,Time,Mass))
>> 
> Please tell me where you learned that as.data.frame(cbind(.)) construction.
> 
>> (
>>  Sample Time Mass
>> 1  11  3.0
>> 2  12  3.1
>> 3  13  3.4
>> 4  21  4.0
>> 5  22  4.3
>> 6  23  4.4
>> 7  31  3.0
>> 8  32  3.2
>> 9  33  3.5
>> 
>> where for each sample, I've measured mass at different points in time. 
>> 
>> I now want to calculate the difference between Mass at Time 2 and 3 for each 
>> unique Sample and store this as a new variable called "Gain2-3". So in my 
>> example three values of 0.3,0.1,0.3 would be calculated for my three unique 
>> samples and these values would be repeated in the table according to Sample. 
>> I am thus expecting:
>> 
>>> mydata #after adding new variable
> 
> mydata$gain2.3 <- with( mydata, ave( Mass , Time, FUN=function(x) 
> diff(x[2],x[3]) ) )

OOOPpps   the code above was a failed attempt.
>> 
>>  Sample Time MassGain2-3
>> 1  11  3.00.3
>> 2  12  3.1 0.3
>> 3  13  3.4 0.3
>> 4  21  4.0 0.1
>> 5  22  4.3 0.1
>> 6  23  4.4 0.1
>> 7  31  3.0 0.3
>> 8  32  3.2 0.3
>> 9  33  3.5 0.3


... the code below should "work".

>> 
> 
>> mydata$gain2.3 <- with( mydata, ave( Mass , Sample, FUN=function(x) 
>> (x[3]-x[2]) ) )
>> mydata
>  Sample Time Mass gain2.3
> 1  11  3.0 0.3
> 2  12  3.1 0.3
> 3  13  3.4 0.3
> 4  21  4.0 0.1
> 5  22  4.3 0.1
> 6  23  4.4 0.1
> 7  31  3.0 0.3
> 8  32  3.2 0.3
> 9  33  3.5 0.3
> 
>> Does anyone have any suggestions as to how to do this? I've looked at the 
>> various apply functions but I can't seem to make anything work. I'm fairly 
>> new to R and would appreciate specific suggestions. 
> 
> -- 
> David Winsemius, MD
> Alameda, CA, USA
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread Rui Barradas

Or diff(x[2:3])

Rui Barradas
Em 18-09-2012 01:05, David Winsemius escreveu:

On Sep 17, 2012, at 5:00 PM, David Winsemius wrote:


On Sep 17, 2012, at 4:15 PM, Julie Lee-Yaw wrote:


Hi

I have a dataframe similar to:


Sample<-c(1,1,1,2,2,2,3,3,3)
Time<-c(1,2,3,1,2,3,1,2,3)
Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)
mydata<-as.data.frame(cbind(Sample,Time,Mass))

Please tell me where you learned that as.data.frame(cbind(.)) construction.


(
  Sample Time Mass
1  11  3.0
2  12  3.1
3  13  3.4
4  21  4.0
5  22  4.3
6  23  4.4
7  31  3.0
8  32  3.2
9  33  3.5

where for each sample, I've measured mass at different points in time.

I now want to calculate the difference between Mass at Time 2 and 3 for each unique 
Sample and store this as a new variable called "Gain2-3". So in my example 
three values of 0.3,0.1,0.3 would be calculated for my three unique samples and these 
values would be repeated in the table according to Sample. I am thus expecting:


mydata #after adding new variable

mydata$gain2.3 <- with( mydata, ave( Mass , Time, FUN=function(x) 
diff(x[2],x[3]) ) )

OOOPpps   the code above was a failed attempt.

  Sample Time MassGain2-3
1  11  3.00.3
2  12  3.1 0.3
3  13  3.4 0.3
4  21  4.0 0.1
5  22  4.3 0.1
6  23  4.4 0.1
7  31  3.0 0.3
8  32  3.2 0.3
9  33  3.5 0.3


... the code below should "work".


mydata$gain2.3 <- with( mydata, ave( Mass , Sample, FUN=function(x) (x[3]-x[2]) 
) )
mydata

  Sample Time Mass gain2.3
1  11  3.0 0.3
2  12  3.1 0.3
3  13  3.4 0.3
4  21  4.0 0.1
5  22  4.3 0.1
6  23  4.4 0.1
7  31  3.0 0.3
8  32  3.2 0.3
9  33  3.5 0.3


Does anyone have any suggestions as to how to do this? I've looked at the 
various apply functions but I can't seem to make anything work. I'm fairly new 
to R and would appreciate specific suggestions.

--
David Winsemius, MD
Alameda, CA, USA

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

David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Parsing "back" to API strcuture

2012-09-17 Thread Eric Fail
Problem solved by Josh O'Brien on stackoverflow,
http://stackoverflow.com/questions/12393004/parsing-back-to-messy-api-strcuture/12435389#12435389

some_magic <- function(df) {
## Replace NA with "", converting column types as needed
df[] <- lapply(df, function(X) {
if(any(is.na(X))) {X[is.na(X)] <- ""; X} else {X}
})

## Print integers in first column as 2-digit character strings
## (DO NOTE: Hardwiring the number of printed digits here is probably
## inadvisable, though needed to _exactly_ reconstitute RAW.API.)
df[[1]] <- sprintf("%02.0f", df[[1]])

## Separately build header and table body, then suture them together
l1 <- paste(names(df), collapse=",")
l2 <- capture.output(write.table(df, sep=",", col.names=FALSE,
 row.names=FALSE))
out <- paste0(c(l1, l2, ""), collapse="\n")

## Reattach attributes
att <- list("`Content-Type`" = structure(c("text/html", "utf-8"),
.Names = c("", "charset")))
attributes(out) <- att
out
}

identical(some_magic(df), RAW.API)
# [1] TRUE


On Thu, Sep 13, 2012 at 11:32 AM, Eric Fail  wrote:
> Dear Jim,
>
> Thank you for your response I appreciate your effort!
>
> It is close, I must admit that. What I am looking for is an object
> that is identical to 'RAW.API,' or at least in the stricture (I guess
> i do not need the ","`Content-Type`" = structure(c("text/html",
> "utf-8"), .Names = c("",
> "charset")))" part.
>
> When I investigate 'x.out' it also have the NA's. I've tried to fix
> it, but I had to give up. It is strange because getting there seems so
> easy (warning false logic!).
>
> Here is what I got on my looong and alternative route in the hope that
> someone on the list might be able to help
>
> RAW.API <- 
> structure("id,event_arm,name,dob,pushed_text,pushed_calc,complete\n\"01\",\"event_1_arm_1\",\"John\",\"1979-05-01\",\"\",\"\",2\n\"01\",\"event_2_arm_1\",\"John\",\"2012-09-02\",\"abc\",\"123\",1\n\"01\",\"event_3_arm_1\",\"John\",\"2012-09-10\",\"\",\"\",2\n\"02\",\"event_1_arm_1\",\"Mary\",\"1951-09-10\",\"def\",\"456\",2\n\"02\",\"event_2_arm_1\",\"Mary\",\"1978-09-12\",\"\",\"\",2\n",
> "`Content-Type`" = structure(c("text/html", "utf-8"), .Names =
> c("","charset")))
>
> # I used an alternative way of converting it to a dataset to keep the
> leading 0 in the id variables
> x <- read.table(file = textConnection(RAW.API ), header = TRUE, sep =
> ",", na.strings = "", stringsAsFactors = FALSE, colClasses ="character")
> x
>
>  # now put it back into the same string; write.csv does quote alphanumerics
> write.csv(x, textConnection('output', 'w'), row.names = FALSE)
> unlockBinding("output", env = .GlobalEnv)
> # fixes the problem with the header
> output[1] <- gsub("\\\"", "", output[1])
> # removes NAs
> output <- gsub("NA", "\"\"", output)
> # removes "\ at the beginning of each line
> output <- gsub("^\\\"", "", output)
> # removes an " at the end of each line
> output <- gsub("\\\"$", "", output)
> # same as before
> x.out <- paste(output, collapse = '\n\"')
> # adds an line break at the end
> x.out <- gsub("$", "\n", x.out)
>
> # so much manual gsub ...
>
> Any help would be very much appreciated.
>
> On Wed, Sep 12, 2012 at 5:54 PM, jim holtman  wrote:
>> This is close, but it does quote the header names, but does produce
>> the same dataframe when read back in:
>>
>>> RAW.API <- 
>>> structure("id,event_arm,name,dob,pushed_text,pushed_calc,complete\n\"01\",\"event_1_arm_1\",\"John\",\"1979-05-01\",\"\",\"\",2\n\"01\",\"event_2_arm_1\",\"John\",\"2012-09-02\",\"abc\",\"123\",1\n\"01\",\"event_3_arm_1\",\"John\",\"2012-09-10\",\"\",\"\",2\n\"02\",\"event_1_arm_1\",\"Mary\",\"1951-09-10\",\"def\",\"456\",2\n\"02\",\"event_2_arm_1\",\"Mary\",\"1978-09-12\",\"\",\"\",2\n",
>>>  "`Content-Type`" = structure(c("text/html", "utf-8"), .Names = c("", 
>>> "charset")))
>>> x <- read.csv(textConnection(RAW.API), as.is = TRUE)
>>> x
>>   id event_arm namedob pushed_text pushed_calc complete
>> 1  1 event_1_arm_1 John 1979-05-01  NA2
>> 2  1 event_2_arm_1 John 2012-09-02 abc 1231
>> 3  1 event_3_arm_1 John 2012-09-10  NA2
>> 4  2 event_1_arm_1 Mary 1951-09-10 def 4562
>> 5  2 event_2_arm_1 Mary 1978-09-12  NA2
>>>
>>> # now put it back into the same string; write.csv does quote alphanumerics
>>> write.csv(x, textConnection('output', 'w'), row.names = FALSE)
>>> x.out <- paste(output, collapse = '\n')
>>> # read it back in to show it is the same
>>> x.in <- read.csv(textConnection(x.out), as.is = TRUE)
>>> x.in
>>   id event_arm namedob pushed_text pushed_calc complete
>> 1  1 event_1_arm_1 John 1979-05-01  NA2
>> 2  1 event_2_arm_1 John 2012-09-02 abc 1231
>> 3  1 event_3_arm_1 John 2012-09-10  NA2
>

[R] chunk row to new table/file

2012-09-17 Thread s.s.m. fauzi
I have big .csv file. I would like to filter that file into a new table.


For example, I have .csv file as below:




   f1 f2  f3 f4  f5  f6 f7 f9  f10  f11
t1  1  0  1   0  1  0   0  0   01
t2  1  0  0   0  0  1   1  1   11
t3  0  0  0   0  0  0   0  0   00
t4  1  0  0   0  1  0   0  0   00
t5  0  0  0   0  0  0   0  0   00
t6  0  0  0   0  0  0   0  0   00

1. I have a table (as above)

2. What I want to do is, I want to chunk a new table for each row (meaning
that, I will have new table for row t1, new table for row t2, new table for
row t3 and etc)

3. To develop new table for each row, there is a condition that need to
meet.  The row should be grouped with other row which have the same value
in column
(as in my example, row t1,t2,t4 should be grouped together because value in
column f1 have the same value (which is 1) with the value in f1 for row t2
and t4, also value in f5 is equal with the value in f5 for row t4, and
value in f11 is equal with the value in f11 for row t2). Output for should
be like this:


   f1 f2  f3 f4  f5  f6 f7 f9  f10  f11
t1  1  0  1   0  1  0   0  0   01
t2  1  0  0   0  0  1   1  1   11
t4  1  0  0   0  1  0   0  0   00

4. Also as we can see from the above table, t2 also should have another
table because value in f1 in t1 and value f1 in t4 is equal. However, t2
should not consider t1. Output should be like this:

  f1 f2  f3 f4  f5  f6 f7 f9  f10  f11
t2  1  0  0   0  0  1   1  1   11
t4  1  0  0   0  1  0   0  0   00




New table(s) (with row and column header) should be then saved in a new .
csvfile.

Appreciate help from the expert!

[[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] chunk row to new table/file

2012-09-17 Thread David Winsemius

On Sep 17, 2012, at 6:27 PM, s.s.m. fauzi wrote:

> I have big .csv file. I would like to filter that file into a new table.
> 
> 
> For example, I have .csv file as below:
> 
> 
> 
> 
>   f1 f2  f3 f4  f5  f6 f7 f9  f10  f11
>t1  1  0  1   0  1  0   0  0   01
>t2  1  0  0   0  0  1   1  1   11
>t3  0  0  0   0  0  0   0  0   00
>t4  1  0  0   0  1  0   0  0   00
>t5  0  0  0   0  0  0   0  0   00
>t6  0  0  0   0  0  0   0  0   00

Answered on SO where this all began. In R-help you are asked not to cross-post.
http://stackoverflow.com/questions/12453483/creating-new-table-from-a-big-csv-table/12468243#comment16773052_12468243--
 
David.
> 
> 1. I have a table (as above)
> 
> 2. What I want to do is, I want to chunk a new table for each row (meaning
> that, I will have new table for row t1, new table for row t2, new table for
> row t3 and etc)
> 
> 3. To develop new table for each row, there is a condition that need to
> meet.  The row should be grouped with other row which have the same value
> in column
> (as in my example, row t1,t2,t4 should be grouped together because value in
> column f1 have the same value (which is 1) with the value in f1 for row t2
> and t4, also value in f5 is equal with the value in f5 for row t4, and
> value in f11 is equal with the value in f11 for row t2). Output for should
> be like this:
> 
> 
>   f1 f2  f3 f4  f5  f6 f7 f9  f10  f11
>t1  1  0  1   0  1  0   0  0   01
>t2  1  0  0   0  0  1   1  1   11
>t4  1  0  0   0  1  0   0  0   00
> 
> 4. Also as we can see from the above table, t2 also should have another
> table because value in f1 in t1 and value f1 in t4 is equal. However, t2
> should not consider t1. Output should be like this:
> 
>  f1 f2  f3 f4  f5  f6 f7 f9  f10  f11
>t2  1  0  0   0  0  1   1  1   11
>t4  1  0  0   0  1  0   0  0   00
> 
> 
> 
> 
> New table(s) (with row and column header) should be then saved in a new .
> csvfile.
> 
> Appreciate help from the expert!
> 
>   [[alternative HTML version deleted]]
-- 

David Winsemius, MD
Alameda, CA, USA

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

2012-09-17 Thread Champika Shyamalie Kariyawasam
Hi all,

I 'm doing the exercise given in the 'SDM with R' (Robert J. Hijmans and Jane 
Elith), chapter 4.2, regarding extracting values . I tried to do the same using 
my own data as well. Each cases i received the following error message ;

"Error in .xyValues(x, as.matrix(y), ...) : xy should have 2 columns only.

Found these dimensions:

Can some body explain me how to get rid of that? Thanks in advance.

champika

[[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 with calculation from dataframe with multiple entries per sample

2012-09-17 Thread arun
HI,
Try this:
 mydata$Gain<-rep(tapply(mydata$Mass,mydata$Sample,FUN=function(x) 
(x[3]-x[2])),each=length(unique(mydata$Sample)))
 mydata
#  Sample Time Mass Gain
#1  1    1  3.0  0.3
#2  1    2  3.1  0.3
#3  1    3  3.4  0.3
#4  2    1  4.0  0.1
#5  2    2  4.3  0.1
#6  2    3  4.4  0.1
#7  3    1  3.0  0.3
#8  3    2  3.2  0.3
#9  3    3  3.5  0.3
A.K.




- Original Message -
From: Julie Lee-Yaw 
To: "r-help@r-project.org" 
Cc: 
Sent: Monday, September 17, 2012 7:15 PM
Subject: [R] help with calculation from dataframe with multiple entries per 
sample

Hi 

I have a dataframe similar to:

>Sample<-c(1,1,1,2,2,2,3,3,3)

>Time<-c(1,2,3,1,2,3,1,2,3)

>Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)

>mydata<-as.data.frame(cbind(Sample,Time,Mass))


  Sample Time Mass
1      1    1  3.0
2      1    2  3.1
3      1    3  3.4
4      2    1  4.0
5      2    2  4.3
6      2    3  4.4
7      3    1  3.0
8      3    2  3.2
9      3    3  3.5

where for each sample, I've measured mass at different points in time. 

I now want to calculate the difference between Mass at Time 2 and 3 for each 
unique Sample and store this as a new variable called "Gain2-3". So in my 
example three values of 0.3,0.1,0.3 would be calculated for my three unique 
samples and these values would be repeated in the table according to Sample. I 
am thus expecting:

>mydata #after adding new variable

  Sample Time MassGain2-3
1      1    1  3.00.3
2      1    2  3.1 0.3
3      1    3  3.4 0.3
4      2    1  4.0 0.1
5      2    2  4.3 0.1
6      2    3  4.4 0.1
7      3    1  3.0 0.3
8      3    2  3.2 0.3
9      3    3  3.5 0.3

Does anyone have any suggestions as to how to do this? I've looked at the 
various apply functions but I can't seem to make anything work. I'm fairly new 
to R and would appreciate specific suggestions. 

Thanks!
    [[alternative HTML version deleted]]


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


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


Re: [R] help with calculation from dataframe with multiple entries per sample

2012-09-17 Thread arun
HI,
Modified version of my earlier solution:
res1<-tapply(mydata$Mass,mydata$Sample,FUN=function(x) (x[3]-x[2]))
res2<-data.frame(Sample=names(res1),Gain2_3=res1)
 merge(mydata,res2)

#Sample Time Mass Gain2_3
#1  1    1  3.0 0.3
#2  1    2  3.1 0.3
#3  1    3  3.4 0.3
#4  2    1  4.0 0.1
#5  2    2  4.3 0.1
#6  2    3  4.4 0.1
#7  3    1  3.0 0.3
#8  3    2  3.2 0.3
#9  3    3  3.5 0.3
A.K.



- Original Message -
From: Julie Lee-Yaw 
To: "r-help@r-project.org" 
Cc: 
Sent: Monday, September 17, 2012 7:15 PM
Subject: [R] help with calculation from dataframe with multiple entries per 
sample

Hi 

I have a dataframe similar to:

>Sample<-c(1,1,1,2,2,2,3,3,3)

>Time<-c(1,2,3,1,2,3,1,2,3)

>Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)

>mydata<-as.data.frame(cbind(Sample,Time,Mass))


  Sample Time Mass
1      1    1  3.0
2      1    2  3.1
3      1    3  3.4
4      2    1  4.0
5      2    2  4.3
6      2    3  4.4
7      3    1  3.0
8      3    2  3.2
9      3    3  3.5

where for each sample, I've measured mass at different points in time. 

I now want to calculate the difference between Mass at Time 2 and 3 for each 
unique Sample and store this as a new variable called "Gain2-3". So in my 
example three values of 0.3,0.1,0.3 would be calculated for my three unique 
samples and these values would be repeated in the table according to Sample. I 
am thus expecting:

>mydata #after adding new variable

  Sample Time MassGain2-3
1      1    1  3.00.3
2      1    2  3.1 0.3
3      1    3  3.4 0.3
4      2    1  4.0 0.1
5      2    2  4.3 0.1
6      2    3  4.4 0.1
7      3    1  3.0 0.3
8      3    2  3.2 0.3
9      3    3  3.5 0.3

Does anyone have any suggestions as to how to do this? I've looked at the 
various apply functions but I can't seem to make anything work. I'm fairly new 
to R and would appreciate specific suggestions. 

Thanks!
    [[alternative HTML version deleted]]


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


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


[R] How to convert R script to standalone executable?

2012-09-17 Thread Jingwan Li
Hi all,

Can anyone tell me how to convert a R script to a standalone executable
that can be installed and run on any Windows machines?
Thanks in advance.

Jingwan

[[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 with calculation from dataframe with multiple entries per sample

2012-09-17 Thread David Winsemius

On Sep 17, 2012, at 7:28 PM, arun wrote:

> HI,
> Try this:
>  mydata$Gain<-rep(tapply(mydata$Mass,mydata$Sample,FUN=function(x) 
> (x[3]-x[2])),each=length(unique(mydata$Sample)))
>  mydata
> #  Sample Time Mass Gain
> #1  11  3.0  0.3
> #2  12  3.1  0.3
> #3  13  3.4  0.3
> #4  21  4.0  0.1
> #5  22  4.3  0.1
> #6  23  4.4  0.1
> #7  31  3.0  0.3
> #8  32  3.2  0.3
> #9  33  3.5  0.3
> A.K.

That is going to fail as soon as there are an uneven number of rows for one 
value of Sample.

> Sample<-c(1,1,1,2,2,2,3,3,3,3)
> Time<-c(1,2,3,1,2,3,1,2,3, 4)
> Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5, 3.7)
> mydata<-as.data.frame(cbind(Sample,Time,Mass))
>  mydata$Gain<-rep(tapply(mydata$Mass,mydata$Sample,FUN=function(x) 
> (x[3]-x[2])),each=length(unique(mydata$Sample)))
Error in `$<-.data.frame`(`*tmp*`, "Gain", value = c(0.3, 0.3, 0.3, 
0.101,  : 
  replacement has 9 rows, data has 10


> 
> 
> 
> 
> - Original Message -
> From: Julie Lee-Yaw 
> To: "r-help@r-project.org" 
> Cc: 
> Sent: Monday, September 17, 2012 7:15 PM
> Subject: [R] help with calculation from dataframe with multiple entries per 
> sample
> 
> Hi 
> 
> I have a dataframe similar to:
> 
>> Sample<-c(1,1,1,2,2,2,3,3,3)
> 
>> Time<-c(1,2,3,1,2,3,1,2,3)
> 
>> Mass<-c(3,3.1,3.4,4,4.3,4.4,3,3.2,3.5)
> 
>> mydata<-as.data.frame(cbind(Sample,Time,Mass))
> 
> 
>   Sample Time Mass
> 1  11  3.0
> 2  12  3.1
> 3  13  3.4
> 4  21  4.0
> 5  22  4.3
> 6  23  4.4
> 7  31  3.0
> 8  32  3.2
> 9  33  3.5
> 
> where for each sample, I've measured mass at different points in time. 
> 
> I now want to calculate the difference between Mass at Time 2 and 3 for each 
> unique Sample and store this as a new variable called "Gain2-3". So in my 
> example three values of 0.3,0.1,0.3 would be calculated for my three unique 
> samples and these values would be repeated in the table according to Sample. 
> I am thus expecting:
> 
>> mydata #after adding new variable
> 
>   Sample Time MassGain2-3
> 1  11  3.00.3
> 2  12  3.1 0.3
> 3  13  3.4 0.3
> 4  21  4.0 0.1
> 5  22  4.3 0.1
> 6  23  4.4 0.1
> 7  31  3.0 0.3
> 8  32  3.2 0.3
> 9  33  3.5 0.3
> 
> Does anyone have any suggestions as to how to do this? I've looked at the 
> various apply functions but I can't seem to make anything work. I'm fairly 
> new to R and would appreciate specific suggestions. 
> 
> Thanks!
> [[alternative HTML version deleted]]
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

David Winsemius, MD
Alameda, CA, USA

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

2012-09-17 Thread Raoni Rodrigues
Hello all,

I'm new in R, and I have a data-frame like this (dput information below):

Specie   Fooditem Occurrence Volume
1  Schizodonvegetal  1   0.05
2  Schizodon   sediment  1   0.60
3  Schizodonvegetal  1   0.15
4  Schizodon   alga  1   0.05
5  Schizodon   sediment  1   0.90
6  Schizodon   sediment  1   0.30
7  Schizodon   sediment  1   0.90
8   Astyanax terrestrial_insect  1   0.10
9   Astyanaxvegetal  1   0.85
10  Astyanax   aquatical_insect  1   0.05
11  Astyanaxvegetal  1   0.90
12  Astyanax  un_insect  1   0.85


for each specie, I have to calculate a food item importance index, that is:

Fi x Vi / Sum (Fi x Vi)

Fi  = percentual frequency of occurrence of a food item
Vi = percentual volume of a food item

So, using ddply (plyr) function, I was able to calculate the total
frequency of occurrence and total volume of each food item, using:

Frequency = ddply (dieta, c('Specie','Fooditem') , summarise,
Frequency = sum (Occurrence))

Volume = ddply (dieta, c('Specie','Fooditem') , summarise, Volume =
sum (Volume))

and calculate total frequency and total volume for a given specie:

TFrequency = ddply (Frequency, 'Specie' , summarise, TF = sum (Frequency))

TVolume = ddply (dieta, c('Specie') , summarise, Volume = sum (Volume))

but once they have different length, I could not use together to
create a percentage needed in my formula.

Any suggestions?

Thanks in advanced for help and attention,

Raoni

dput (diet)

structure(list(Specie = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 1L), .Label = c("Astyanax", "Schizodon"), class = "factor"),
Fooditem = structure(c(6L, 3L, 6L, 1L, 3L, 3L, 3L, 4L, 6L,
2L, 6L, 5L), .Label = c("alga", "aquatical_insect", "sediment",
"terrestrial_insect", "un_insect", "vegetal"), class = "factor"),
Occurrence = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), Volume = c(0.05, 0.6, 0.15, 0.05, 0.9, 0.3, 0.9, 0.1,
0.85, 0.05, 0.9, 0.85)), .Names = c("Specie", "Fooditem",
"Occurrence", "Volume"), class = "data.frame", row.names = c(NA,
-12L))

sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)
Windows XP
-- 
Raoni Rosa Rodrigues
Research Associate of Fish Transposition Center CTPeixes
Universidade Federal de Minas Gerais - UFMG
Brasil
rodrigues.ra...@gmail.com

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


[R] S4, polymorphism, and parallelization

2012-09-17 Thread Fernando Saldanha
I am running Rmpi and MPICH2 to do parallelization in a Windows 7 machine.
I am only using my PC's cores. Parallelization for standard R code works
fine. For S4 code I am having the following problem:

Let us say I have a class A and a subclasses B and C (both B and C
"contains" A). I declared a method

setGeneric(
name = "superClassMethod",
 def = function(object) {standardGeneric("superClassMethod")}
)
setMethod(
f = "superClassMethod",
 signature = "A",
definition = function(object) {
# Some code here
 }
)

At some point I call function paralapply (similar to parLapply) in this way

my.list <- paralapply(some.other.list, superClassMethod, papply_commondata
= envir.vars)

Then I get an error message as follows:

Error message: Error in function (classes, fdef, mtable)  :
  unable to find an inherited method for function "superClassMethod", for
signature "B"

Error in paralapply(some.other.list, superClassMethod, papply_commondata =
envir.vars)

On the other hand, if I redefine the method for classes B and C as follows:

setMethod(
f = "superClassMethod",
signature = "B",
 definition = function(object) {
# Some code here
}
)

setMethod(
f = "superClassMethod",
signature = "C",
 definition = function(object) {
# Some code here
}
)

Obviously this goes against the idea of polymorphism.

How can I solve this problem?

Thanks for any help.

Fernando Saldanha

[[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] Boxplot lattice vs standard graphics

2012-09-17 Thread Massimo Bressan

ok, I see now!
here it is the reproducible example along with the final code (aslo with 
the median line instead of a point)


thank you all for the great help

max

# start code

library(lattice)

test<-structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L), .Label = c("A",
"B", "C", "D", "E"), class = "factor"), conc = c(2.32, 0.902,
0.468, 5.51, 1.49, 0.532, 0.72, 0.956, 0.887, 20, 30, 2.12, 0.442,
10, 50, 110, 3.36, 2.41, 20, 70, 3610, 100, 4.79, 20, 0.0315,
30, 60, 1, 3.37, 80, 1.21, 0.302, 0.728, 1.29, 30, 40, 90, 30,
0.697, 6.25, 0.576, 0.335, 20, 10, 620, 40, 9.98, 4.76, 2.61,
3.39, 20, 4.59)), .Names = c("site", "conc"), row.names = c(NA,
52L), class = "data.frame")

mystats <- function(x, ...){ # Here ...
  out <- boxplot.stats(10^x, ...)  # ...and here!!!
  out$stats <- log10(out$stats)
  out$conf <- log10(out$conf) ## Omit if you don't want notches
  out$out <- log10(out$out)
  out ## With the boxplot statistics converted to the log10 scale
}

dev.new()
bwplot(conc~site, data=test,
   pch="|",  # this is plotting a line instead of a point
   scales = list(y=list(log=10)),
   panel = function(...){
 panel.bwplot(..., stats = mystats)
   }
)

# end code

Il 17/09/2012 20:26, Rui Barradas ha scritto:

Hello,

Em 17-09-2012 18:50, David Winsemius escreveu:

On Sep 17, 2012, at 4:18 AM, maxbre wrote:

here it is, I think (I hope)  I'm getting a little closer with this, 
but

still there is something  to sort out...

error using packet 1
unused argument(s)  (coef =1.5, do.out=TRUE)

by reading the help for panel.bwplot at the argument "stats" it 
says: "the
function must accept arguments coef and do.out even if they do not 
use them

(a ... argument is good enough). "
I'm not sure how to couple with this...

any help for this ?

thanks


## start code


mystats <- function(x){
  out <- boxplot.stats(10^x)
  out$stats <- log10(out$stats)
  out$conf <- log10(out$conf) ## Omit if you don't want notches
  out$out <- log10(out$out)
  out$coef<-1.5 #??
  out$do.out<-"TRUE" #??
  out ## With the boxplot statistics converted to the log10 scale
}

bwplot(conc~site, data=test,
   scales=list(y=list(log=10)),
   panel= function(x,y){
 panel.bwplot(x,y,stats=mystats)
   }
   )

No example data, so no efforts at running code.


Actually there is, in the op.



?panel.bwplot

# Notice the Usage at the top of the page. The "..." is there for a 
reason.


# And notice that neither 'do.out' nor 'coef' are passed in the 
"stats" list


# The message was talking about what arguments your 'mystats' would 
accept,  not what it would return. It's another instance of your 
needing to understand what the "..." formalism is doing.


?boxplot.stats

# I would be making a concerted effort to return a list with exactly 
the components listed there.


And since I'm terrible at graphics I try to learn as much as possible 
on R-Help. Here it goes.



library(lattice)

test<-structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L), .Label = c("A",
"B", "C", "D", "E"), class = "factor"), conc = c(2.32, 0.902,
0.468, 5.51, 1.49, 0.532, 0.72, 0.956, 0.887, 20, 30, 2.12, 0.442,
10, 50, 110, 3.36, 2.41, 20, 70, 3610, 100, 4.79, 20, 0.0315,
30, 60, 1, 3.37, 80, 1.21, 0.302, 0.728, 1.29, 30, 40, 90, 30,
0.697, 6.25, 0.576, 0.335, 20, 10, 620, 40, 9.98, 4.76, 2.61,
3.39, 20, 4.59)), .Names = c("site", "conc"), row.names = c(NA,
52L), class = "data.frame")


#standard graphics
dev.new()
with(test,boxplot(conc~site, log="y"))

#lattice
mystats <- function(x, ...){ # Here ...
out <- boxplot.stats(10^x, ...)  # ...and here!!!
out$stats <- log10(out$stats)
out$conf <- log10(out$conf) ## Omit if you don't want notches
out$out <- log10(out$out)
out ## With the boxplot statistics converted to the log10 scale
}

dev.new()
bwplot(conc~site, data=test,
   scales = list(y=list(log=10)),
   panel = function(...){
 panel.bwplot(..., stats = mystats)
   }
)

With a median _line_ it would be perfect.
(Not a follow-up, it was already answered some time ago, use pch = "|" 
in panel.bwplot.)


Rui Barradas



## end code







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


Re: [R] How to convert R script to standalone executable?

2012-09-17 Thread David Winsemius

On Sep 17, 2012, at 8:23 PM, Jingwan Li wrote:

> Hi all,
> 
> Can anyone tell me how to convert a R script to a standalone executable
> that can be installed and run on any Windows machines?
> Thanks in advance.

 R is an interpreted language. There is no compiler that creates standalone 
modules.

-- 

David Winsemius, MD
Alameda, CA, USA

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

2012-09-17 Thread Hock Ann Lim
Dear Rui Barrada,
 
Thank you so much for your kind sharing. It's really help.
 
Regards,
Lim Hock Ann
 


 From: Rui Barradas 

Cc: R-Help  
Sent: Tuesday, September 18, 2012 12:03 AM
Subject: Re: [R] Problem with Stationary Bootstrap
  

Hello,

The problem is your function calling itself until there's no more
stack memory left.
Besides, your function doesn't make any sense. You pass an argument
'fit' then do not used it but change it's value then return itself.
Corrected:

set.seed(1)
X <- runif(10, 0, 10)
Y <- 2 + 3*X
a <- data.frame(X = X, Y = Y)

fun <- function(a){
  fit <- lm(Y ~ X, data=a)
  return(coef(fit))
}
result <- boot::tsboot(a, statistic = fun, R = 10, sim = "geom",
l = 10, orig.t = TRUE)

Hope this helps,

Rui Barradas


Em 17-09-2012 14:42, Hock Ann Lim escreveu:

Dear R experts,
 
I'm running the following stationary bootstrap programming to find the 
parameters estimate of a linear model:  
 
X<-runif(10,0,10)
Y<-2+3*X
a<-data.frame(X,Y)
coef<-function(fit){
  fit <- lm(Y~X,data=a)
   return(coef(fit))
}
 result<- tsboot(a,statistic=coef(fit),R = 10,n.sim = NROW(a),sim = 
"geom",orig.t = TRUE)
 
Unfortunately, I got this error message from R:
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Can someone tells me what's wrong in the programming.
 
Thank you.
 
Regards,
Lim Hock Ann [[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] creating graphs using Rook

2012-09-17 Thread punitha
hi,

  I m said to display graph in browser using Rook.
So i found a code i.e
library(Rook) # for web functionality 
library(ggplot2) # for graphing 
library(tseries) # used to grab time series from yahoo for stock symbols 
library(plyr) # data tweaks 
 
PIC.DIR = paste(getwd(), 'pic', sep='/') 
 
# define the web page form 
newapp = function(env) { 
req = Rook::Request$new(env) 
res = Rook::Response$new() 
 
if (!is.null(req$POST())) { 
stock.symbol <- req$POST()[["stock.symbol"]] 
day.window <- req$POST()[["day.window"]] 
} else { 
stock.symbol <- 'AAPL' 
day.window <- 60 
} 
res$write('What stock ticker would you like to see:\n') 
res$write('') 
res$write('Stock Symbol:\n') 
res$write('\n') 
stock.input <- paste('\n', sep='') 
res$write( stock.input )  
res$write('\n') 
res$write('30 Days \n') 
res$write('60
Days \n') 
res$write('90 Days \n') 
res$write('\n\n') 
myNormalize = function (target) { 
return((target - min(target))/(max(target) - min(target))) 
} 
 
if (!is.null(req$POST())) { 
# get the stock data as a data frame 
df <-
as.data.frame(get.hist.quote(stock.symbol,start=as.character(Sys.Date() - 
as.numeric(day.window)),quote=c("Open", "High", "Low", "Close"))) 
 
# add an average and the top/bottom for the candle 
df <- mutate(df, Average =(High + Low + Close)/3, Bottom =
pmin(Open, Close), Top = pmax(Open, Close), Open.to.Close = ifelse(sign(Open
- Close) == 1,'Increase','Decrease'), Date = row.names(df), Date.Label =
ifelse(weekdays(as.Date(row.names(df))) == 'Friday',row.names(df),'')) #
this gets the date from row.names into a column 
 
# create a box plot 
my.plot <- ggplot(data=df, aes(x=Date, lower=Bottom, upper=Top,
middle=Average,  ymin=Low,  ymax=High, color=Open.to.Close,
fill=Open.to.Close), xlab='Date', ylab='Price') + 
geom_boxplot(stat='identity') + 
# add the line for average price from HCL 
geom_line(data=df, aes(x=Date,y=Average, group=0),
color='black') + 
# tweak the labeling 
opts(axis.text.x = theme_text(angle=270), legend.position =
'top', legend.direction='horizontal') + 
scale_x_discrete(labels=df$Date.Label) 
ggsave(plot=my.plot, paste(PIC.DIR, "/pic", stock.symbol,
day.window, ".png", sep = "")) 
 
res$write(paste(day.window,' days stock price trend for
',stock.symbol,'', sep='')) 
res$write(paste(" <",  
s$full_url("pic"),  
> ", sep = "")) 
} 
res$finish() 
} 
s = Rhttpd$new() 
s$add(app = newapp, name = "visbin") 
s$add(app = File$new(PIC.DIR), name = "pic") 
s$start() 
s$browse("visbin") 

but when i execute this code i get an error saying
Error in grDevices::png(..., width = width, height = height, res = dpi,  : 
  unable to start png() device

Or Is there any other code which can help me in displaying graph in Rook
using ggplot2





-
Thank you,

with regards,
Punitha
--
View this message in context: 
http://r.789695.n4.nabble.com/creating-graphs-using-Rook-tp4643458.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.