Re: [R] Telling plot() the max y value to expect when plotting one distribution and then using lines() to add more distributions

2012-02-24 Thread R. Michael Weylandt
Easiest thing to do: use the optional ylim argument to plot (taking values like 
c(0, maxhx) or possibly a little wider) which will let you set the bounds 
directly. 

Michael

PS It's possible to get the following to be much more easily extensible using 
loops and what not, but as its very late in my time zone, I'll wait til the 
morning to work it out (for fear of making yet another public mistake :-P) For 
now, note that it's perfectly ok to use

maxhx <- max(hx1, hx2, hx3) 

which will save you a few lines. 

On Feb 24, 2012, at 5:58 PM, FJ M  wrote:

> 
> I am plotting three Pearson Type IV distributions. It looks like I have to 
> plot the distribution with the highest value of y and then use lines() to add 
> the two distributions that are shorter / have lower max values of y. The 
> following code figures out which distribution has the max y value, plots it 
> first and then uses lines for the other two distributions with a series of 
> three if statements. This works. I run R from a batch file that reads the 
> following in a text file.
> 
> I want to graph dozens of distributions and I am looking for a more elegant 
> way to do this.
> 
> New to R, experienced C programmer, thanks in advance. Frank
> 
> 
> 
> colors <- c("red", "blue", "darkgreen", "gold", "black")
> labels <- c("1", "2","3")
> pdf("C:\\Users\\Frank\\Documents\\R\\Scripts\\pt4_Graph.pdf")
> ## load Pearson package
> library(PearsonDS)
> ##range for x axis
> no_of_increments<- 100
> x <- seq(-0.06, +0.06, length=no_of_increments)
> ##parameters for the plots of three distributions
> mx<- c(1.95, 18.35,1.93)
> nux<- c(0.08,-1.02,0.25)
> locationx<- c(0.0048,-0.00254,0.00189)
> scalex<- c(0.0115,0.082187,0.026675)
> ## calculate probability density function
> hx1<- dpearsonIV(x,m=mx[1],nu=nux[1],location=locationx[1],scale=scalex[1])
> hx2<- dpearsonIV(x,m=mx[2],nu=nux[2],location=locationx[2],scale=scalex[2])
> hx3<- dpearsonIV(x,m=mx[3],nu=nux[3],location=locationx[3],scale=scalex[3])
> ##calculate max of each distribtion
> maxhx1<- max(hx1)
> maxhx2<- max(hx2)
> maxhx3<- max(hx3)
> maxhx<- max(hx1,hx2,hx3)
> maxhx1
> maxhx2
> maxhx3
> maxhx
> 
> if (maxhx1==maxhx) 
> {plot(x, hx1 , type="l", lwd=2, col=colors[1], xlab="x value",  
> ylab="Density", main="pt4")
> for (i in 2:3){
>  lines(x, 
> dpearsonIV(x,m=mx[i],nu=nux[i],location=locationx[i],scale=scalex[i]), lwd=2, 
> col=colors[i])}
> legend("topright", inset=.05, title="Distributions",
>  labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors)
> grid()
> }
> 
> if (maxhx2==maxhx) {plot(x, hx2 , type="l", lwd=2, xlab="x value",  
> ylab="Density", main="SPX", col=colors[2])
> {
>  lines(x, 
> dpearsonIV(x,m=mx[1],nu=nux[1],location=locationx[1],scale=scalex[1]), lwd=2, 
> col=colors[1])
>  lines(x, 
> dpearsonIV(x,m=mx[3],nu=nux[3],location=locationx[3],scale=scalex[3]), lwd=2, 
> col=colors[3])
> legend("topright", inset=.05, title="Distributions",
>  labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors)
> grid()
> }
> 
> if (maxhx3==maxhx) 
> {plot(x, hx3 , type="l", lwd=2, col=colors[3], xlab="x value",  
> ylab="Density", main="SPX")
> for (i in 1:2){
>  lines(x, 
> dpearsonIV(x,m=mx[i],nu=nux[i],location=locationx[i],scale=scalex[i]), lwd=2, 
> col=colors[i])}
> legend("topright", inset=.05, title="Distributions",
>  labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors)
> grid()
> }
> 
>   
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Table into a list

2012-02-24 Thread Jorge I Velez
My apologies.  The last line should have been

with(d, sort(c(as.character(x1), as.character(x2

Regards,
Jorge.-


On Sat, Feb 25, 2012 at 2:03 AM, Jorge I Velez <> wrote:

> Perhaps the following?
>
> d <- structure(list(x1 = structure(1:4, .Label = c("a", "c", "e",
> "g"), class = "factor"), x2 = structure(1:4, .Label = c("b",
> "d", "f", "h"), class = "factor")), .Names = c("x1", "x2"), class =
> "data.frame", row.names = c("1",
> "2", "3", "4"))
>
> with(d, c(as.character(x1), as.character(x2)))
> #  [1] "a" "c" "e" "g" "b" "d" "f" "h"
>
> HTH,
> Jorge.-
>
>
> On Fri, Feb 24, 2012 at 5:32 PM, thomas88 <> wrote:
>
>> Hello,
>> I am looking for a way to transform an array into a list (or a string).
>> My array has two columns 1 and 2, and I would like to create a list of the
>> values.
>>
>> Let's say I have :
>>
>>   x1   x2
>> 1  a  b
>> 2  c  d
>> 3  e  f
>> 4  g  h
>>
>> What I would like to obtain is a,b,c,d,e,f,g,h.
>>
>> I tried without success melt and reshape ( reshape(my_array,
>> direction="long", varying=1:2) ) but I cannot get it work.
>>
>> Thanks a lot !!!
>> thomas
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4418804.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

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


Re: [R] Table into a list

2012-02-24 Thread R. Michael Weylandt
My apologies: I missed the order of the desired output: the easiest
thing to do is likely to use the same techniques given below (and by
others in this thread) with a transpose t() before.

Michael

On Sat, Feb 25, 2012 at 2:05 AM, R. Michael Weylandt
 wrote:
> Your question is not well formed: do you want a list or a string
> (totally different things)? Or even more likely, a character vector?
> What do you have now: is it really an array (=matrix) or is it the
> data.frame it looks like?
>
> If it's a matrix:
>
> x <- matrix(letters[1:8], ncol = 2)
> x <- as.vector(x) # Character Vector
> paste(x, collapse = "") # String
>
> If it's a data frame with factors:
>
> x <- data.frame(matrix(letters[1:8], ncol = 2))
> as.character(unlist(x)) # omit as.character() if you actually have
> character elements and not factors.
>
> Michael
>
> On Fri, Feb 24, 2012 at 5:32 PM, thomas88  wrote:
>> Hello,
>> I am looking for a way to transform an array into a list (or a string).
>> My array has two columns 1 and 2, and I would like to create a list of the
>> values.
>>
>> Let's say I have :
>>
>>       x1       x2
>> 1      a          b
>> 2      c          d
>> 3      e          f
>> 4      g          h
>>
>> What I would like to obtain is a,b,c,d,e,f,g,h.
>>
>> I tried without success melt and reshape ( reshape(my_array,
>> direction="long", varying=1:2) ) but I cannot get it work.
>>
>> Thanks a lot !!!
>> thomas
>>
>> --
>> View this message in context: 
>> http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4418804.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] Table into a list

2012-02-24 Thread R. Michael Weylandt
Your question is not well formed: do you want a list or a string
(totally different things)? Or even more likely, a character vector?
What do you have now: is it really an array (=matrix) or is it the
data.frame it looks like?

If it's a matrix:

x <- matrix(letters[1:8], ncol = 2)
x <- as.vector(x) # Character Vector
paste(x, collapse = "") # String

If it's a data frame with factors:

x <- data.frame(matrix(letters[1:8], ncol = 2))
as.character(unlist(x)) # omit as.character() if you actually have
character elements and not factors.

Michael

On Fri, Feb 24, 2012 at 5:32 PM, thomas88  wrote:
> Hello,
> I am looking for a way to transform an array into a list (or a string).
> My array has two columns 1 and 2, and I would like to create a list of the
> values.
>
> Let's say I have :
>
>       x1       x2
> 1      a          b
> 2      c          d
> 3      e          f
> 4      g          h
>
> What I would like to obtain is a,b,c,d,e,f,g,h.
>
> I tried without success melt and reshape ( reshape(my_array,
> direction="long", varying=1:2) ) but I cannot get it work.
>
> Thanks a lot !!!
> thomas
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4418804.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] Table into a list

2012-02-24 Thread Jorge I Velez
Perhaps the following?

d <- structure(list(x1 = structure(1:4, .Label = c("a", "c", "e",
"g"), class = "factor"), x2 = structure(1:4, .Label = c("b",
"d", "f", "h"), class = "factor")), .Names = c("x1", "x2"), class =
"data.frame", row.names = c("1",
"2", "3", "4"))

with(d, c(as.character(x1), as.character(x2)))
#  [1] "a" "c" "e" "g" "b" "d" "f" "h"

HTH,
Jorge.-


On Fri, Feb 24, 2012 at 5:32 PM, thomas88 <> wrote:

> Hello,
> I am looking for a way to transform an array into a list (or a string).
> My array has two columns 1 and 2, and I would like to create a list of the
> values.
>
> Let's say I have :
>
>   x1   x2
> 1  a  b
> 2  c  d
> 3  e  f
> 4  g  h
>
> What I would like to obtain is a,b,c,d,e,f,g,h.
>
> I tried without success melt and reshape ( reshape(my_array,
> direction="long", varying=1:2) ) but I cannot get it work.
>
> Thanks a lot !!!
> thomas
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4418804.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] how to compute srt value to text along a line

2012-02-24 Thread dinesh

Hi

I want to draw a line between two points p1 and p2 (no problems) and 
then print text it along its path (facing problems). I use  grconvertX() 
to compute the slope E.g.,


arrows(p1.x, p1.y, p2.x., p2.y); # p2 is on right of p1
vert = grconvertX( c(p2.y, p1.y), from="user", to="inches" ); # 
also tried to="device"

horz = grconvertX( c(p2.x, p1.x), from="user", to="inches" );
srt = 180 * atan( diff(vert) / diff(horz) );
text( p2.x, p2.y, "this line", pos=2, srt=srt );

However, the text is never exactly aligned with the line. Usually, it's 
a little overtilted. I also tried variously with 
par(c("fin","din","pin","plt")) but same kind of luck.


I was wondering if
- Is there a more appropriate way to compute the srt   parameter?
- is there some other simple function to to write text at a  slope 
matching that of some line?


I am using R2.13.1 on a notebook running Windows 7 64bit.

Thanks
din...@milkorwater.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] listing array after loop

2012-02-24 Thread R. Michael Weylandt
This sure sounds like you need to read the advice I gave you on the
other thread where you asked the same questions...

Michael

On Fri, Feb 24, 2012 at 5:04 PM, uday  wrote:
> The following error I got
>
> Warning messages:
> 1: In sci.lat[i] = data[, 7] :
>  number of items to replace is not a multiple of replacement length
> 2: In sci.lon[i] = ((temp.lon + 180)%%360) - 180 :
>  number of items to replace is not a multiple of replacement length
> 3: In sci.ch4[i] = data[, 45] :
>  number of items to replace is not a multiple of replacement length
> 4: In sci.lat[i] = data[, 7] :
>  number of items to replace is not a multiple of replacement length
> 5: In sci.lon[i] = ((temp.lon + 180)%%360) - 180 :
>  number of items to replace is not a multiple of replacement length
> 6: In sci.ch4[i] = data[, 45] :
>  number of items to replace is not a multiple of replacement length
>>
>> save(sci.lat,sci.lon,sci.ch4,file="myData.RData")
> Error in gzfile(file, "wb") : cannot open the connection
> In addition: Warning message:
> In gzfile(file, "wb") :
>  cannot open compressed file 'myData.RData', probable reason 'Permission
> denied
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/listing-array-after-loop-tp4418081p4418752.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] fGarch package for Student-t Garch

2012-02-24 Thread nserdar
Hi 


Rt<-garchFit(formula=~garch(1,1),include.mean=FALSE,data=
X2,cond.dist=c("std"))   # Student-t Garch. 

I got the this output 

  omega   alpha1 beta1 shape 
0.0001027529 0.05195144470.88871366025.6843302645 

I use above formulation to calculate the time-varying variance for Student-t
Garch. 


Var(t)= omega + alpha*(return(t-1)^2)+beta*(var(t-1)) 

Should I use the shape parameter in my Garch-student T volatility forecast ?
( Or need another parameter?) 

How to use these parameters estimation for  time-varying variance for Garch-
Student t ? 

Regards, 
Ser 

--
View this message in context: 
http://r.789695.n4.nabble.com/fGarch-package-for-Student-t-Garch-tp4418871p4418871.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] Optim() package restriction

2012-02-24 Thread nserdar
I did it like above  but got an error message.

> estimate<- optim(init.par,Linn,gr=NULL,method= "L-BFGS-B",
> hessian=FALSE,control =
> list(trace=1),lower=c(0,-Inf,Inf,Inf),upper=c(1,Inf,Inf,Inf))
Error in solve.default(sig[, , 1]) : 
  system is computationally singular: reciprocal condition number = 0

"how to derive constrain for only 1 variable"

Regards,
Ser

--
View this message in context: 
http://r.789695.n4.nabble.com/Optim-package-restriction-tp4418379p4418865.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] remove multiple objects starting with same name

2012-02-24 Thread R. Michael Weylandt
rm(list = ls(pattern = "object"))

Michael

On Fri, Feb 24, 2012 at 4:40 PM, katarv  wrote:
> Hi,
>
> I'm trying to figure out syntax R function rm() needs to remove all objects
> starting with same name.  For example, if I have object1, object2, object3,
> i want to do an operation similar to UNIX rm object*
>
> Thanks.
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/remove-multiple-objects-starting-with-same-name-tp4418694p4418694.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] Optim() package restriction

2012-02-24 Thread nserdar
Thanks for your attention. 

I searched this function but I can not find " special example about box
constraint".

Can you give an example for my code?

Regards,
Ser

--
View this message in context: 
http://r.789695.n4.nabble.com/Optim-package-restriction-tp4418379p4418858.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] Telling plot() the max y value to expect when plotting one distribution and then using lines() to add more distributions

2012-02-24 Thread FJ M

I am plotting three Pearson Type IV distributions. It looks like I have to plot 
the distribution with the highest value of y and then use lines() to add the 
two distributions that are shorter / have lower max values of y. The following 
code figures out which distribution has the max y value, plots it first and 
then uses lines for the other two distributions with a series of three if 
statements. This works. I run R from a batch file that reads the following in a 
text file.
 
I want to graph dozens of distributions and I am looking for a more elegant way 
to do this.
 
New to R, experienced C programmer, thanks in advance. Frank



colors <- c("red", "blue", "darkgreen", "gold", "black")
labels <- c("1", "2","3")
pdf("C:\\Users\\Frank\\Documents\\R\\Scripts\\pt4_Graph.pdf")
## load Pearson package
library(PearsonDS)
##range for x axis
no_of_increments<- 100
x <- seq(-0.06, +0.06, length=no_of_increments)
##parameters for the plots of three distributions
mx<- c(1.95, 18.35,1.93)
nux<- c(0.08,-1.02,0.25)
locationx<- c(0.0048,-0.00254,0.00189)
scalex<- c(0.0115,0.082187,0.026675)
## calculate probability density function
hx1<- dpearsonIV(x,m=mx[1],nu=nux[1],location=locationx[1],scale=scalex[1])
hx2<- dpearsonIV(x,m=mx[2],nu=nux[2],location=locationx[2],scale=scalex[2])
hx3<- dpearsonIV(x,m=mx[3],nu=nux[3],location=locationx[3],scale=scalex[3])
##calculate max of each distribtion
maxhx1<- max(hx1)
maxhx2<- max(hx2)
maxhx3<- max(hx3)
maxhx<- max(hx1,hx2,hx3)
maxhx1
maxhx2
maxhx3
maxhx

if (maxhx1==maxhx) 
 {plot(x, hx1 , type="l", lwd=2, col=colors[1], xlab="x value",  
ylab="Density", main="pt4")
for (i in 2:3){
  lines(x, 
dpearsonIV(x,m=mx[i],nu=nux[i],location=locationx[i],scale=scalex[i]), lwd=2, 
col=colors[i])}
legend("topright", inset=.05, title="Distributions",
  labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors)
grid()
}

if (maxhx2==maxhx) {plot(x, hx2 , type="l", lwd=2, xlab="x value",  
ylab="Density", main="SPX", col=colors[2])
{
  lines(x, 
dpearsonIV(x,m=mx[1],nu=nux[1],location=locationx[1],scale=scalex[1]), lwd=2, 
col=colors[1])
  lines(x, 
dpearsonIV(x,m=mx[3],nu=nux[3],location=locationx[3],scale=scalex[3]), lwd=2, 
col=colors[3])
legend("topright", inset=.05, title="Distributions",
  labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors)
grid()
}

if (maxhx3==maxhx) 
 {plot(x, hx3 , type="l", lwd=2, col=colors[3], xlab="x value",  
ylab="Density", main="SPX")
for (i in 1:2){
  lines(x, 
dpearsonIV(x,m=mx[i],nu=nux[i],location=locationx[i],scale=scalex[i]), lwd=2, 
col=colors[i])}
legend("topright", inset=.05, title="Distributions",
  labels, lwd=2, lty=c(1, 1, 1, 1, 2), col=colors)
grid()
}
 
  
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Speeding up "accumulation" code in large matrix calc?

2012-02-24 Thread robertfeldt
Wow! Thanks to both Petr and Berend for this extensive help. 

I learned a lot not only about this specific case but about R in general
from studying your answers. 

The compiled version t4 seems to give the most consistently quickest results
and for my case (about 6000 rows and 500 columns with a probability of the
sought for outcome 0.04) I see speedups from my original of 30-40 times. See
below for details.

Excellent help thank you!

# t1-t4 as above in thread and then compiled to t1.c-t4.c ...
random_matrix <- function(nrows, ncols, probabilityOfOne) {
matrix((runif(nrows*ncols)http://r.789695.n4.nabble.com/Speeding-up-accumulation-code-in-large-matrix-calc-tp4417911p4419422.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] listing array after loop

2012-02-24 Thread uday
The following error I got 

Warning messages:
1: In sci.lat[i] = data[, 7] :
  number of items to replace is not a multiple of replacement length
2: In sci.lon[i] = ((temp.lon + 180)%%360) - 180 :
  number of items to replace is not a multiple of replacement length
3: In sci.ch4[i] = data[, 45] :
  number of items to replace is not a multiple of replacement length
4: In sci.lat[i] = data[, 7] :
  number of items to replace is not a multiple of replacement length
5: In sci.lon[i] = ((temp.lon + 180)%%360) - 180 :
  number of items to replace is not a multiple of replacement length
6: In sci.ch4[i] = data[, 45] :
  number of items to replace is not a multiple of replacement length
> 
> save(sci.lat,sci.lon,sci.ch4,file="myData.RData")
Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
  cannot open compressed file 'myData.RData', probable reason 'Permission
denied

--
View this message in context: 
http://r.789695.n4.nabble.com/listing-array-after-loop-tp4418081p4418752.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] Table into a list

2012-02-24 Thread Rui Barradas
Hello,
Try

(d <- data.frame(x1=letters[2*1:4 - 1], x2=letters[2*1:4]))
c(apply(d, 1, identity))

Note that you'll need the concatenation 'c()'.

Hope this helps,

Rui Barradas



--
View this message in context: 
http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4419091.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] Table into a list

2012-02-24 Thread thomas88
Hello,
I am looking for a way to transform an array into a list (or a string).
My array has two columns 1 and 2, and I would like to create a list of the
values.

Let's say I have :

   x1   x2
1  a  b
2  c  d
3  e  f 
4  g  h

What I would like to obtain is a,b,c,d,e,f,g,h.

I tried without success melt and reshape ( reshape(my_array,
direction="long", varying=1:2) ) but I cannot get it work.

Thanks a lot !!!
thomas

--
View this message in context: 
http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4418804.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] remove multiple objects starting with same name

2012-02-24 Thread katarv
Hi,

I'm trying to figure out syntax R function rm() needs to remove all objects
starting with same name.  For example, if I have object1, object2, object3,
i want to do an operation similar to UNIX rm object*

Thanks.




--
View this message in context: 
http://r.789695.n4.nabble.com/remove-multiple-objects-starting-with-same-name-tp4418694p4418694.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] tcl tk command function with arguments ??

2012-02-24 Thread ilai
On Fri, Feb 24, 2012 at 5:03 PM, peter dalgaard  wrote:
>
>
> Now that's just weird... Firstly, it has nothing to do with sapply vs. for 
> loops. It just works because you are inserting yet another function 
> environment.

Thank you Peter, that makes more sense. As you can probably imagine,
first I made it work, then I convinced myself why. Just another of my
bad habits...

Secondly, if there was ever a point to having the buttons in the
OK.but list, it is not going to work anymore because you are assigning
each element to a different list, one per function environment.

Yes. I was aware of this but what is not going to work ? isn't the
OK.but list simply "storage" ? can it be used in some other way ? The
OP should answer if there is indeed some other application intended
that might fail, but I assumed there really wasn't a reason for this
exercise of creating the same button in a loop except for convenience.

> A more straightforward fix could be to do
>
> command = local({i <- i; function() PressedOK(i)})

Ouch! the thought to use local crossed my mind and was discarded in
favor of other (failed) attempts to "store" i before evaluation. This
is much better. Thank you again. I change my vote from my own solution
to this one.

>
> Other options might use the fact that command arguments can be R call 
> objects, so you can insert the value of i  directly into the call using
>
> command = substitute(PressedOK(i), list(i=i))
>
> or
>
> command = bquote(PressedOK(.(i)))
>
> [ There's a bug fixed in 2.14.2-RC which prevents this from working in a for 
> loop; for 2.14.1 and earlier, you'll need .(force(i)) ]
>
>> Cheers,
>> Elai
>>
>>
>>> Thanks
>>>
>>>
>>> --
>>> View this message in context: 
>>> http://r.789695.n4.nabble.com/tcl-tk-command-function-with-arguments-tp4416470p4416470.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.
>
> --
> 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] Producing KML files

2012-02-24 Thread R. Michael Weylandt
Hi Melicie,

I'm not a Windows user or a user of SAGA but the warning message suggests part 
of the problem may be that R can't find your SAGA installation. Is it in your 
Windows PATH?

You may be able to get more specialized help on the R-SIG-geo list as well. 

Michael

On Feb 24, 2012, at 12:06 PM, "Desflots, Melicie"  
wrote:

> Hi,
> 
> I am very new to R and I am trying to write KML files. I am running R-2.13.1 
> and I have the following packages:
> 
> -  AKIMA
> 
> -  RGDAL
> 
> -  RSAGA
> 
> -  SP
> 
> 
> I was trying to run the simple example that I found at the following web page:
> http://spatial-analyst.net/wiki/index.php?title=Export_maps_to_GE
> 
> The lines that I can run are:
> 
> data(meuse.grid)
> coordinates(meuse.grid) <- ~x+y
> gridded(meuse.grid) <- TRUE
> proj4string(meuse.grid) = CRS("+init=epsg:28992")
> # raster to polygon conversion;
> writeGDAL(meuse.grid["soil"], "meuse_soil.sdat", "SAGA", mvFlag=-9)
> rsaga.geoprocessor(lib="shapes_grid", module=6,
>   param=list(GRID="meuse_soil.sgrd", 
> POLYGONS="meuse_soil.shp", CLASS_ALL=1))
> 
> and it crashes there with the following error message:
> 
> Error in setwd(env$workspace) : character argument expected
> In addition: Warning message:
> In rsaga.env() :
>  SAGA command line program 'saga_cmd.exe' not found in any of the paths
> C:/Program Files/R/R-2.13.1/library/RSAGA/saga_vc
> C:/Program Files/R/R-2.13.1/library/RSAGA/SAGA-GIS
> ...
> 
> Can someone please let me know what I should do to fix that error?
> 
> Thanks,
> Mel
> 
> 
>[[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] looping over string of frames when importing with 'sqlFetch' from a Microsoft Access database

2012-02-24 Thread Eric Fail
correction, this is the working R script, forgot '1: ... )',

dfn = list();
for (i in 1:length(stringTables)) {
dfn[[i]] <- sqlFetch(mdbConnect, stringTables[[i]])
}

On Fri, Feb 24, 2012 at 4:48 PM, Eric Fail  wrote:

> Problem solved thanks to Peter Langfelder's response to Adel ESSAFI.
>
> This is what should be in the loop,
>
> dfn = list();
> for (i in length(stringTables) {
> dfn[[ i ]] <-
> sqlFetch(mdbConnect, stringTables[[ 
> i
> ]])
> }
>
> Thanks,
> Eric
>
> On Fri, Feb 24, 2012 at 3:19 PM, Eric Fail  wrote:
>
>> Dear R-list,
>>
>> I am trying to import (all) frames from a Microsoft Access database as
>> individual data frames in a fancy loop, but I'm having troubles figuring
>> out how to use the 'sqlFetch' from the RODBS package in a loop (mostly
>> because I can't figure out how to loop over elements (I came from stata)
>>
>> I would very much appreciate if anyone on the list could help me solve
>> this problem, as it is an issue of connecting to a database I can't really
>> make a working example, please bear with me.
>>
>> ### not-working R code ###
>>
>> ## first I establish a connection to my database
>> mdbConnect<-odbcConnectAccess("C:\\... \\database.mdb")
>>
>> ## then I read of all the table names
>> stringTables <- sqlTables(mdbConnect, tableType=c("TABLE"))$TABLE_NAME
>>
>> ## and then I meet the wall ...
>> for(i.Frame in stringTables) {
>> i.Frame <- sqlFetch(mdbConnect, i.Frame)
>> }
>> ## this broken loop creates one data frame called containing the
>> 'i.Frame' containing the last frame in the 'stringTables.' I'm not doing
>> this correct.
>>
>> ## the final step.
>> DF <- stringTables[[1]]
>> for ( .df in stringTables) {
>>   DF <-merge(DF,.df, by.x="uniqueid", by.y="uniqueid", all=T)
>>  }
>>
>> ### end of not-working R code ###
>>
>> Thanks,
>> Eric
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] looping over string of frames when importing with 'sqlFetch' from a Microsoft Access database

2012-02-24 Thread Eric Fail
Problem solved thanks to Peter Langfelder's response to Adel ESSAFI.

This is what should be in the loop,

dfn = list();
for (i in length(stringTables) {
dfn[[ i ]] <-
sqlFetch(mdbConnect, stringTables[[
i
]])
}

Thanks,
Eric

On Fri, Feb 24, 2012 at 3:19 PM, Eric Fail  wrote:

> Dear R-list,
>
> I am trying to import (all) frames from a Microsoft Access database as
> individual data frames in a fancy loop, but I'm having troubles figuring
> out how to use the 'sqlFetch' from the RODBS package in a loop (mostly
> because I can't figure out how to loop over elements (I came from stata)
>
> I would very much appreciate if anyone on the list could help me solve
> this problem, as it is an issue of connecting to a database I can't really
> make a working example, please bear with me.
>
> ### not-working R code ###
>
> ## first I establish a connection to my database
> mdbConnect<-odbcConnectAccess("C:\\... \\database.mdb")
>
> ## then I read of all the table names
> stringTables <- sqlTables(mdbConnect, tableType=c("TABLE"))$TABLE_NAME
>
> ## and then I meet the wall ...
> for(i.Frame in stringTables) {
> i.Frame <- sqlFetch(mdbConnect, i.Frame)
> }
> ## this broken loop creates one data frame called containing the 'i.Frame'
> containing the last frame in the 'stringTables.' I'm not doing this correct.
>
> ## the final step.
> DF <- stringTables[[1]]
> for ( .df in stringTables) {
>   DF <-merge(DF,.df, by.x="uniqueid", by.y="uniqueid", all=T)
>  }
>
> ### end of not-working R code ###
>
> Thanks,
> Eric
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] find difference between data frames

2012-02-24 Thread R. Michael Weylandt
I'm not sure if you mean to ignore row 6 while ignoring row 4 or not
so here are two solutions (depending on what you meant)

dput(x) # dput is your friend
structure(list(kind = c(1L, 1L, 1L, 1L, 2L, 2L), x = c(8L, 44L,
25L, 36L, 2L, 36L), y = c(9L, 3L, 7L, 20L, 14L, 20L)), .Names = c("kind",
"x", "y"), class = "data.frame", row.names = c("1", "2", "3",
"4", "5", "6"))

## If you want to get rid of duplicates for both cases -- not the
prettiest but it works
table(x[!(duplicated(x[,-1], fromLast = TRUE) | duplicated(x[,-1])),1])

## If you only want to get rid of it for the kind==1 rows (assuming
the data.frame is sorted by kind)
table(x[!duplicated(x[,-1], fromLast = TRUE), 1])

It's usually good practice to say what the answer you expect is to
avoid this sort of confusion.

Michael

On Fri, Feb 24, 2012 at 2:00 PM, psy106616  wrote:
> I have one data frame, like below:
>        kind        x        y
> 1        1          8         9
> 2        1        44        3
> 3        1        25        7
> 4        1         36       20
> 5        2         2          14
> 6        2         36       20
>
> so, I want to find unique coordinates in kind 1 rather than kind 2, ex, row
> 4 should be excluded, is that possible?
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/find-difference-between-data-frames-tp4418328p4418328.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] How would you program an Adverse Events statistical table using R code?

2012-02-24 Thread Robert Wilkins
A graph != A table.
I'm talking about a page full of summary statistics and advanced
statistics, with lots of cross categories on the top and left margin
of the table, as opposed to a visual display with x-axis and y-axis,
which is totally different.

(An example of how this is done in another language is available  at
http://fivetimesfaster.blogspot.com )

For an AE table, you have an N and % column for every treatment group,
and for all patients combined. On the right side, a categorical
p-value (chi-sq or Fisher's) for every preferred term (every row!
forget multiple testing issues, this is what the boss is asking
for(it's ad-hoc safety analysis))
There's a row for grand total N for each group.
A row for N and % of patients with any event (regardless of body
system and preferred term)
For each body system, there's a section of rows that include:
  A row for N and % of patients with any event (this body system)
  A row for N and % of patients who do NOT have an event( this body system)
  And , of course, within body system, a row for each preferred term
(again N and % for each group , and also the p-value)

Body system and preferred term are, of course broad medical category
and specific medical category.


In the Pharma industry, they use the SAS programming language. Each
table often needs several hundred lines of code. Essentially it's a
combination of analysis and (visual)-reporting mixed together, with
some prerequisite data transformation. (And yes, with this new
language, it can be done in under 20 lines of code).

I have not seen people discuss attempts to do such things with the R
programming language, and how successful such attempts have been. How
hard is it, how much code is it?

In general, we are talking about a variety of complex,
somewhat-nonhomogeneous statistical tables with a variety of different
row sections and row categories, and different column sections and
column categories, and a mixture of summary statistics and advanced
statistics (p-value , least square mean, etc), and sometimes
statistics from different statistical procedures on the same page.

Robert Wilkins

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] tcl tk command function with arguments ??

2012-02-24 Thread peter dalgaard

On Feb 24, 2012, at 19:44 , ilai wrote:

> On Fri, Feb 24, 2012 at 12:58 AM, Alexander  
> wrote:
> 
>> I would like to know if its possible to use a function with arguments as a
>> command in tcl tk.
> 
> Yes
> 
> 
> I think
>> this is due to the fact that the PressedOK(3) was the last call of the
>> function, but I don't understand why all the other buttons have now a
>> different command. Any idea?
>> 
> 
> Because in for loop i is overwritten every time - as you said i=3 is
> the last command.
> Replacing for with sapply should fix it:
> 
> require(tcltk)
> OK.but <- NULL
> PressedOK <- function(i)
> {
>   tkmessageBox(message=paste("You pressed OK!",i,sep=""))
> }
> 
> tt <- tktoplevel()
> sapply(1:3,function(i){
>  OK.but[[i]] <- tkbutton(tt,text="OK",command=function()PressedOK(i))
>  tkgrid(OK.but[[i]])
> })
> tkfocus(tt)
> 


Now that's just weird... Firstly, it has nothing to do with sapply vs. for 
loops. It just works because you are inserting yet another function 
environment. Secondly, if there was ever a point to having the buttons in the 
OK.but list, it is not going to work anymore because you are assigning each 
element to a different list, one per function environment.

The problem with the original suggestion:

for(i in seq(3)){
OK.but[[i]] <- tkbutton(tt,text="OK",command=function()PressedOK(i))
tkgrid(OK.but[[i]])
}

is that the callback function will access  i  in the enclosing environment 
since it is neither a local variable or a function argument. This will happen 
when the callback is _executed_, at which time the loop index has long since 
reached the value of 3.

A more straightforward fix could be to do 

command = local({i <- i; function() PressedOK(i)}) 

Other options might use the fact that command arguments can be R call objects, 
so you can insert the value of i  directly into the call using

command = substitute(PressedOK(i), list(i=i))

or 

command = bquote(PressedOK(.(i)))

[ There's a bug fixed in 2.14.2-RC which prevents this from working in a for 
loop; for 2.14.1 and earlier, you'll need .(force(i)) ]

> Cheers,
> Elai
> 
> 
>> Thanks
>> 
>> 
>> --
>> View this message in context: 
>> http://r.789695.n4.nabble.com/tcl-tk-command-function-with-arguments-tp4416470p4416470.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.

-- 
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] syntaxe problem

2012-02-24 Thread Peter Langfelder
On Fri, Feb 24, 2012 at 3:47 PM, Adel ESSAFI  wrote:
> Hello,
> I want to create 10 dataframe  using a for loop.
> I don t know what to do to create 10 different dataframes whose name is
> parametrized with variable i.
> This syntaxe fails. It create a unique fataframe called dfn.
> Any input will help
> Thanks
>
>>  for (i in 1:10){
> + filename=paste("avail4",i,sep = "_")
> + dfn=read.table(filename)
> + }

You may want to create a list of 10 data frames.

dfn = list();

 for (i in 1:10){
filename=paste("avail4",i,sep = "_")
dfn[[i]]=read.table(filename)
}

This way dfn[[1]] will be the data frame read from the first file,
dfn[[2]] from the second file etc.

Hope this helps,

Peter

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

2012-02-24 Thread Adel ESSAFI
Hello,
I want to create 10 dataframe  using a for loop.
I don t know what to do to create 10 different dataframes whose name is
parametrized with variable i.
This syntaxe fails. It create a unique fataframe called dfn.
Any input will help
Thanks

>  for (i in 1:10){
+ filename=paste("avail4",i,sep = "_")
+ dfn=read.table(filename)
+ }


-- 
PhD candidate in Computer Science
Address
3 avenue lamine, cité ezzahra, Sousse 4000
Tunisia
tel: +216 97 246 706 (+33640302046 jusqu'au 15/6)
fax: +216 71 391 166

[[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] looping over string of frames when importing with 'sqlFetch' from a Microsoft Access database

2012-02-24 Thread Eric Fail
Dear R-list,

I am trying to import (all) frames from a Microsoft Access database as 
individual data frames in a fancy loop, but I'm having troubles figuring out 
how to use the 'sqlFetch' from the RODBS package in a loop (mostly because I 
can't figure out how to loop over elements (I came from stata)

I would very much appreciate if anyone on the list could help me solve this 
problem, as it is an issue of connecting to a database I can't really make a 
working example, please bear with me.

### not-working R code ###

## first I establish a connection to my database
mdbConnect<-odbcConnectAccess("C:\\... \\database.mdb")

## then I read of all the table names
stringTables <- sqlTables(mdbConnect, tableType=c("TABLE"))$TABLE_NAME

## and then I meet the wall ...
for(i.Frame in stringTables) {
    i.Frame <- sqlFetch(mdbConnect, i.Frame)
}
## this broken loop creates one data frame called containing the 'i.Frame' 
containing the last frame in the 'stringTables.' I'm not doing this correct.

## the final step.
DF <- stringTables[[1]]
for ( .df in stringTables) {
  DF <-merge(DF,.df, by.x="uniqueid", by.y="uniqueid", all=T)
 }

### end of not-working R code ###

Thanks,
Eric

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

2012-02-24 Thread Greg Snow
?ks.test
?qqplot

also look at permutation tests and possibly the vis.test function in
the TeachingDemos package.

Note that with all of these large samples may give you power to detect
meaningless differences and small samples may not have enough power to
detect potentially important differences.

On Wed, Feb 22, 2012 at 12:37 AM, Mohammed Ouassou
 wrote:
> Hi everyone,
>
> I have 2 data sets and I like to carry out a test to find out if they
> come from the same distribution.
>
>
> Any suggestions ? thanks in advance.
>
> M.O
>
>
>
>
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@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] Speeding up "accumulation" code in large matrix calc?

2012-02-24 Thread Petr Savicky
On Fri, Feb 24, 2012 at 09:06:28PM +0100, Berend Hasselman wrote:
[...]
> Summary of results
> 
> > Nrow <- 100
> > Ncol <- 1000
> > A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)
> > print(rbind(z1,z2,z3,z4,z5,z6))
>user.self sys.self elapsed user.child sys.child
> z1 0.5430.005   0.551  0 0
> z2 0.2990.004   0.304  0 0
> z3 0.0700.012   0.082  0 0
> z4 0.1120.002   0.114  0 0
> z5 0.2630.007   0.271  0 0
> z6 0.0620.009   0.070  0 0
[...]
> The original function (t1) benefits a lot from compiling to byte code.
> The function that operates on columns (t3) seems to be always the quickest in 
> this experiment.

Hi.

Let me include one more solution operating on rows to the test.

  t4 <- function(A, outcome) {
  oneRow <- function(x, outcome)
  {
  n <- length(x)
  y <- 1:n
  z <- y
  z[c(FALSE, x[-n] != outcome)] <- 0
  y - cummax(z)
  }
  t(apply(A, 1, oneRow, outcome=outcome))
  }

  library(compiler)
  t1.c <- cmpfun(t1)
  t3.c <- cmpfun(t3)
  t4.c <- cmpfun(t4)
 
  Nrow <- 100
  Ncol <- 1000
  A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)
 
  library(rbenchmark)
  benchmark(t1(A,outcome=1),
t3(A,outcome=1),
t4(A,outcome=1),
t1.c(A,outcome=1),
t3.c(A,outcome=1),
t4.c(A,outcome=1),
columns=c("test", "user.self", "sys.self", "relative"),
replications=1)

test user.self sys.self relative
  1   t1(A, outcome = 1) 0.7440  46.5000
  4 t1.c(A, outcome = 1) 0.2840  17.6875
  2   t3(A, outcome = 1) 0.0760   4.7500
  5 t3.c(A, outcome = 1) 0.0720   4.6250
  3   t4(A, outcome = 1) 0.0160   1.
  6 t4.c(A, outcome = 1) 0.0200   1.1250

Here, t4(), t4.c() is faster than t3(), t3.c().

With

  Nrow <- 2
  Ncol <- 50
  A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)

i get

test user.self sys.self  relative
  1   t1(A, outcome = 1) 7.4440 20.233696
  4 t1.c(A, outcome = 1) 2.7400  7.442935
  2   t3(A, outcome = 1) 0.3680  1.00
  5 t3.c(A, outcome = 1) 0.3680  1.002717
  3   t4(A, outcome = 1) 0.5920  1.605978
  6 t4.c(A, outcome = 1) 0.5360  1.456522

Here, t3() and t3.c() are faster than t4(), t4.c().

Petr.

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

2012-02-24 Thread ilai
On Fri, Feb 24, 2012 at 12:18 PM, nserdar  wrote:
> Hi
>
> I need a "phi" restriction in my code. That is   "0
> How can I do that ?

> init.par<-c(1,1,1,1)
> estimate<- optim(init.par,Linn,gr=NULL,method= "BFGS", hessian=FALSE,control
> = list(trace=1))
>

You want method "L-BFGS-B" not "BFGS". See details in ?optim

Best


> Regards,
> res
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Optim-package-restriction-tp4418379p4418379.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] evaluating derivative matrices of spline functions

2012-02-24 Thread Spencer Graves
  I don't know about "smooth.spline", but the "fda" package 
includes "deriv.fd".  It also includes "eval.fd" and "predict.fd".  If 
you only want a first derivative, then differentiating a standard cubic 
spline may be adequate.  However, the first derivative of a cubic spline 
is a quadratic spline, the second derivative is a linear spline, and the 
third derivative is a step function.  The "fda" package provides more 
alternative basis sets than the standard cubic splines, and may give you 
results more to your liking.



  Hope this helps.
  Spencer


p.s.  Full disclosure:  I'm the third author on the Springer "Use R!" 
book on "Functional Data Analysis with R and Matlab".  I was the R 
expert on the team that produced that book.  The lead author, Jim 
Ramsay, invented "functional data analysis" as a generalization of 
spline smoothing to (a) bases other than the standard cubic b-splines 
and (b) penalty functions other than the standard integral of the square 
of the second derivative.



On 2/24/2012 12:33 PM, Vassily Shvets wrote:

Hello,
I've noticed that SPLUS has a function for evaluating the derivative matrices 
of splines.
I've also noticed that there's a function in R for evaluating matrices from 
smooth.spline;
maybe someone knows if something has been written to evaluate matrices from 
'smooth.basis'?
regards,
s

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



--
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.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] Speeding up "accumulation" code in large matrix calc?

2012-02-24 Thread Petr Savicky
On Fri, Feb 24, 2012 at 09:06:28PM +0100, Berend Hasselman wrote:
[...]
> I've done some speed tests.
> 
> t1 <- function(m, outcome) {
>   nrows <- dim(m)[1]
>   ncols <- dim(m)[2]
>   res <- matrix(rep.int(0, nrows*ncols), nrow=nrows)
>   for(row in 1:nrows) {
>   for(col in 2:ncols) {
>   res[row,col] <- if(m[row,col-1]==outcome) {0} else 
> {1+res[row,col-1]}
>   }
>   }
>   res
> }
> 
> # by row
> t2 <- function(A, outcome) {
> oneRow <- function(x, outcome)
> {
> n <- length(x)
> y <- c(0, cumsum(x[-n] == outcome))
> ave(x, y, FUN = function(z) seq.int(along=z) - 1)
> }
> 
> t(apply(A, 1, oneRow, outcome=1))
> }
> 
> # transformation
> t3 <- function(A, outcome) {
> B <- array(0, dim=dim(A))
> curr <- B[, 1]
> for (i in seq.int(from=2, length=ncol(A)-1)) {
> curr <- ifelse (A[, i-1] == outcome, 0, 1 + curr)
> B[, i] <- curr
> }
> B
> }
> 
> # Compile functions to byte code
> library(compiler)
> t1.c <- cmpfun(t1)
> t2.c <- cmpfun(t2)
> t3.c <- cmpfun(t3)
> 
> Nrow <- 100
> Ncol <- 1000
> A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)
> 
> z1 <- system.time(res1 <- t1(A,outcome=1))
> z2 <- system.time(res2 <- t2(A,outcome=1))
> z3 <- system.time(res3 <- t3(A, outcome=1))
> z4 <- system.time(res4 <- t1.c(A,outcome=1))
> z5 <- system.time(res5 <- t2.c(A,outcome=1))
> z6 <- system.time(res6 <- t3.c(A, outcome=1))
> print(all(res2==res1))
> print(all(res3==res1))
> print(all(res4==res1))
> print(all(res5==res1))
> print(all(res6==res1))
> print(rbind(z1,z2,z3,z4,z5,z6))
> 
[...]
> --
> 
> Summary of results
> 
> > Nrow <- 100
> > Ncol <- 1000
> > A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)
> > print(rbind(z1,z2,z3,z4,z5,z6))
>user.self sys.self elapsed user.child sys.child
> z1 0.5430.005   0.551  0 0
> z2 0.2990.004   0.304  0 0
> z3 0.0700.012   0.082  0 0
> z4 0.1120.002   0.114  0 0
> z5 0.2630.007   0.271  0 0
> z6 0.0620.009   0.070  0 0
> 
> 
> > Nrow <- 1000
> > Ncol <- 100
> > A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)
> >
> > z1 <- system.time(res1 <- t1(A,outcome=1))
> > z2 <- system.time(res2 <- t2(A,outcome=1))
> > z3 <- system.time(res3 <- t3(A, outcome=1))
> > z4 <- system.time(res4 <- t1.c(A,outcome=1))
> > z5 <- system.time(res5 <- t2.c(A,outcome=1))
> > z6 <- system.time(res6 <- t3.c(A, outcome=1))
>user.self sys.self elapsed user.child sys.child
> z1 0.5430.005   0.551  0 0
> z2 0.2990.004   0.304  0 0
> z3 0.0700.012   0.082  0 0
> z4 0.1120.002   0.114  0 0
> z5 0.2630.007   0.271  0 0
> z6 0.0620.009   0.070  0 0
[...]
> 
> The original function (t1) benefits a lot from compiling to byte code.
> The function that operates on columns (t3) seems to be always the quickest in 
> this experiment.

Thank you for this. Intuition may be wrong.

Function t2() calls ave(), which contains a loop over the groups, so
its efficiency depends also on the number of groups. If the matrix is
generated with fewer 1's, then i obtained

  Nrow <- 100
  Ncol <- 1000
  A <- matrix((runif(Ncol*Nrow)<0.002)+0, nrow=Nrow)
 
  library(rbenchmark)
  benchmark(t1(A,outcome=1),
t2(A,outcome=1),
t3(A,outcome=1),
t1.c(A,outcome=1),
t2.c(A,outcome=1),
t3.c(A,outcome=1),
columns=c("test", "user.self", "relative"),
replications=1)

  1   t1(A, outcome = 1) 0.776 13.362069
  4 t1.c(A, outcome = 1) 0.308  5.275862
  2   t2(A, outcome = 1) 0.172  2.965517
  5 t2.c(A, outcome = 1) 0.176  3.034483
  3   t3(A, outcome = 1) 0.060  1.051724
  6 t3.c(A, outcome = 1) 0.056  1.00

So, the result is slightly better for t2() with probability 0.002
of 1 than with probability 0.2. At least, it is faster than t1.c().
But still, t3() or t3.c() is faster.

Petr.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] evaluating derivative matrices of spline functions

2012-02-24 Thread Vassily Shvets
Hello,
I've noticed that SPLUS has a function for evaluating the derivative matrices 
of splines.
I've also noticed that there's a function in R for evaluating matrices from 
smooth.spline;
maybe someone knows if something has been written to evaluate matrices from 
'smooth.basis'?
regards,
s

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

2012-02-24 Thread EKN
Dear Forum,

I have installed and used various Weka functions in R - both already
available interfaces or created ones via make_Weka_classifier - without any
trouble. However, the RBFNetwork (RBF Neural Network) function is one that I
have not been able to call.  I tried creating the R interface using RBF<-
make_Weka_classifier("weka/classifiers/functions/RBFNetwork"), and the
following is the error I get:

Error in .jnew(name) : java.lang.ClassNotFoundException

Does anyone know if I am just using the incorrect function name? How do I
create the RBFNetwork interface in R?

Thank you all in advance,

Ester

--
View this message in context: 
http://r.789695.n4.nabble.com/RBFNetwork-in-RWeka-tp4418424p4418424.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] B-spline/smooth.basis derivative matrices

2012-02-24 Thread Vassily Shvets
Hello,
I've noticed that SPLUS seems to have a function for evaluating derivative 
matrices of splines. I've found the R function that evaluates matrices from 
'smooth.spline'; maybe someone has written something to do the same with 
smooth.basis?
regards,
s

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

2012-02-24 Thread psy106616
I have one data frame, like below:
kindxy
11  8 9
21443
31257
41 36   20
52 2  14
62 36   20

so, I want to find unique coordinates in kind 1 rather than kind 2, ex, row
4 should be excluded, is that possible?

--
View this message in context: 
http://r.789695.n4.nabble.com/find-difference-between-data-frames-tp4418328p4418328.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] shell command with Robocopy error

2012-02-24 Thread Aldo
Also it copies the files, but I am using this as part of a larger code block
and concerned the errors will kill the loop

--
View this message in context: 
http://r.789695.n4.nabble.com/shell-command-with-Robocopy-error-tp4418254p4418345.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] Optim() package restriction

2012-02-24 Thread nserdar
Hi 

I need a "phi" restriction in my code. That is   "0http://r.789695.n4.nabble.com/Optim-package-restriction-tp4418379p4418379.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] Speeding up "accumulation" code in large matrix calc?

2012-02-24 Thread Berend Hasselman

On 24-02-2012, at 20:02, Petr Savicky wrote:

> On Fri, Feb 24, 2012 at 08:59:44AM -0800, robertfeldt wrote:
>> Hi,
>> 
>> I have R code like so:
>> 
>> num.columns.back.since.last.occurence <- function(m, outcome) {
>>  nrows <- dim(m)[1];
>>  ncols <- dim(m)[2];
>>  res <- matrix(rep.int(0, nrows*ncols), nrow=nrows);
>>  for(row in 1:nrows) {
>>  for(col in 2:ncols) {
>>  res[row,col] <- if(m[row,col-1]==outcome) {0} else 
>> {1+res[row,col-1]}
>>  }
>>  }
>>  res;
>> }
>> 
>> but on the very large matrices I apply this the execution times are a
>> problem. I would appreciate any help to rewrite this with more
>> "standard"/native R functions to speed things up.
> 
> Hi.
> 
> If the number of rows is large and the number of columns is not,
> then try the following.
> 
>  # random matrix
>  A <- matrix((runif(49) < 0.2) + 0, nrow=7)
>  outcome <- 1
> 
>  # transformation
>  B <- array(0, dim=dim(A))
>  curr <- B[, 1]
>  for (i in seq.int(from=2, length=ncol(A)-1)) {
>  curr <- ifelse (A[, i-1] == outcome, 0, 1 + curr)
>  B[, i] <- curr
>  }

I've done some speed tests.

t1 <- function(m, outcome) {
nrows <- dim(m)[1]
ncols <- dim(m)[2]
res <- matrix(rep.int(0, nrows*ncols), nrow=nrows)
for(row in 1:nrows) {
for(col in 2:ncols) {
res[row,col] <- if(m[row,col-1]==outcome) {0} else 
{1+res[row,col-1]}
}
}
res
}

# by row
t2 <- function(A, outcome) {
oneRow <- function(x, outcome)
{
n <- length(x)
y <- c(0, cumsum(x[-n] == outcome))
ave(x, y, FUN = function(z) seq.int(along=z) - 1)
}

t(apply(A, 1, oneRow, outcome=1))
}

# transformation
t3 <- function(A, outcome) {
B <- array(0, dim=dim(A))
curr <- B[, 1]
for (i in seq.int(from=2, length=ncol(A)-1)) {
curr <- ifelse (A[, i-1] == outcome, 0, 1 + curr)
B[, i] <- curr
}
B
}

# Compile functions to byte code
library(compiler)
t1.c <- cmpfun(t1)
t2.c <- cmpfun(t2)
t3.c <- cmpfun(t3)

Nrow <- 100
Ncol <- 1000
A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)

z1 <- system.time(res1 <- t1(A,outcome=1))
z2 <- system.time(res2 <- t2(A,outcome=1))
z3 <- system.time(res3 <- t3(A, outcome=1))
z4 <- system.time(res4 <- t1.c(A,outcome=1))
z5 <- system.time(res5 <- t2.c(A,outcome=1))
z6 <- system.time(res6 <- t3.c(A, outcome=1))
print(all(res2==res1))
print(all(res3==res1))
print(all(res4==res1))
print(all(res5==res1))
print(all(res6==res1))
print(rbind(z1,z2,z3,z4,z5,z6))

Nrow <- 1000
Ncol <- 100
A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)

z1 <- system.time(res1 <- t1(A,outcome=1))
z2 <- system.time(res2 <- t2(A,outcome=1))
z3 <- system.time(res3 <- t3(A, outcome=1))
z4 <- system.time(res4 <- t1.c(A,outcome=1))
z5 <- system.time(res5 <- t2.c(A,outcome=1))
z6 <- system.time(res6 <- t3.c(A, outcome=1))
print(all(res2==res1))
print(all(res3==res1))
print(all(res4==res1))
print(all(res5==res1))
print(all(res6==res1))
print(rbind(z1,z2,z3,z4,z5,z6))

Nrow <- 1000
Ncol <- 1000
A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)

z1 <- system.time(res1 <- t1(A,outcome=1))
z2 <- system.time(res2 <- t2(A,outcome=1))
z3 <- system.time(res3 <- t3(A, outcome=1))
z4 <- system.time(res4 <- t1.c(A,outcome=1))
z5 <- system.time(res5 <- t2.c(A,outcome=1))
z6 <- system.time(res6 <- t3.c(A, outcome=1))
print(all(res2==res1))
print(all(res3==res1))
print(all(res4==res1))
print(all(res5==res1))
print(all(res6==res1))
print(rbind(z1,z2,z3,z4,z5,z6))

--

Summary of results

> Nrow <- 100
> Ncol <- 1000
> A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)
> print(rbind(z1,z2,z3,z4,z5,z6))
   user.self sys.self elapsed user.child sys.child
z1 0.5430.005   0.551  0 0
z2 0.2990.004   0.304  0 0
z3 0.0700.012   0.082  0 0
z4 0.1120.002   0.114  0 0
z5 0.2630.007   0.271  0 0
z6 0.0620.009   0.070  0 0


> Nrow <- 1000
> Ncol <- 100
> A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)
>
> z1 <- system.time(res1 <- t1(A,outcome=1))
> z2 <- system.time(res2 <- t2(A,outcome=1))
> z3 <- system.time(res3 <- t3(A, outcome=1))
> z4 <- system.time(res4 <- t1.c(A,outcome=1))
> z5 <- system.time(res5 <- t2.c(A,outcome=1))
> z6 <- system.time(res6 <- t3.c(A, outcome=1))
   user.self sys.self elapsed user.child sys.child
z1 0.5430.005   0.551  0 0
z2 0.2990.004   0.304  0 0
z3 0.0700.012   0.082  0 0
z4 0.1120.002   0.114  0 0
z5 0.2630.007   0.271  0 0
z6 0.0620.009   0.070  0 0

> Nrow <- 1000
> Ncol <- 1000
> A <- matrix((runif(Ncol*Nrow)<0.2)+0, nrow=Nrow)
> print(rbind(z1,z2,z3,z4,z5,z6))
   user.self sys.self elapsed user.child sys.

Re: [R] data frame manipulation with conditions

2012-02-24 Thread ilai
Ahh, I see it now.
For some reason your original post popped up on the list again, could
be just my mail server, sorry.
Looks like Uwe gave you the same solution (in two lines for better
clarity) right away. Depending on your level of "noobiness", my advice
would have been to ignore everything after that. Although if the other
approaches worked better for you, cheers.
Again sorry for this double thread.


On Fri, Feb 24, 2012 at 12:31 PM, Arnaud Gaboury
 wrote:
> TY Elai for your answer. One solution has been given earlier in this list by 
> Sarah Goslee and William Dunlap.
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of ilai
> Sent: vendredi 24 février 2012 20:14
> To: A2CT2 Trading
> Cc: r-help@r-project.org
> Subject: Re: [R] data frame manipulation with conditions
>
> On Fri, Feb 24, 2012 at 8:11 AM, A2CT2 Trading  wrote:
>> Dear list,
>>
>> n00b question, but still can't find any easy answer.
>>
>> Here is a df:
>>
>>> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
>
> # No, your y is a factor
>  str(df)
> 'data.frame':   4 obs. of  2 variables:
>  $ x: Factor w/ 3 levels "AA","BB","CC": 1 2 3 1  $ y: Factor w/ 4 levels 
> "1","2","3","4": 1 2 3 4
>
> # You want to remove the cbind
>> df<-data.frame(x=c("AA","BB","CC","AA"),y=1:4)
>> str(df)
> 'data.frame':   4 obs. of  2 variables:
>  $ x: Factor w/ 3 levels "AA","BB","CC": 1 2 3 1  $ y: int  1 2 3 4
>
>> I want to modify this df this way :
>>  if df$x=="AA" then df$y=df$y*10
>>  if df$x=="BB" then df$y=df$y*25
>>
>> and so on with other conditions.
>>
>
>  df$y<- df$y * c(10,25,.5)[df$x]
> [1] 10.0 50.0  1.5 40.0
>  # 1*10 2*25 3*.5 4*10
>
> HTH
>
> Elai
>
>> TY for any help.
>>
>> Trading
>>
>> A2CT2 Ltd.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] data frame manipulation with conditions

2012-02-24 Thread Arnaud Gaboury
TY Elai for your answer. One solution has been given earlier in this list by 
Sarah Goslee and William Dunlap.

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of ilai
Sent: vendredi 24 février 2012 20:14
To: A2CT2 Trading
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with conditions

On Fri, Feb 24, 2012 at 8:11 AM, A2CT2 Trading  wrote:
> Dear list,
>
> n00b question, but still can't find any easy answer.
>
> Here is a df:
>
>> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))

# No, your y is a factor
 str(df)
'data.frame':   4 obs. of  2 variables:
 $ x: Factor w/ 3 levels "AA","BB","CC": 1 2 3 1  $ y: Factor w/ 4 levels 
"1","2","3","4": 1 2 3 4

# You want to remove the cbind
> df<-data.frame(x=c("AA","BB","CC","AA"),y=1:4)
> str(df)
'data.frame':   4 obs. of  2 variables:
 $ x: Factor w/ 3 levels "AA","BB","CC": 1 2 3 1  $ y: int  1 2 3 4

> I want to modify this df this way :
>  if df$x=="AA" then df$y=df$y*10
>  if df$x=="BB" then df$y=df$y*25
>
> and so on with other conditions.
>

 df$y<- df$y * c(10,25,.5)[df$x]
[1] 10.0 50.0  1.5 40.0
 # 1*10 2*25 3*.5 4*10

HTH

Elai

> TY for any help.
>
> Trading
>
> A2CT2 Ltd.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] listing array after loop

2012-02-24 Thread Petr Savicky
On Fri, Feb 24, 2012 at 09:48:16AM -0800, uday wrote:
> 
> I want to create r object from my data set.
> I have several data files  and I would like to read individual parameter
> from file and save all 10 files parameter in a single array 
> e.g 
> setwd("/temp/")
> file_s <- list.files(path = ".", pattern = "0b.was", all.files = FALSE,
> full.names = FALSE, recursive = FALSE, ignore.case =
> FALSE)
>   lat   <- NULL
>   lon  <- NULL
>   ch4<- NULL
> for ( i in 1:10) { 
>   data<-   read.table(file_s[i],header=TRUE,skip=55 ) 
>   lat[i]   = data[,7] # latitude
>   temp.lon  = data[,8] # longitude
> # the longitude data is in 360 degree format need to convert to -180 to 180
>   lon[i] =  ((temp.lon+180) %% 360 ) - 180 
>   ch4[i]=  data[,45] # ch4
> }
> 
> save (lat,lon,ch4, file="myData.RData"")
> 
> but some how it does not work . 

Hi.

If you get an error message, please, send it. If you get a
result, but it differs from what you expect, explain, what
is wrong. At the first glance, i do not see anything
suspicious. However, i do not know, what is the contents
of the files file_s[i] and whether the number of file
names in file_s is at least 10.

Petr Savicky.

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

2012-02-24 Thread ilai
On Fri, Feb 24, 2012 at 8:11 AM, A2CT2 Trading  wrote:
> Dear list,
>
> n00b question, but still can't find any easy answer.
>
> Here is a df:
>
>> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))

# No, your y is a factor
 str(df)
'data.frame':   4 obs. of  2 variables:
 $ x: Factor w/ 3 levels "AA","BB","CC": 1 2 3 1
 $ y: Factor w/ 4 levels "1","2","3","4": 1 2 3 4

# You want to remove the cbind
> df<-data.frame(x=c("AA","BB","CC","AA"),y=1:4)
> str(df)
'data.frame':   4 obs. of  2 variables:
 $ x: Factor w/ 3 levels "AA","BB","CC": 1 2 3 1
 $ y: int  1 2 3 4

> I want to modify this df this way :
>  if df$x=="AA" then df$y=df$y*10
>  if df$x=="BB" then df$y=df$y*25
>
> and so on with other conditions.
>

 df$y<- df$y * c(10,25,.5)[df$x]
[1] 10.0 50.0  1.5 40.0
 # 1*10 2*25 3*.5 4*10

HTH

Elai

> TY for any help.
>
> Trading
>
> A2CT2 Ltd.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] multhist weird behavior/ xlabels wrong

2012-02-24 Thread Laura Matrajt

Hi Jim,
thanks for your reply, I will try using this instead!
best,
Laura



On Feb 24, 2012, at 3:09 AM, Jim Lemon wrote:

> On 02/24/2012 09:30 AM, Laura Matrajt wrote:
>> 
>> Hi,
>>  I found some weird behavior of the function multhist in the plotrix package 
>> and I would like to ask you about it:
>> so, it works well to put two histograms next to each other, but I don't 
>> understand the breaks…
>> so for example,
>> library(plotrix)
>> mh<- list(rnorm(200, mean=100, sd=10), rnorm(200, mean=100, sd=10))
>> multhist(mh)   #produces a plot with 
>> 12 bins
>> multhist(mh, breaks=2)#produces a plot with 2 bins, 
>> as expected
>> multhist(mh, breaks=3) #produces a plot with 4 
>> bins???
>> multhist(mh, breaks=4) #produces a plot with 4 bins
>> multhist(mh, breaks=7) #produces a plot with 6 
>> bins???
>> 
>> etc. So odd number of breaks doesn't seem to work, and even more, some times 
>> it does the lowest even number of bins (so if I put breaks=7 I will get 6 
>> bins) but other times it does the highest even number of bins (so if I put 
>> breaks=3 I get 4 bins)
>> 
>> In addition, things become even worse when you try to add labels to the bins.
>> 
>> 
>> So, all this to say that I am trying to put two histograms side to side, and 
>> put some correct number of bins and labels… does anyone have an idea of how 
>> to do this?
> 
> Hi Laura,
> This may be due to the way breaks are calculated when you just specify a 
> suggested number of bins. However, when I tried this with barp:
> 
> mhmat<-rbind(table(cut(mh[[1]],breaks=3)),
> table(cut(mh[[2]],breaks=3)))
> library(plotrix)
> barp(mhmat)
> 
> I got what I expected, three groups of two bars. Perhaps this will do what 
> you want.
> 
> Jim


[[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] Speeding up "accumulation" code in large matrix calc?

2012-02-24 Thread Petr Savicky
On Fri, Feb 24, 2012 at 08:59:44AM -0800, robertfeldt wrote:
> Hi,
> 
> I have R code like so:
> 
> num.columns.back.since.last.occurence <- function(m, outcome) {
>   nrows <- dim(m)[1];
>   ncols <- dim(m)[2];
>   res <- matrix(rep.int(0, nrows*ncols), nrow=nrows);
>   for(row in 1:nrows) {
>   for(col in 2:ncols) {
>   res[row,col] <- if(m[row,col-1]==outcome) {0} else 
> {1+res[row,col-1]}
>   }
>   }
>   res;
> }
> 
> but on the very large matrices I apply this the execution times are a
> problem. I would appreciate any help to rewrite this with more
> "standard"/native R functions to speed things up.

Hi.

If the number of rows is large and the number of columns is not,
then try the following.

  # random matrix
  A <- matrix((runif(49) < 0.2) + 0, nrow=7)
  outcome <- 1

  # transformation
  B <- array(0, dim=dim(A))
  curr <- B[, 1]
  for (i in seq.int(from=2, length=ncol(A)-1)) {
  curr <- ifelse (A[, i-1] == outcome, 0, 1 + curr)
  B[, i] <- curr
  }

  # verify
  all(num.columns.back.since.last.occurence(A, 1) == B)

  [1] TRUE

Hope this helps.

Petr Savicky.

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

2012-02-24 Thread Prof Brian Ripley

On 24/02/2012 16:30, Annalisa Orenti wrote:

Dear R-Users,
I've recently used relsurv package for relative survival analysis. In 
particular I've tried to reproduce the examples proposed in the R-documentation 
about rsadd, rsmul and rstrans functions in R latest version (R 2.14.1). These 
examples don't run and the error message is always the following:

data(slopop)
data(rdata)
rsadd(Surv(time,cens)~sex+as.factor(agegr)+ratetable(age=age*365,sex=sex,year=year),ratetable=slopop,data=rdata,int=5)
Errore in .Call("pyears3b", as.integer(death), as.integer(rfac), 
as.integer(atts$dim),  :
  C symbol name "pyears3b" not in DLL for package "survival"

However I've tried to reproduce the same examples in R oldest version (R 2.9.2) 
and they correctly run.
Do you have any suggestions?


1) Read and follow the posting guide.

2) Update your relsurv, from the sources if necessary.  It needed an 
update to the current version of survival (way later than R 2.14.1).



Thank you for your help.
Best regards.
Annalisa

[[alternative HTML version deleted]]


It is contemptuous to send HTML when expressly asked not to ...


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



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

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


Re: [R] install rJava in Ubuntu 11.10

2012-02-24 Thread Arnaud Gaboury
As a Linux user, I know you are not running exactly the same Java as on 
windows. It exists some copyright issues which prevent you to run Sun Java on 
your Linux box. 
As shown, you are running in fact openJDK. If result is the same for you, being 
able to run Java, it is not the same for most apps.
Install folders are different, and I guess R cannot find the right place for 
your Java environment.

Try to google more on this issue (Java on Linux openJDK install folder), or 
anything about "building Android on Linux"( same problem as Android needs 
java). There is something you could try: add the openJDK path in your 
environment.

Hope this help.


Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of John Kane
Sent: vendredi 24 février 2012 19:32
To: r-help@r-project.org
Subject: [R] install rJava in Ubuntu 11.10

I am trying to install rJava on a WUBI  Ubuntu 11.10 installation of R with no 
luck. I was originally trying to install the iplots package and encountered 
this rJava problem.

Code used:
install.packages("rJava")

(CRAN mirrors --Canada(ON) and Canada(QC2)

I installed iplots with no problem on Windows 7.

I know just about zero about Ubuntu or Linux in general so I have no idea what 
I am doing.

Any suggestions would be gratefully received.

I am getting the error/warning messages below.
=

Cannot compile a simple JNI program. See config.log for details.

Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run "R CMD javareconf" as root.

ERROR: configuration failed for package ‘rJava’
* removing ‘/home/john/R/i686-pc-linux-gnu-library/2.13/rJava’

The downloaded packages are in
‘/tmp/RtmphfnJ62/downloaded_packages’
Warning message:
In install.packages("rJava") :
  installation of package 'rJava' had non-zero exit status 
=
EXISTING JAVA INSTALLAION

john@ubuntu:~$ java -version
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1) 
OpenJDK Client VM (build 20.0-b11, mixed mode, sharing)

===

I have re-run "R CMD javareconf" as root.

Does the R CMC javareconf need something added?
(i.e. R CMD javaconf xxx)

Do I really need a  Java Development Kit installed?

sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C   

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


Publish your photos in seconds for FREE
TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4

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

2012-02-24 Thread Aldo
Ok so my problem is I am running a shell command to copy certain file types
from one directory to another and it returns multiple errors

the code is

models=c("1sFE1cFE","1sFE1cFEp")
for(m in 1:length(models)){
shell(paste("robocopy C:\\Sim_Test_1\\Sim",models[m]," ","
C:\\Sim_Test_1\\SimArchive\\Sim",dirnum,"\\pinrepstd *.std *.rep *.tpl *.pin
*crap.txt",sep=""),wait=TRUE)
}

the errors are 

Warning messages:
1: running command 'C:\WINDOWS\system32\cmd.exe /c robocopy
C:\Sim_Test_1\Sim1sFE1cFE  C:\Sim_Test_1\SimArchive\Sim001\pinrepstd *.std
*.rep *.tpl *.pin *crap.txt' had status 1 
2: In shell(paste("robocopy C:\\Sim_Test_1\\Sim", models[m], " ", "
C:\\Sim_Test_1\\SimArchive\\Sim",  :
  'robocopy C:\Sim_Test_1\Sim1sFE1cFE 
C:\Sim_Test_1\SimArchive\Sim001\pinrepstd *.std *.rep *.tpl *.pin *crap.txt'
execution failed with error code 1
3: running command 'C:\WINDOWS\system32\cmd.exe /c robocopy
C:\Sim_Test_1\Sim1sFE1cFEp  C:\Sim_Test_1\SimArchive\Sim001\pinrepstd *.std
*.rep *.tpl *.pin *crap.txt' had status 3 
4: In shell(paste("robocopy C:\\Sim_Test_1\\Sim", models[m], " ", "
C:\\Sim_Test_1\\SimArchive\\Sim",  :
  'robocopy C:\Sim_Test_1\Sim1sFE1cFEp 
C:\Sim_Test_1\SimArchive\Sim001\pinrepstd *.std *.rep *.tpl *.pin *crap.txt'
execution failed with error code 3

I am not sure what the error codes mean, is there a way to decipher them?



--
View this message in context: 
http://r.789695.n4.nabble.com/shell-command-with-Robocopy-error-tp4418254p4418254.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] R CMD INSTALL fails where R CMD check succeeds.

2012-02-24 Thread Rob Steele
That's it!  I was mounting /tmp with the noexec option.  That was the 
problem.  Thanks!


On 2/24/2012 12:56 PM, Prof Brian Ripley wrote:

Guess: did you set TMPDIR to somewhere you are allowed to execute
scripts?


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Speeding up "accumulation" code in large matrix calc?

2012-02-24 Thread Petr Savicky
On Fri, Feb 24, 2012 at 08:59:44AM -0800, robertfeldt wrote:
> Hi,
> 
> I have R code like so:
> 
> num.columns.back.since.last.occurence <- function(m, outcome) {
>   nrows <- dim(m)[1];
>   ncols <- dim(m)[2];
>   res <- matrix(rep.int(0, nrows*ncols), nrow=nrows);
>   for(row in 1:nrows) {
>   for(col in 2:ncols) {
>   res[row,col] <- if(m[row,col-1]==outcome) {0} else 
> {1+res[row,col-1]}
>   }
>   }
>   res;
> }
> 
> but on the very large matrices I apply this the execution times are a
> problem. I would appreciate any help to rewrite this with more
> "standard"/native R functions to speed things up.

Hi.

If the number of columns is large, so the rows are long, then
the following can be more efficient.

  oneRow <- function(x, outcome)
  {
  n <- length(x)
  y <- c(0, cumsum(x[-n] == outcome))
  ave(x, y, FUN = function(z) seq.int(along=z) - 1)
  }

  # random matrix 
  A <- matrix((runif(49) < 0.2) + 0, nrow=7)

  # the required transformation
  B <- t(apply(A, 1, oneRow, outcome=1))

  # verify
  all(num.columns.back.since.last.occurence(A, 1) == B)

  [1] TRUE

This solution performs a loop over rows (in apply), so if the
number of rows is large and the number of columns is not,
then a solution, which uses a loop over columns, may be
better.

Hope this helps.

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] tcl tk command function with arguments ??

2012-02-24 Thread ilai
On Fri, Feb 24, 2012 at 12:58 AM, Alexander  wrote:

> I would like to know if its possible to use a function with arguments as a
> command in tcl tk.

Yes


 I think
> this is due to the fact that the PressedOK(3) was the last call of the
> function, but I don't understand why all the other buttons have now a
> different command. Any idea?
>

Because in for loop i is overwritten every time - as you said i=3 is
the last command.
Replacing for with sapply should fix it:

require(tcltk)
OK.but <- NULL
PressedOK <- function(i)
{
   tkmessageBox(message=paste("You pressed OK!",i,sep=""))
}

tt <- tktoplevel()
sapply(1:3,function(i){
  OK.but[[i]] <- tkbutton(tt,text="OK",command=function()PressedOK(i))
  tkgrid(OK.but[[i]])
})
tkfocus(tt)

Cheers,
Elai


> Thanks
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/tcl-tk-command-function-with-arguments-tp4416470p4416470.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] install rJava in Ubuntu 11.10

2012-02-24 Thread John Kane
I am trying to install rJava on a WUBI  Ubuntu 11.10 installation of R with no 
luck. I was originally trying to install the iplots package and encountered 
this rJava problem.

Code used:
install.packages("rJava")

(CRAN mirrors --Canada(ON) and Canada(QC2)

I installed iplots with no problem on Windows 7.

I know just about zero about Ubuntu or Linux in general so I have no idea what 
I am doing.

Any suggestions would be gratefully received.

I am getting the error/warning messages below.
=

Cannot compile a simple JNI program. See config.log for details.

Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run "R CMD javareconf" as root.

ERROR: configuration failed for package ‘rJava’
* removing ‘/home/john/R/i686-pc-linux-gnu-library/2.13/rJava’

The downloaded packages are in
‘/tmp/RtmphfnJ62/downloaded_packages’
Warning message:
In install.packages("rJava") :
  installation of package 'rJava' had non-zero exit status
=
EXISTING JAVA INSTALLAION

john@ubuntu:~$ java -version
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)
OpenJDK Client VM (build 20.0-b11, mixed mode, sharing)

===

I have re-run "R CMD javareconf" as root.

Does the R CMC javareconf need something added?
(i.e. R CMD javaconf xxx)

Do I really need a  Java Development Kit installed?

sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C   

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


Publish your photos in seconds for FREE
TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] strange behaviour of "POSIXlt" "POSIXt" object

2012-02-24 Thread jim holtman
What version of R are you using.  Here is the results with 2.14.1 under
Windows:

> x <- as.POSIXlt("2009-03-29 06:30:00")
>
> x
[1] "2009-03-29 06:30:00"
> class(x)
[1] "POSIXlt" "POSIXt"
> is.na(x)
[1] FALSE
>


On Fri, Feb 24, 2012 at 12:57 PM, ikuzar  wrote:

> Hi,
> Does anybody know why get I this kind of strange situation:
>
> Browse[2]> hcEnd
> [1] "2009-03-29 06:30:00"
> Browse[2]> class(hcEnd)
> [1] "POSIXlt" "POSIXt"
> Browse[2]> is.na(hcEnd)
> [1] TRUE
>
> This issue is the source of my all issues in my program,
>
> Thanks for your help
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/strange-behaviour-of-POSIXlt-POSIXt-object-tp4418115p4418115.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.
>



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

[[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] strange behaviour of "POSIXlt" "POSIXt" object

2012-02-24 Thread Curt Seeliger
> Does anybody know why get I this kind of strange situation:
> 
> Browse[2]> hcEnd
> [1] "2009-03-29 06:30:00"
> Browse[2]> class(hcEnd)
> [1] "POSIXlt" "POSIXt" 
> Browse[2]> is.na(hcEnd)
> [1] TRUE

pp<-as.POSIXlt("2009-03-29 06:30:00")
pp
[1] "2009-03-29 06:30:00"
class(pp)
[1] "POSIXlt" "POSIXt" 
is.na(pp)
[1] FALSE

So we can't repeat your example.

-- 
Curt Seeliger, Data Ranger
Raytheon Information Services - Contractor to ORD
seeliger.c...@epa.gov
541/754-4638



[[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] strange behaviour of "POSIXlt" "POSIXt" object

2012-02-24 Thread R. Michael Weylandt
Can you dput(hcEnd) and give a snippet of the code that generates it?

Michael

On Feb 24, 2012, at 12:57 PM, ikuzar  wrote:

> Hi, 
> Does anybody know why get I this kind of strange situation:
> 
> Browse[2]> hcEnd
> [1] "2009-03-29 06:30:00"
> Browse[2]> class(hcEnd)
> [1] "POSIXlt" "POSIXt" 
> Browse[2]> is.na(hcEnd)
> [1] TRUE
> 
> This issue is the source of my all issues in my program, 
> 
> Thanks for your help
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/strange-behaviour-of-POSIXlt-POSIXt-object-tp4418115p4418115.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] permutation approach to know effect of one factor (factor A) to another (factor B) in each level of factor A (although it is slow)

2012-02-24 Thread Kazunari Nozue
Hi all,
 
At first I will explain my linear mixed effects model;
lme1 <- lme(leaf_length ~ 
Treatment*Genotype*leaf,random=~Treatment|Set,data=data)

or
lmer1 <- lmer(leaf~Treatment*Genotype*leaf+(Treatment|Set),data=data)

 
Treatment factor has two conditions: mock (=Mo) and treatment(=Tr)
Leaf is position of leaf: 3rd leaf, 4th leaf, 
Genotype is type of plant: wt, mut1, mut2, ., mut72
Set is experimental replicates: A to J.
I would like to ask how to compare leaf length under condition A and one under 
condition B in each Genotype, i.e. know effect of one factor (factor A, 
“Genotype”) to another (factor B, “Treatment’) in each level of factor A (eg. 
“wt”, “mut1”, “mut2”, ...).
Since my data is unbalanced data, I could not use TukeyHSD() multiple 
comparison (see its help).
My understanding is that pvalue in summary(lme1)$tTable is controversial and 
pvals.fnc(lmer1) # in languageR package
gave me an error (due to (Treatment|Set) because (1|Set) did not gave me an 
error, but (Treatment\SET) is essential in this model.).

As seen below, I would like to know my permutation method is OK or not.
 
I started from a simple permutation approach from Maindonald and Braun (2003) 
"Data Analysis and Graphics Using R." pg 98. (see scripts below) and I combined 
my mixed model and this approach with simulated data (omitting leaf factor to 
simplify, see scripts below). Disadvantage of this method is running time could 
be long in large data sets with many permutation (eg. 1), I would like to 
know my method is OK. If I could have better methods (probably by using 
multcomp package, such as glht() function), I would really appreciate them.

Sorry for long message.
 
Thank you,
 
Kazu
##
### Maindonald nad Braun pg. 98
##
library(DAAG)
data(two65) # from DAAG package
x1 <- two65$ambient;x2<-two65$heated;x<-c(x1,x2)
n1<-length(x1);n2<-length(x2);n<-n1+n2
dbar<-mean(x2) - mean(x1)
z<-array(,2000)

for(i in 1:2000) {
mn<-sample(n,n2,replace=FALSE)
dbardash<-mean(x[mn])-mean(x[-mn])
z[i]<-dbardash
}

pval<-(sum(z > abs(dbar)) + sum(z< -abs(dbar)))/2000
plot(density(z),yaxs="i")
abline(v=dbar)
abline(v=-dbar,lty=2)
###
### my example with unbalanced data
###
library(lme4)
#simulate data. leaf length in Tr is longer than Mo. wt shows more dramatic 
response to Tr than mut. setA plants were longer than setB plants (set factor 
is significant in this model).
set.seed(1234)
data <- 
data.frame(Treatment=rep(c("Tr","Mo"),c(9,11)),leaf=c(rnorm(9,11),rnorm(11,10)),Set=rep(c("A","B"),times=10))
data$Genotype <- factor(rep(c("mut","wt"),each=5,length.out=20))
#add setA specific effect for shade and then for sun
data$leaf[data$Treatment=="Tr" & data$Set=="A"] <- 
data$leaf[data$Treatment=="Tr" & data$Set=="A"] + 
rnorm(length(data$leaf[data$Treatment=="Tr" & data$Set=="A"]),1)
data$leaf[data$Treatment=="Tr" & data$Genotype=="mut"] <- 
data$leaf[data$Treatment=="Tr" & data$Genotype=="mut"] + 
rnorm(length(data$leaf[data$Treatment=="Tr" & data$Genotype=="mut"]),-0.5)
data$leaf[data$Treatment=="Mo" & data$Set=="A"] <- 
data$leaf[data$Treatment=="Mo" & data$Set=="A"] + 
rnorm(length(data$leaf[data$Treatment=="Mo" & data$Set=="A"]),-0.25)
data
# mean from observed data
mean.table.obs<-tapply(data$leaf, list(data$Treatment,data$Genotype),mean)
# permutation
mean.table.PER<-list()
nreps<-1000
z<-list() # mean differences

for(i in 1:nreps) {
new.data<-data.frame()

new.wt<-sample(data[data$Genotype=="wt",]$leaf,sum(data$Genotype=="wt",na.rm=TRUE),replace=FALSE)
 # null hypothesis: leaf in Mo = Tr in wt

new.mut<-sample(data[data$Genotype=="mut",]$leaf,sum(data$Genotype=="mut",na.rm=TRUE),replace=FALSE)

new.data<-data.frame(leaf=c(new.wt,new.mut),Genotype=data$Genotype,Treatment=data$Treatment,Set=data$Set)
# mixed effect model
lmer.temp<- lmer(leaf~Treatment*Genotype+(Treatment|Set),data=new.data)
#calculate mean of each group
mean.table.PER[[i]]<-tapply(fitted(lmer.temp), 
list(new.data$Treatment,new.data$Genotype),mean)
z[[i]]<-mean.table.PER[[i]][2,] - mean.table.PER[[i]][1,]
}

# calculate p value
TF1<-list()
TF2<-list()
p.value<-vector()

for(i in 1:length(levels(data$Genotype))) {
for(n in 1:length(z)) {
 TF1[[n]]<-  (z[[n]][i] > abs(mean.table.obs[2,i] - 
mean.table.obs[1,i]))*1
 TF2[[n]]<-  (z[[n]][i] < -abs(mean.table.obs[2,i] - 
mean.table.obs[1,i]))*1
  }
p.value[i]<-(sum(as.numeric(TF1) + as.numeric(TF2)))/length(z)
}

names(p.value)<-levels(data$Genotype)
p.value
p.adjust<-p.adjust(p=p.value,method=”fdr”)
p.adjust
# graph
par(mfcol=c(2,1))
hist(unlist(z)[names(unlist(z))=="mut"],breaks=seq(-5,5,0.2))
abline(v=abs(mean.table.obs[2,1] - mean.table.obs[1,1]))
abline(v=-abs(mean.table.obs[2,1] - mean.table.obs[1,1]))

hist(unlist(z)[names(unlist(z))=="wt"],breaks=seq(-5,

Re: [R] help filtering points from a scatterplot

2012-02-24 Thread Dallas
Okay. I think I understand now. You would just like nothing to be plotted for
the points below a certain threshold but there will still be that space
indexing where the point would've gone. I hope I have this right. 

So what you could do to fix that is to make a new matrix (still including
all the data) and then make values above a certain threshold NA. 


#Make up some data 
> a=seq(1,100,by=1) 
> b=runif(100,0,0.5) 

#Make a matrix 
> matrix=cbind(a,b) 

#Make values above a threshold = NA
> newmatrix=matrix
> newmatrix[,2][which(newmatrix[,2]<0.1)]<-NA

#Plot values 
>  plot(newmatrix[,2]~newmatrix[,1], ylim=c(0,1), las=1, ylab='Explan',
> xlab='Window') 


Okay. You just solved it. I'll still post this if you would like to use it. 

Tad


--
View this message in context: 
http://r.789695.n4.nabble.com/help-filtering-points-from-a-scatterplot-tp4415833p4418169.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] strange behaviour of "POSIXlt" "POSIXt" object

2012-02-24 Thread ikuzar
Hi, 
Does anybody know why get I this kind of strange situation:

Browse[2]> hcEnd
[1] "2009-03-29 06:30:00"
Browse[2]> class(hcEnd)
[1] "POSIXlt" "POSIXt" 
Browse[2]> is.na(hcEnd)
[1] TRUE

This issue is the source of my all issues in my program, 

Thanks for your help

--
View this message in context: 
http://r.789695.n4.nabble.com/strange-behaviour-of-POSIXlt-POSIXt-object-tp4418115p4418115.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] listing array after loop

2012-02-24 Thread uday

I want to create r object from my data set.
I have several data files  and I would like to read individual parameter
from file and save all 10 files parameter in a single array 
e.g 
setwd("/temp/")
file_s <- list.files(path = ".", pattern = "0b.was", all.files = FALSE,
full.names = FALSE, recursive = FALSE, ignore.case =
FALSE)
  lat   <- NULL
  lon  <- NULL
  ch4<- NULL
for ( i in 1:10) { 
  data<-   read.table(file_s[i],header=TRUE,skip=55 ) 
  lat[i]   = data[,7] # latitude
  temp.lon  = data[,8] # longitude
# the longitude data is in 360 degree format need to convert to -180 to 180
  lon[i] =  ((temp.lon+180) %% 360 ) - 180 
  ch4[i]=  data[,45] # ch4
}

save (lat,lon,ch4, file="myData.RData"")

but some how it does not work . 

How to list all data in single array after loop .




--
View this message in context: 
http://r.789695.n4.nabble.com/listing-array-after-loop-tp4418081p4418081.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] UT Summer Statistics Institute--info for R-help

2012-02-24 Thread SSC Postdoc Search
Dear R-help,

The Division of Statistics + Scientific Computation at The University of
Texas at Austin will be hosting the University¹s fifth annual UT Summer
Statistics Institute on the UT Austin campus from May 21 ­ May 24, 2012.
Short courses are offered at all levels including introductory statistics,
software, and statistical methods and applications. We are offering the
following courses using or teaching R: An Introduction to R: General
Usage, Data Analysis, and Graphics; Power Analysis for Proposal Writing;
Advanced Regression; and Introduction to Data Mining.

The three main purposes of the SSI are:
€   To provide participants with access to new statistical knowledge and
skills
€   To give participants hands-on experience with data analysis
€   To prepare participants to interpret studies employing statistical
methods.

Registration is now open. Students receive a 60% discount and groups can
receive a 20% discount off the regular $500 course fee. Visit our website
at http://www.ssc.utexas.edu to download the UT Summer Statistics
Institute brochure and learn more.

Marilyn Harris

-- 
Marilyn Harris
Administrative Associate
Division of Statistics + Scientific Computation
College of Natural Sciences
Will C. Hogg (WCH) 2.104C
(512) 471-7618
marilynhar...@austin.utexas.edu

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


[R] Producing KML files

2012-02-24 Thread Desflots, Melicie
Hi,

I am very new to R and I am trying to write KML files. I am running R-2.13.1 
and I have the following packages:

-  AKIMA

-  RGDAL

-  RSAGA

-  SP


I was trying to run the simple example that I found at the following web page:
http://spatial-analyst.net/wiki/index.php?title=Export_maps_to_GE

The lines that I can run are:

data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
gridded(meuse.grid) <- TRUE
proj4string(meuse.grid) = CRS("+init=epsg:28992")
# raster to polygon conversion;
writeGDAL(meuse.grid["soil"], "meuse_soil.sdat", "SAGA", mvFlag=-9)
rsaga.geoprocessor(lib="shapes_grid", module=6,
   param=list(GRID="meuse_soil.sgrd", 
POLYGONS="meuse_soil.shp", CLASS_ALL=1))

and it crashes there with the following error message:

Error in setwd(env$workspace) : character argument expected
In addition: Warning message:
In rsaga.env() :
  SAGA command line program 'saga_cmd.exe' not found in any of the paths
C:/Program Files/R/R-2.13.1/library/RSAGA/saga_vc
C:/Program Files/R/R-2.13.1/library/RSAGA/SAGA-GIS
...

Can someone please let me know what I should do to fix that error?

Thanks,
Mel


[[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] saving all data in r object

2012-02-24 Thread uday
Hi Iris,
thanks for reply 

but this solution does not work 


Uday 

--
View this message in context: 
http://r.789695.n4.nabble.com/saving-all-data-in-r-object-tp4413092p4417933.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] NaN's in class 'performance; [package "ROCR"]

2012-02-24 Thread Chet Seligman
The first item in @ y.values is a NaN
Slot "y.values":
[[1]]
  [1]   NaN 1.000

How do replace it with 1.00 or otherwise get rid of it?

Chet

[[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] Speeding up "accumulation" code in large matrix calc?

2012-02-24 Thread robertfeldt
Hi,

I have R code like so:

num.columns.back.since.last.occurence <- function(m, outcome) {
nrows <- dim(m)[1];
ncols <- dim(m)[2];
res <- matrix(rep.int(0, nrows*ncols), nrow=nrows);
for(row in 1:nrows) {
for(col in 2:ncols) {
res[row,col] <- if(m[row,col-1]==outcome) {0} else 
{1+res[row,col-1]}
}
}
res;
}

but on the very large matrices I apply this the execution times are a
problem. I would appreciate any help to rewrite this with more
"standard"/native R functions to speed things up.

--
View this message in context: 
http://r.789695.n4.nabble.com/Speeding-up-accumulation-code-in-large-matrix-calc-tp4417911p4417911.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] package relsurv

2012-02-24 Thread Annalisa Orenti
Dear R-Users,
I've recently used relsurv package for relative survival analysis. In 
particular I've tried to reproduce the examples proposed in the R-documentation 
about rsadd, rsmul and rstrans functions in R latest version (R 2.14.1). These 
examples don't run and the error message is always the following:
 
data(slopop)
data(rdata)
rsadd(Surv(time,cens)~sex+as.factor(agegr)+ratetable(age=age*365,sex=sex,year=year),ratetable=slopop,data=rdata,int=5)
Errore in .Call("pyears3b", as.integer(death), as.integer(rfac), 
as.integer(atts$dim),  : 
 C symbol name "pyears3b" not in DLL for package "survival"

However I've tried to reproduce the same examples in R oldest version (R 2.9.2) 
and they correctly run.
Do you have any suggestions?
Thank you for your help.
Best regards.
Annalisa
  
[[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] Solved: RE: help filtering points from a scatterplot

2012-02-24 Thread Vining, Kelly
Thanks again for your help. I did indeed solve the problem by plotting the 
initial graph as type='n', then adding my subset of points using 'points'.

Cheers,
--Kelly V.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Dallas
Sent: Friday, February 24, 2012 5:58 AM
To: r-help@r-project.org
Subject: Re: [R] help filtering points from a scatterplot

I believe this is what you want to do, though it may need tweaking.

#Make up some data
> a=seq(1,100,by=1)
> b=runif(100,0,0.5)

#Make a matrix
> matrix=cbind(a,b)

#Subset the matrix based upon values of interest
> subsetmatrix=matrix[which(b<0.1),]

#Plot values
> 
> plot(subsetmatrix[,2]~subsetmatrix[,1],ylim=c(0,1),las=1,ylab='Explan',xlab='Window')


Hope this helps. 



--
View this message in context: 
http://r.789695.n4.nabble.com/help-filtering-points-from-a-scatterplot-tp4415833p4417247.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] data frame manipulation with condition

2012-02-24 Thread William Dunlap
When a factor is used as a subscript it is treated
as its integer codes so explicit conversion to character
is needed if you want to subscript by names:
  > f <- factor(c("One","Three","Two"), levels=c("One","Two","Three"))
  > x <- c(Two=2, One=1, Three=3)
  > x[f]
Two Three   One 
  2 3 1 
  > x[as.character(f)]
One Three   Two 
  1 3 2
For most other functions (e.g., %in%, paste, sprintf("%s"))
you do not need an explicit conversion to character, but '['
requires you to choose.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -Original Message-
> From: Sarah Goslee [mailto:sarah.gos...@gmail.com]
> Sent: Friday, February 24, 2012 9:39 AM
> To: William Dunlap
> Cc: Arnaud Gaboury; r-help@r-project.org
> Subject: Re: [R] data frame manipulation with condition
> 
> On Fri, Feb 24, 2012 at 12:23 PM, William Dunlap  wrote:
> > Use mult[as.character(df$x)] instead of mult[df$x].
> > They are different when df$x is a factor and the
> > character version is what you want.
> 
> R will coerce a factor to character to perform the comparison; explicitly
> calling as.character() is not necessary:
> 
> > df$x
> [1] AA BB CC AA DD DD
> > df$x == "AA"
> [1]  TRUE FALSE FALSE  TRUE FALSE FALSE
> 
> See ?factor for details.
> 
> Sarah
> 
> >  > df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
> >  > mult <- c(AA = 10, BB = 25,DD=15)
> >  > df$y <- df$y * mult[as.character(df$x)]
> >  > df
> >     x  y
> >  1 AA 10
> >  2 BB 50
> >  3 CC NA
> >  4 AA 40
> >  5 DD 75
> >  6 DD 90
> >
> > This gets the order right.  The NA for "CC" is because
> > your vector of multipliers didn't include an entry for
> > CC.  You can either add CC=1 to mult or work only on the
> > subset of the data which has entries in the mult vector.
> >
> >  > df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
> >  > mult <- c(AA = 10, BB = 25,DD=15)
> >  > i <- as.character(df$x) %in% names(mult)
> >  > df$y[i] <- df$y[i] * mult[as.character(df$x[i])]
> >  > df
> >     x  y
> >  1 AA 10
> >  2 BB 50
> >  3 CC  3
> >  4 AA 40
> >  5 DD 75
> >  6 DD 90
> >
> > 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 Arnaud
> Gaboury
> >> Sent: Friday, February 24, 2012 8:37 AM
> >> To: Uwe Ligges
> >> Cc: r-help@r-project.org
> >> Subject: Re: [R] data frame manipulation with condition
> >>
> >> > df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
> >> > mult <- c(AA = 10, BB = 25,DD=15)
> >> > df$y <- df$y * mult[df$x]
> >> > df
> >>    x  y
> >> 1 AA 10
> >> 2 BB 50
> >> 3 CC 45
> >> 4 AA 40
> >> 5 DD NA
> >> 6 DD NA
> >>
> >> My df is in fact much more longer than the chosen example shown here. It 
> >> seems your tip didn't do
> the
> >> job.
> >> I am expecting this as result :
> >>
> >> > df
> >>    x  y
> >> 1 AA 10  > if df$x==AA, df$y<-1*10
> >> 2 BB 50   > if df$x==BB, df$y<-2*25
> >> 3 CC 3         NOTHING
> >> 4 AA 40    > if df$x==AA, df$y<-4*10
> >> 5 DD 75   > if df$x==DD, df$y<-5*15
> >> 6 DD 90   > if df$x==DD, df$y<-6*15
> >>
> >> Arnaud Gaboury
> >>
> >> A2CT2 Ltd.
> >>
> >> -Original Message-
> >> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
> >> Sent: vendredi 24 février 2012 17:07
> >> To: Arnaud Gaboury
> >> Cc: r-help@r-project.org
> >> Subject: Re: [R] data frame manipulation with condition
> >>
> >>
> >>
> >> On 24.02.2012 16:59, Arnaud Gaboury wrote:
> >> > TY Uwe,
> >> >
> >> > So I will have to write a line for each condition? Right?
> >> >
> >> > In fact I was trying to do something with apply in one line, but 
> >> > couldn't achieve any result. In
> >> fact, all my transformation will be multiplying one object by a specific 
> >> number according to the
> value
> >> of df$x.
> >>
> >> In that case:
> >>
> >> mult <- c(AA = 10, BB = 25)
> >>
> >> Then:
> >>
> >>
> >> df$y <- df$y * mult[df$x]
> >>
> >>
> >> Uwe Ligges
> >>
> >>
> >> >
> >> > Arnaud Gaboury
> >> >
> >> > A2CT2 Ltd.
> >> >
> >> >
> >> > -Original Message-
> >> > From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
> >> > Sent: vendredi 24 février 2012 16:33
> >> > To: Arnaud Gaboury
> >> > Cc: r-help@r-project.org
> >> > Subject: Re: [R] data frame manipulation with condition
> >> >
> >> >
> >> >
> >> > On 24.02.2012 16:25, Arnaud Gaboury wrote:
> >> >> Dear list,
> >> >>
> >> >> n00b question, but still can't find any easy answer.
> >> >>
> >> >> Here is a df:
> >> >
> >> >
> >> > Change
> >> >
> >> >>> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
> >> >
> >> > to
> >> >
> >> >    df<- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)
> >> >
> >> > to make your object a sensible data.frame.
> >> >
> >> >
> >> >
> >> >>> df
> >> >>      x y
> >> >> 1 AA 1
> >> >> 2 BB 2
> >> >> 3 CC 3
> >> >> 4 AA 4
> >> >>
> >> >>
> >> >> I want to modify this df this way :
> >> >>    if df$

Re: [R] R CMD INSTALL fails where R CMD check succeeds.

2012-02-24 Thread Prof Brian Ripley

On 24/02/2012 15:22, Rob Steele wrote:

This is in a 64 bit CentOS 5.6 instance at Amazon AWS with R version
2.14.1 (2011-12-22). It happens on several packages: RMySQL, RODBC,
FastICA. Many other packages install just fine.


Your subject line cannot be really true: R CMD check calls R CMD 
INSTALL.  So this has to be about how you ran R CMD INSTALL.


Guess: did you set TMPDIR to somewhere you are allowed to execute 
scripts?  See the R-admin manual 



Here's an example error message:

* installing *source* package 'RODBC' ...
** package 'RODBC' successfully unpacked and MD5 sums checked
sh: ./configure: /bin/sh: bad interpreter: Permission denied
ERROR: configuration failed for package 'RODBC'
* removing '/usr/share/R/library/RODBC'
* restoring previous '/usr/share/R/library/RODBC'



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

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


Re: [R] data frame manipulation with condition

2012-02-24 Thread Sarah Goslee
Whatever makes you happy.

> df1 <-
+ structure(list(x = structure(c(1L, 2L, 2L, 3L), .Label = c("AA",
+ "BB", "CC"), class = "factor"), y = 1:4), .Names = c("x", "y"
+ ), row.names = c(NA, -4L), class = "data.frame")
> mult <- c("AA"=2,"BB"=5,"CC"=1,"DD"=2)
> df1$y * mult[df1$x]
AA BB BB CC
 2 10 15  4
> df1$y * mult[as.character(df1$x)]
AA BB BB CC
 2 10 15  4
>
>
> df2 <- data.frame(x = c("AA","AA","BB","BB","BB","CC","DD","DD"), y = 1:8)
> df2$y * mult[df2$x]
AA AA BB BB BB CC DD DD
 2  4 15 20 25  6 14 16
> df2$y * mult[as.character(df2$x)]
AA AA BB BB BB CC DD DD
 2  4 15 20 25  6 14 16


On Fri, Feb 24, 2012 at 12:52 PM, Arnaud Gaboury
 wrote:
> In fact I need to use William tip: Use mult[as.character(df$x)] instead of 
> mult[df$x].
>
>
> Let's try again with a shorter df as example:
>
> The rule: if AA, then multiply y by 2, if BB multiply y by 5, if CC do 
> nothing, if DD multiply by 2.
>
>
> Let's say day 1 I have df1:
>
> df1 <-
> structure(list(x = structure(c(1L, 2L, 2L, 3L), .Label = c("AA",
> "BB", "CC"), class = "factor"), y = 1:4), .Names = c("x", "y"
> ), row.names = c(NA, -4L), class = "data.frame")
>
>> df1
>   x y
> 1 AA 1
> 2 BB 2
> 3 BB 3
> 4 CC 4
>
>>mult <- c("AA"=2,"BB"=5,"CC"=1,"DD"=2)
>>df1$y <- df1$y * mult[as.character(df1$x)]
>> df1
>   x  y
> 1 AA  2
> 2 BB 10
> 3 BB 15
> 4 CC  4
>
> WORKING
>
> Now day 2 with df2:
>
>>df2 <- data.frame(x = c("AA","AA","BB","BB","BB","CC","DD","DD"), y = 1:8)
>>df2$y <- df2$y * mult[as.character(df2$x)]
>> df2
>   x  y
> 1 AA  2
> 2 AA  4
> 3 BB 15
> 4 BB 20
> 5 BB 25
> 6 CC  6
> 7 DD 14
> 8 DD 16
>
> WORKING
>
>
> Ty both of you and have a good weekend.
>

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

2012-02-24 Thread Arnaud Gaboury
In fact I need to use William tip: Use mult[as.character(df$x)] instead of 
mult[df$x].


Let's try again with a shorter df as example:

The rule: if AA, then multiply y by 2, if BB multiply y by 5, if CC do nothing, 
if DD multiply by 2.


Let's say day 1 I have df1:

df1 <-
structure(list(x = structure(c(1L, 2L, 2L, 3L), .Label = c("AA", 
"BB", "CC"), class = "factor"), y = 1:4), .Names = c("x", "y"
), row.names = c(NA, -4L), class = "data.frame")

> df1
   x y
1 AA 1
2 BB 2
3 BB 3
4 CC 4

>mult <- c("AA"=2,"BB"=5,"CC"=1,"DD"=2)
>df1$y <- df1$y * mult[as.character(df1$x)]
> df1
   x  y
1 AA  2
2 BB 10
3 BB 15
4 CC  4

WORKING

Now day 2 with df2:

>df2 <- data.frame(x = c("AA","AA","BB","BB","BB","CC","DD","DD"), y = 1:8)
>df2$y <- df2$y * mult[as.character(df2$x)]
> df2
   x  y
1 AA  2
2 AA  4
3 BB 15
4 BB 20
5 BB 25
6 CC  6
7 DD 14
8 DD 16

WORKING


Ty both of you and have a good weekend.


Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Arnaud Gaboury
Sent: vendredi 24 février 2012 18:17
To: Sarah Goslee
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition

TY very much Sarah: your tip is doing the job:

reported <-
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 
10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 13L, 14L, 14L), .Label = 
c("CL", "Cocoa", "Coffee C", "GC", "HG", "HO", "NG", "PL", "RB", "SI", "Sugar 
No 11", "ZC", "ZL", "ZW"), class = "factor"), reported.Price = c(105.35, 2380, 
2407, 2408, 202.35, 202.8, 202.95, 205.85, 206.05, 206.1, 206.2, 1748, 378.8, 
379.25, 379.5, 320.61, 2.538, 2.543, 1669, 1678.5, 304.49, 321.39, 321.6, 
321.65, 322.5, 322.55, 322.8, 323.04, 3390, 3397.5, 24.16, 24.2, 24.22, 24.23, 
24.54, 25.5, 25.55, 631.75, 638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 
3L, -1L, -2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 11L, -54L, 
-52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 17L, 17L, 114L, 71L, 16L, 
27L, -3L, 3L, -3L, -89L, -1L, -1L, -51L, -51L)), .Names = c("Product", 
"reported.Price", "reported.Nbr.Lots"
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 8L, 9L, 
10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 31L, 
32L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 2L, 3L, 1L, 33L, 34L), class = 
"data.frame")

> mult<-c(CL=100,GC=10,HG=10,NG=1000,PL=10,RB=100,SI=10,ZL=100,HO=100,KC
> =1,CC=1,SB=1,ZC=1,ZW=1) reported$reported.Price <- 
> reported$reported.Price * mult[reported$Product]

reported <-
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 
10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 13L, 14L, 14L), .Label = 
c("CL", "Cocoa", "Coffee C", "GC", "HG", "HO", "NG", "PL", "RB", "SI", "Sugar 
No 11", "ZC", "ZL", "ZW"), class = "factor"), reported.Price = c(10535, 23800, 
24070, 24080, 2023.5, 2028, 2029.5, 2058.5, 2060.5, 2061, 2062, 1748000, 3788, 
3792.5, 3795, 32061, 25.38, 25.43, 166900, 167850, 30449, 32139, 32160, 32165, 
32250, 32255, 32280, 32304, 3390, 3397.5, 24.16, 24.2, 24.22, 24.23, 24.54, 
25.5, 25.55, 631.75, 638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 3L, 
-1L, -2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 11L, -54L, 
-52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 17L, 17L, 114L, 71L, 16L, 
27L, -3L, 3L, -3L, -89L, -1L, -1L, -51L, -51L)), .Names = c("Product", 
"reported.Price", "reported.Nbr.Lots"
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 8L, 9L, 
10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 31L, 
32L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 2L, 3L, 1L, 33L, 34L), class = 
"data.frame")

Have a good weekend.

Arnaud Gaboury
 
A2CT2 Ltd.
Trade: +41 22 849 88 63
Fax:   +41 22 849 88 66
arnaud.gabo...@a2ct2.com 

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
Access to this email by anyone else is unauthorized. If you are not the 
intended recipient, any disclosure, copying, distribution or any action taken 
or omitted to be taken in reliance on it, is prohibited and may be unlawful. If 
you have received this email in error please notify the sender. 


-Original Message-
From: Sarah Goslee [mailto:sarah.gos...@gmail.com]
Sent: vendredi 24 février 2012 17:54
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition

You need, as I already suggested, to use a value of 1 for levels you don't want 
to change.

> mult <- c(AA = 10, BB = 25, CC=1, DD=15) mult[df$x]
AA BB CC AA DD DD
10 25  1 10 15 15
> df$y * mult[df$x]
AA BB CC AA DD DD
10 50  3 40 75 90


On Fri, Feb 24, 2012 at 11:36 AM, Arnaud Gaboury  
wrote:
>> df<- data.frame

Re: [R] help filtering points from a scatterplot

2012-02-24 Thread Vining, Kelly
Thanks for the suggestion, Tad, but that's not quite it. That is still taking a 
subset of the whole data set, so I am losing some of the x("Window") values. I 
need to be able to retain all of the x values (column a in your example), but 
not plot any points above. Maybe I need to construct a blank x-y plot first 
with the needed range of x values, then use "points" to plot my data values? 
Not sure how exactly to do that...

--Kelly V.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Dallas
Sent: Friday, February 24, 2012 5:58 AM
To: r-help@r-project.org
Subject: Re: [R] help filtering points from a scatterplot

I believe this is what you want to do, though it may need tweaking.

#Make up some data
> a=seq(1,100,by=1)
> b=runif(100,0,0.5)

#Make a matrix
> matrix=cbind(a,b)

#Subset the matrix based upon values of interest
> subsetmatrix=matrix[which(b<0.1),]

#Plot values
> 
> plot(subsetmatrix[,2]~subsetmatrix[,1],ylim=c(0,1),las=1,ylab='Explan',xlab='Window')


Hope this helps. 



--
View this message in context: 
http://r.789695.n4.nabble.com/help-filtering-points-from-a-scatterplot-tp4415833p4417247.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] data frame manipulation with condition

2012-02-24 Thread Sarah Goslee
On Fri, Feb 24, 2012 at 12:23 PM, William Dunlap  wrote:
> Use mult[as.character(df$x)] instead of mult[df$x].
> They are different when df$x is a factor and the
> character version is what you want.

R will coerce a factor to character to perform the comparison; explicitly
calling as.character() is not necessary:

> df$x
[1] AA BB CC AA DD DD
> df$x == "AA"
[1]  TRUE FALSE FALSE  TRUE FALSE FALSE

See ?factor for details.

Sarah

>  > df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
>  > mult <- c(AA = 10, BB = 25,DD=15)
>  > df$y <- df$y * mult[as.character(df$x)]
>  > df
>     x  y
>  1 AA 10
>  2 BB 50
>  3 CC NA
>  4 AA 40
>  5 DD 75
>  6 DD 90
>
> This gets the order right.  The NA for "CC" is because
> your vector of multipliers didn't include an entry for
> CC.  You can either add CC=1 to mult or work only on the
> subset of the data which has entries in the mult vector.
>
>  > df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
>  > mult <- c(AA = 10, BB = 25,DD=15)
>  > i <- as.character(df$x) %in% names(mult)
>  > df$y[i] <- df$y[i] * mult[as.character(df$x[i])]
>  > df
>     x  y
>  1 AA 10
>  2 BB 50
>  3 CC  3
>  4 AA 40
>  5 DD 75
>  6 DD 90
>
> 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 Arnaud Gaboury
>> Sent: Friday, February 24, 2012 8:37 AM
>> To: Uwe Ligges
>> Cc: r-help@r-project.org
>> Subject: Re: [R] data frame manipulation with condition
>>
>> > df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
>> > mult <- c(AA = 10, BB = 25,DD=15)
>> > df$y <- df$y * mult[df$x]
>> > df
>>    x  y
>> 1 AA 10
>> 2 BB 50
>> 3 CC 45
>> 4 AA 40
>> 5 DD NA
>> 6 DD NA
>>
>> My df is in fact much more longer than the chosen example shown here. It 
>> seems your tip didn't do the
>> job.
>> I am expecting this as result :
>>
>> > df
>>    x  y
>> 1 AA 10  > if df$x==AA, df$y<-1*10
>> 2 BB 50   > if df$x==BB, df$y<-2*25
>> 3 CC 3         NOTHING
>> 4 AA 40    > if df$x==AA, df$y<-4*10
>> 5 DD 75   > if df$x==DD, df$y<-5*15
>> 6 DD 90   > if df$x==DD, df$y<-6*15
>>
>> Arnaud Gaboury
>>
>> A2CT2 Ltd.
>>
>> -Original Message-
>> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
>> Sent: vendredi 24 février 2012 17:07
>> To: Arnaud Gaboury
>> Cc: r-help@r-project.org
>> Subject: Re: [R] data frame manipulation with condition
>>
>>
>>
>> On 24.02.2012 16:59, Arnaud Gaboury wrote:
>> > TY Uwe,
>> >
>> > So I will have to write a line for each condition? Right?
>> >
>> > In fact I was trying to do something with apply in one line, but couldn't 
>> > achieve any result. In
>> fact, all my transformation will be multiplying one object by a specific 
>> number according to the value
>> of df$x.
>>
>> In that case:
>>
>> mult <- c(AA = 10, BB = 25)
>>
>> Then:
>>
>>
>> df$y <- df$y * mult[df$x]
>>
>>
>> Uwe Ligges
>>
>>
>> >
>> > Arnaud Gaboury
>> >
>> > A2CT2 Ltd.
>> >
>> >
>> > -Original Message-
>> > From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
>> > Sent: vendredi 24 février 2012 16:33
>> > To: Arnaud Gaboury
>> > Cc: r-help@r-project.org
>> > Subject: Re: [R] data frame manipulation with condition
>> >
>> >
>> >
>> > On 24.02.2012 16:25, Arnaud Gaboury wrote:
>> >> Dear list,
>> >>
>> >> n00b question, but still can't find any easy answer.
>> >>
>> >> Here is a df:
>> >
>> >
>> > Change
>> >
>> >>> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
>> >
>> > to
>> >
>> >    df<- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)
>> >
>> > to make your object a sensible data.frame.
>> >
>> >
>> >
>> >>> df
>> >>      x y
>> >> 1 AA 1
>> >> 2 BB 2
>> >> 3 CC 3
>> >> 4 AA 4
>> >>
>> >>
>> >> I want to modify this df this way :
>> >>    if df$x=="AA" then df$y=df$y*10
>> >
>> > df$y[df$x=="AA"]<- df$y[df$x=="AA"] * 25
>> >
>> > ...
>> >
>> >
>> > Uwe Ligges
>> >
>> >
>> >>    if df$x=="BB" then df$y=df$y*25
>> >
>> >
>> >
>> >
>> >> and so on with other conditions.
>> >>
>> >> TY for any help.
>> >>
>> >> Trading
>> >>
>> >> A2CT2 Ltd.
>> >>

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

2012-02-24 Thread William Dunlap
Use mult[as.character(df$x)] instead of mult[df$x].
They are different when df$x is a factor and the
character version is what you want.

  > df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
  > mult <- c(AA = 10, BB = 25,DD=15)
  > df$y <- df$y * mult[as.character(df$x)]
  > df
 x  y
  1 AA 10
  2 BB 50
  3 CC NA
  4 AA 40
  5 DD 75
  6 DD 90

This gets the order right.  The NA for "CC" is because
your vector of multipliers didn't include an entry for
CC.  You can either add CC=1 to mult or work only on the
subset of the data which has entries in the mult vector.

  > df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
  > mult <- c(AA = 10, BB = 25,DD=15)
  > i <- as.character(df$x) %in% names(mult)
  > df$y[i] <- df$y[i] * mult[as.character(df$x[i])]
  > df
 x  y
  1 AA 10
  2 BB 50
  3 CC  3
  4 AA 40
  5 DD 75
  6 DD 90

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 Arnaud Gaboury
> Sent: Friday, February 24, 2012 8:37 AM
> To: Uwe Ligges
> Cc: r-help@r-project.org
> Subject: Re: [R] data frame manipulation with condition
> 
> > df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
> > mult <- c(AA = 10, BB = 25,DD=15)
> > df$y <- df$y * mult[df$x]
> > df
>x  y
> 1 AA 10
> 2 BB 50
> 3 CC 45
> 4 AA 40
> 5 DD NA
> 6 DD NA
> 
> My df is in fact much more longer than the chosen example shown here. It 
> seems your tip didn't do the
> job.
> I am expecting this as result :
> 
> > df
>x  y
> 1 AA 10  > if df$x==AA, df$y<-1*10
> 2 BB 50   > if df$x==BB, df$y<-2*25
> 3 CC 3 NOTHING
> 4 AA 40> if df$x==AA, df$y<-4*10
> 5 DD 75   > if df$x==DD, df$y<-5*15
> 6 DD 90   > if df$x==DD, df$y<-6*15
> 
> Arnaud Gaboury
> 
> A2CT2 Ltd.
> 
> -Original Message-
> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
> Sent: vendredi 24 février 2012 17:07
> To: Arnaud Gaboury
> Cc: r-help@r-project.org
> Subject: Re: [R] data frame manipulation with condition
> 
> 
> 
> On 24.02.2012 16:59, Arnaud Gaboury wrote:
> > TY Uwe,
> >
> > So I will have to write a line for each condition? Right?
> >
> > In fact I was trying to do something with apply in one line, but couldn't 
> > achieve any result. In
> fact, all my transformation will be multiplying one object by a specific 
> number according to the value
> of df$x.
> 
> In that case:
> 
> mult <- c(AA = 10, BB = 25)
> 
> Then:
> 
> 
> df$y <- df$y * mult[df$x]
> 
> 
> Uwe Ligges
> 
> 
> >
> > Arnaud Gaboury
> >
> > A2CT2 Ltd.
> >
> >
> > -Original Message-
> > From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
> > Sent: vendredi 24 février 2012 16:33
> > To: Arnaud Gaboury
> > Cc: r-help@r-project.org
> > Subject: Re: [R] data frame manipulation with condition
> >
> >
> >
> > On 24.02.2012 16:25, Arnaud Gaboury wrote:
> >> Dear list,
> >>
> >> n00b question, but still can't find any easy answer.
> >>
> >> Here is a df:
> >
> >
> > Change
> >
> >>> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
> >
> > to
> >
> >df<- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)
> >
> > to make your object a sensible data.frame.
> >
> >
> >
> >>> df
> >>  x y
> >> 1 AA 1
> >> 2 BB 2
> >> 3 CC 3
> >> 4 AA 4
> >>
> >>
> >> I want to modify this df this way :
> >>if df$x=="AA" then df$y=df$y*10
> >
> > df$y[df$x=="AA"]<- df$y[df$x=="AA"] * 25
> >
> > ...
> >
> >
> > Uwe Ligges
> >
> >
> >>if df$x=="BB" then df$y=df$y*25
> >
> >
> >
> >
> >> and so on with other conditions.
> >>
> >> TY for any help.
> >>
> >> Trading
> >>
> >> A2CT2 Ltd.
> >>
> >>
> >> Arnaud Gaboury
> >>
> >> A2CT2 Ltd.
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/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] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
TY very much Sarah: your tip is doing the job:

reported <-
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 12L, 12L, 13L, 14L, 14L), .Label = c("CL", "Cocoa", "Coffee C", 
"GC", "HG", "HO", "NG", "PL", "RB", "SI", "Sugar No 11", "ZC", 
"ZL", "ZW"), class = "factor"), reported.Price = c(105.35, 2380, 
2407, 2408, 202.35, 202.8, 202.95, 205.85, 206.05, 206.1, 206.2, 
1748, 378.8, 379.25, 379.5, 320.61, 2.538, 2.543, 1669, 1678.5, 
304.49, 321.39, 321.6, 321.65, 322.5, 322.55, 322.8, 323.04, 
3390, 3397.5, 24.16, 24.2, 24.22, 24.23, 24.54, 25.5, 25.55, 
631.75, 638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 3L, 
-1L, -2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 
11L, -54L, -52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 
17L, 17L, 114L, 71L, 16L, 27L, -3L, 3L, -3L, -89L, -1L, -1L, 
-51L, -51L)), .Names = c("Product", "reported.Price", "reported.Nbr.Lots"
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 8L, 9L, 10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 
38L, 39L, 40L, 41L, 42L, 31L, 32L, 24L, 25L, 26L, 27L, 28L, 29L, 
30L, 2L, 3L, 1L, 33L, 34L), class = "data.frame")

> mult<-c(CL=100,GC=10,HG=10,NG=1000,PL=10,RB=100,SI=10,ZL=100,HO=100,KC=1,CC=1,SB=1,ZC=1,ZW=1)
> reported$reported.Price <- reported$reported.Price * mult[reported$Product]

reported <-
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 12L, 12L, 13L, 14L, 14L), .Label = c("CL", "Cocoa", "Coffee C", 
"GC", "HG", "HO", "NG", "PL", "RB", "SI", "Sugar No 11", "ZC", 
"ZL", "ZW"), class = "factor"), reported.Price = c(10535, 23800, 
24070, 24080, 2023.5, 2028, 2029.5, 2058.5, 2060.5, 2061, 2062, 
1748000, 3788, 3792.5, 3795, 32061, 25.38, 25.43, 166900, 167850, 
30449, 32139, 32160, 32165, 32250, 32255, 32280, 32304, 3390, 
3397.5, 24.16, 24.2, 24.22, 24.23, 24.54, 25.5, 25.55, 631.75, 
638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 3L, -1L, 
-2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 11L, 
-54L, -52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 17L, 
17L, 114L, 71L, 16L, 27L, -3L, 3L, -3L, -89L, -1L, -1L, -51L, 
-51L)), .Names = c("Product", "reported.Price", "reported.Nbr.Lots"
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 8L, 9L, 10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 
38L, 39L, 40L, 41L, 42L, 31L, 32L, 24L, 25L, 26L, 27L, 28L, 29L, 
30L, 2L, 3L, 1L, 33L, 34L), class = "data.frame")

Have a good weekend.

Arnaud Gaboury
 
A2CT2 Ltd.
Trade: +41 22 849 88 63
Fax:   +41 22 849 88 66
arnaud.gabo...@a2ct2.com 

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
Access to this email by anyone else is unauthorized. If you are not the 
intended recipient, any disclosure, copying, distribution or any action taken 
or omitted to be taken in reliance on it, is prohibited and may be unlawful. If 
you have received this email in error please notify the sender. 


-Original Message-
From: Sarah Goslee [mailto:sarah.gos...@gmail.com] 
Sent: vendredi 24 février 2012 17:54
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition

You need, as I already suggested, to use a value of 1 for levels you don't want 
to change.

> mult <- c(AA = 10, BB = 25, CC=1, DD=15) mult[df$x]
AA BB CC AA DD DD
10 25  1 10 15 15
> df$y * mult[df$x]
AA BB CC AA DD DD
10 50  3 40 75 90


On Fri, Feb 24, 2012 at 11:36 AM, Arnaud Gaboury  
wrote:
>> df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6) mult 
>> <- c(AA = 10, BB = 25,DD=15) df$y <- df$y * mult[df$x] df
>   x  y
> 1 AA 10
> 2 BB 50
> 3 CC 45
> 4 AA 40
> 5 DD NA
> 6 DD NA
>
> My df is in fact much more longer than the chosen example shown here. It 
> seems your tip didn't do the job.
> I am expecting this as result :
>
>> df
>   x  y
> 1 AA 10  > if df$x==AA, df$y<-1*10
> 2 BB 50   > if df$x==BB, df$y<-2*25
> 3 CC 3         NOTHING
> 4 AA 40    > if df$x==AA, df$y<-4*10
> 5 DD 75   > if df$x==DD, df$y<-5*15
> 6 DD 90   > if df$x==DD, df$y<-6*15
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> -Original Message-
> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
> Sent: vendredi 24 février 2012 17:07
> To: Arnaud Gaboury
> Cc: r-help@r-project.org
> Subject: Re: [R] data frame manipulation with condition
>
>
>
> On 24.02.2012 16:59, Arnaud Gaboury wrote:
>> TY Uwe,
>>
>> So I will have to write a line for each condition? Right?
>>
>> In fact I was trying to do something with apply in one line, but couldn't 
>> achieve any result. In fact, all my transformation will be multiplying one 
>> object by a specific number according to the value of df$x.

Re: [R] Searching for a pattern within a vector

2012-02-24 Thread William Dunlap
A different approach to this problem is via convolutional filtering.
  f <- function (x, pattern, tolerance = 1e-05) 
  {
  # x is a numeric matrix (or vector or data.frame) of data, pattern is
  # a vector.  This returns the number of times the pattern is found
  # in each column of x.
  # tolerance is just to account for floating point inaccuracy.
  m <- mean(pattern)
  centeredPattern <- pattern - m
  xp <- filter(as.matrix(x) - m, rev(centeredPattern))
  colSums(abs(xp - sum(centeredPattern^2)) < tolerance, na.rm = TRUE)
  }

E.g., with your example data
  z <- data.frame(
   a = c(1, 1, 1, 0, 0, 1, 1, 1, 1, 1),
   b = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
   c = c(1, 0, 0, 1, 1, 1, 1, 1, 1, 1),
   d = c(0, 0, 0, 1, 1, 1, 0, 0, 0, 0),
   e = c(0, 0, 0, 1, 1, 1, 1, 1, 0, 0))
  pattern <- c(0, 0, 1, 1, 1, 1)
we get
  > f(z, pattern)
  [1] 1 0 1 0 1
  > f(z, pattern) > 0 # what you asked for
  [1]  TRUE FALSE  TRUE FALSE  TRUE

(I've been showing kids on our local FIRST robotics team how
signal/image processing can be done and your example
reminded me of that.)

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: Friday, February 24, 2012 12:25 AM
> To: Apoorva Gupta
> Cc: r-help@r-project.org
> Subject: Re: [R] Searching for a pattern within a vector
> 
> 
> On 24-02-2012, at 08:30, Apoorva Gupta wrote:
> 
> > Dear R users,
> >
> > I have a data.frame as follows
> >
> > a b c d e
> > [1,] 1 1 1 0 0
> > [2,] 1 1 0 0 0
> > [3,] 1 1 0 0 0
> > [4,] 0 1 1 1 1
> > [5,] 0 1 1 1 1
> > [6,] 1 1 1 1 1
> > [7,] 1 1 1 0 1
> > [8,] 1 1 1 0 1
> > [9,] 1 1 1 0 0
> > [10,] 1 1 1 0 0
> >
> > Within these 4 vectors, I want to choose those vectors for which I
> > have the pattern (0,0,1,1,1,1) occuring anywhere in the vector.
> > This means I want vectors a,c,e and not b and d.
> >
> 
> See this thread "[R] matching a sequence in a vector?" :
> 
> http://tolstoy.newcastle.edu.au/R/e17/help/12/02/4201.html
> 
> Berend
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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 winbugs glm

2012-02-24 Thread ilai
My apologies to R-list members, this discussion diverged and is no
longer R related. Probably more fitting in one of the BUGS forums, but
I keep cc ing for any future interested reader that stumbled upon this
post in r-help.

Now to the point. Thank you so much for the reference, I was not aware
of this book. I will check it out as it seems can be useful for me
too.
However, compare McArthy's model to your own:
He is using Refuge[i] i=1,2,3 BUT ONLY AS A PLACE HOLDER for b[1:3] !!!
"... b[Refuge[i]]*Density[i]  " where density is numeric - this is as
you said ANCOVA - fitting different slopes to Density BY levels of
Refuge. Not the same thing as your
"...  b[Depth[i]] * Depth[i] "
Which is senseless as already discussed.
Side note, he can enter an explicit intercept "a" because it is the
estimate for the Med level, in the data he has dummy vars only for
Small and Large (e.g. in the first two columns of his design matrix,
lines 6 and 7 are 0 0 ). Thus, HIS model is identifiable.

Brad Efron (1986) said "Bayesian theory requires a great deal of
thought about the given situation to apply sensibly". And maybe this
is a good time to revisit another statement I think attributed to him:
"Recommending that scientists use Bayes’ theorem is like giving the
neighborhood kids the key to your F-16. "

Present company excluded :) as you seem to be more careful in your
application than some.

Cheers,
Elai



On Fri, Feb 24, 2012 at 8:46 AM, Adan Jordan-Garza
 wrote:
> Ohh! about the reference code for the categorical predictor,
> from the McCarthy book, Bayesian Methods for Ecology (ISBN978-0-521-85057-5)
> the following ANCOVA model has a Refuge as a categorical predictor with 3
> levels coded as "1", "2" and "3".
>
> This is the cited model:
>
> model
> {
> a ~ dnorm(1.01, 24.826)
>
> # intercept
> b[1] ~ dnorm(0.628, 56.70) # effect of density at resource level 1 (low)
> b[2] ~ dnorm(0.488, 110.83) # effect of density at resource level 2 (medium)
> b[3] ~ dnorm(0.180, 70.144) # effect of density at resource level 3 (high)
> intnS[1] ~ dnorm(0, 1.0E-6) # interaction terms for small plots at 3 refuge
> densities
> intnS[2] ~ dnorm(0, 1.0E-6)
> intnS[3] ~ dnorm(0, 1.0E-6)
> intnL[1] ~ dnorm(0, 1.0E-6) # interaction terms for large plots at 3 refuge
> densities
> intnL[2] ~ dnorm(0, 1.0E-6)
> intnL[3] ~ dnorm(0, 1.0E-6)
> prec ~ dgamma(0.001, 0.001) # precision
> for (i in 1:25) # for each of the 25 plots
> {
> pred[i] <- a + b[Refuge[i]]*Density[i] +
> intnS[Refuge[i]]*Small[i]*Density[i] + intnL[Refuge[i]]*Large[i]*Density[i]
> Mortality[i] ~ dnorm(pred[i], prec)
> }
> }
> Initial values
> list(a=0, b=c(0,0,0), intnS=c(0,0,0), intnL=c(0,0,0), prec=1)
> Data
> Small[] Large[] Density[] Refuge[] Mortality[]
>
> 0 1 0.3125 1 1.6
>
> 1 0 0.75 1 0
>
> 0 1 0.75 1 2.22
>
> 1 0 1 1 1.19
>
> 1 0 1.25 1 5.19
>
> 0 0 1.5 1 1.73
>
> 0 0 1.9375 1 5.15
>
> 1 0 1 2 0.83
>
> 0 1 1.1875 2 1.44
>
> 0 0 1.375 2 1.5
>
> 0 0 1.4375 2 1.73
>
> 1 0 1.75 2 0
>
> 1 0 1.75 2 2.5
>
> 1 0 3.5 2 2.82
>
> 0 0 4 2 1.81
>
> 1 0 1.75 3 1.5
>
> 0 1 1.84375 3 1.33
>
> 1 0 2 3 1.66
>
> 1 0 2.25 3 0.73
>
> 0 0 2.5 3 1.6
>
> 0 1 3 3 1.99
>
> 1 0 3.25 3 1.09
>
> 1 0 4.25 3 1.54
>
> 1 0 5 3 1.6
>
> 1 0 5.5 3 1.73
>
> END
>
>
>
>
>
>
> On Fri, Feb 24, 2012 at 9:28 AM, Adan Jordan-Garza
>  wrote:
>>
>> Ok this makes a lot of sense, thank you very much Ilai!
>> Cheers
>> Guillermo
>>
>> On Fri, Feb 24, 2012 at 12:16 AM, ilai  wrote:
>>>
>>> On Thu, Feb 23, 2012 at 8:32 PM, Adan Jordan-Garza
>>>  wrote:
>>> > Hello Ilai,
>>> > thank you very much for your response,
>>> > can I bother you a little further?
>>> > What do you mean my model is not identifiable?
>>>
>>> You should read up on model identifiably or consult your local
>>> statistician for a complete explanation, especially if you are to be
>>> doing more analysis. An incomplete explanation just regarding your
>>> bugs code: you are estimating "a" (an overall mean) and the three
>>> levels b[1:3]. That's too much, you need to remove "a". Think what you
>>> are asking of bugs to estimate (I'll make up some numbers): for bugs,
>>> the solution
>>> a = 10
>>> b[1] = 0
>>> b[2] = -2
>>> b[3] = -5
>>> is no different than
>>> a = 8
>>> b[1] = 2
>>> b[2] = 0
>>> b[3] = -3
>>> or
>>> a = 5
>>> b[1] = 5
>>> b[2] = 3
>>> b[3] = 0
>>>
>>> This is why you're getting large intervals - even with convergence
>>> etc. the MCMC is simply skipping between these options with no way to
>>> "identify" which is it since it knows the means for depths 1:3, but
>>> nothing about "a". a could be 100 and all others -99,-95 etc.
>>> Makes sense?
>>>
>>> It is, for e.g., the reason why summary(glm(y~Depth)) gave you
>>> intercept (in R the first level) and estimates for the DIFFERENCES of
>>> all other factor levels from the first. It was not just to make it
>>> harder on you, it's because the same idea holds for the frequentist
>>> approach.
>>>
>>> It runs ok (1
>>> > iteractions) no autocorrelation, and it does converge but t

Re: [R] Aggregate with Function List ?

2012-02-24 Thread Eik Vettorazzi
Hi Michael,
something like the following might be a starting point for aggregating
data using arbitrary lists of functions:

(it is lacking a method for data.frame objects)

maggregate<-function(...)UseMethod("maggregate")
maggregate.default<-function(x, FUN, ...){
 tmp<-lapply(FUN,function(fct)aggregate(x,FUN=fct,...))
 names(tmp)<-sapply(substitute(FUN), deparse)[-1]
 r2<-data.frame(tmp[[1]][,1],sapply(tmp,"[",-1))
 names(r2)[1]<-names(tmp[[1]])[1]
 r2
}
maggregate.formula<-function(formula, data, FUN, ..., subset, na.action
= na.omit){

tmp<-lapply(FUN,function(fct)aggregate(formula,data,fct,...,na.action =
na.action))
 names(tmp)<-sapply(substitute(FUN), deparse)[-1]
 r2<-data.frame(tmp[[1]][,1],sapply(tmp,"[",-1))
 names(r2)[1]<-names(tmp[[1]])[1]
 r2
 }
#using formula method
maggregate(Sepal.Length~Species,data=iris,FUN=c(mean,median,sd))
maggregate(Sepal.Length~Species,data=iris,FUN=list(mean,quantile))

#check if parameters are passed to quantile
maggregate(Sepal.Length~Species,iris,FUN=list(mean,quantile),probs=c(.25,.5,.75))


maggregate(iris$Sepal.Length,by=list(iris$Species),FUN=list(mean,quantile))


Cheers

Am 23.02.2012 19:41, schrieb Michael Karol:
> R Experts
> 
>  
> 
>   I wish to tabulate into one data frame statistics summarizing
> concentration data.   The summary is to include mean, standard
> deviation, median, min and max.  I wish to have summaries by Dose, Day
> and Time.   I can do this by calling aggregate once for each of the
> statistics (mean, standard deviation, median, min and max) and then
> execute 4 merges to merging the 5 data frames into one.  (Example
> aggregate code for mean only is shown below.)  
> 
>   Can someone show me the coding to do this as one command, rather than
> 5 calls to aggregate and 4 merges.  In other words, in essence, I'd like
> to present to "FUN =" a list of functions, so all the summary stats come
> back in one data frame.  Your assistance is appreciated.  Thank you.
> 
>  
> 
> MeansByDoseDayTime <- aggregate(as.double(DF$Concentration), by =
> list(DF$Dose, DF$Day, DF$Time), FUN = mean, trim = 0, na.rm = T,
> weights=NULL)
> 
>  
> 
>  
> 
> Regards, 
> 
> Michael
> 
> 
>   [[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.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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

2012-02-24 Thread Arnaud Gaboury
OK Uwe, I understand, and I will be more explicit.

Here is how could my df be:

reported <-
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 12L, 12L, 13L, 14L, 14L), .Label = c("CL", "Cocoa", "Coffee C", 
"GC", "HG", "HO", "NG", "PL", "RB", "SI", "Sugar No 11", "ZC", 
"ZL", "ZW"), class = "factor"), reported.Price = c(105.35, 2380, 
2407, 2408, 202.35, 202.8, 202.95, 205.85, 206.05, 206.1, 206.2, 
1748, 378.8, 379.25, 379.5, 320.61, 2.538, 2.543, 1669, 1678.5, 
304.49, 321.39, 321.6, 321.65, 322.5, 322.55, 322.8, 323.04, 
3390, 3397.5, 24.16, 24.2, 24.22, 24.23, 24.54, 25.5, 25.55, 
631.75, 638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 3L, 
-1L, -2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 
11L, -54L, -52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 
17L, 17L, 114L, 71L, 16L, 27L, -3L, 3L, -3L, -89L, -1L, -1L, 
-51L, -51L)), .Names = c("Product", "reported.Price", "reported.Nbr.Lots"
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 8L, 9L, 10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 
38L, 39L, 40L, 41L, 42L, 31L, 32L, 24L, 25L, 26L, 27L, 28L, 29L, 
30L, 2L, 3L, 1L, 33L, 34L), class = "data.frame")


Row will change. I am looking to multiply reported.Price by 100 IF Product=CL, 
multiply by 10 IF product=GC, multiply by 100 IF product=HG, multiply by 1000 
IF Product=NG, multiply by 100 IF product=RB.

I hope I am clear enough, and YES I have tried many workarounds myself before 
posting. Feel free to ignore my post if you think I am lazy and disrespectful 
to the list.


Arnaud Gaboury
 
A2CT2 Ltd.



-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: vendredi 24 février 2012 17:41
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition



On 24.02.2012 17:36, Arnaud Gaboury wrote:
>> df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
>> mult<- c(AA = 10, BB = 25,DD=15)
>> df$y<- df$y * mult[df$x]
>> df
> x  y
> 1 AA 10
> 2 BB 50
> 3 CC 45
> 4 AA 40
> 5 DD NA
> 6 DD NA
>
> My df is in fact much more longer than the chosen example shown here. It 
> seems your tip didn't do the job.
> I am expecting this as result :


This is not the I do the job for you hotline. You are free to think a little 
bit yourself given you have not managed in two attempts to describe your 
problem sufficiently well!

Uwe Ligges



>> df
> x  y
> 1 AA 10  >  if df$x==AA, df$y<-1*10
> 2 BB 50   >  if df$x==BB, df$y<-2*25
> 3 CC 3 NOTHING
> 4 AA 40>  if df$x==AA, df$y<-4*10
> 5 DD 75   >  if df$x==DD, df$y<-5*15
> 6 DD 90   >  if df$x==DD, df$y<-6*15
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> -Original Message-
> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
> Sent: vendredi 24 février 2012 17:07
> To: Arnaud Gaboury
> Cc: r-help@r-project.org
> Subject: Re: [R] data frame manipulation with condition
>
>
>
> On 24.02.2012 16:59, Arnaud Gaboury wrote:
>> TY Uwe,
>>
>> So I will have to write a line for each condition? Right?
>>
>> In fact I was trying to do something with apply in one line, but couldn't 
>> achieve any result. In fact, all my transformation will be multiplying one 
>> object by a specific number according to the value of df$x.
>
> In that case:
>
> mult<- c(AA = 10, BB = 25)
>
> Then:
>
>
> df$y<- df$y * mult[df$x]
>
>
> Uwe Ligges
>
>
>>
>> Arnaud Gaboury
>>
>> A2CT2 Ltd.
>>
>>
>> -Original Message-
>> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
>> Sent: vendredi 24 février 2012 16:33
>> To: Arnaud Gaboury
>> Cc: r-help@r-project.org
>> Subject: Re: [R] data frame manipulation with condition
>>
>>
>>
>> On 24.02.2012 16:25, Arnaud Gaboury wrote:
>>> Dear list,
>>>
>>> n00b question, but still can't find any easy answer.
>>>
>>> Here is a df:
>>
>>
>> Change
>>
 df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
>>
>> to
>>
>> df<- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)
>>
>> to make your object a sensible data.frame.
>>
>>
>>
 df
>>>   x y
>>> 1 AA 1
>>> 2 BB 2
>>> 3 CC 3
>>> 4 AA 4
>>>
>>>
>>> I want to modify this df this way :
>>> if df$x=="AA" then df$y=df$y*10
>>
>> df$y[df$x=="AA"]<- df$y[df$x=="AA"] * 25
>>
>> ...
>>
>>
>> Uwe Ligges
>>
>>
>>> if df$x=="BB" then df$y=df$y*25
>>
>>
>>
>>
>>> and so on with other conditions.
>>>
>>> TY for any help.
>>>
>>> Trading
>>>
>>> A2CT2 Ltd.
>>>
>>>
>>> Arnaud Gaboury
>>>
>>> A2CT2 Ltd.
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/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
http

[R] help with apply function for 3D array

2012-02-24 Thread C Lin




Dear R users, I am trying to use apply function on a 3D array (get rid of any 
loop) but wasn't successfull. Below is a toy example of what I am trying to do: 
refID_remNoCat = 1:30;
s_remNoCat = sample(1:length(refID_remNoCat),size=length(refID_remNoCat));
s.sort_remNoCat = sort(s_remNoCat,index.return=TRUE);
p_ref_remNoCat = c(5,10);
nperm = 2;
nCat = 2;
N = length(refID_remNoCat);
p=1;
max_es_rand = matrix(rep(0,nCat*nperm),ncol=nperm,nrow=nCat);
Nh = rep(0,nCat);
NR = matrix(rep(0,nCat*nperm),ncol=nperm,nrow=nCat);
es_rand = array(rep(0,nCat*N*nperm),c(nCat,nperm,N));
p_ref_ix_remNoCat_rand = 
array(rep(0,nCat*max(p_ref_remNoCat)*nperm),c(nCat,nperm,max(p_ref_remNoCat)));
Phit = array(rep(0,nCat*N*nperm),c(nCat,nperm,N));
Pmiss = array(rep(0,nCat*N*nperm),c(nCat,nperm,N));
set.seed(1);
for (z in 1:nCat){
  for (j in 1:nperm){
Nh[z] = N-p_ref_remNoCat[z];
p_ref_ix_remNoCat_rand[z,j,1:p_ref_remNoCat[z]] = 
sample(1:length(refID_remNoCat),size=p_ref_remNoCat[z],replace=FALSE);
NR[z,j] = sum(abs(s_remNoCat[p_ref_ix_remNoCat_rand[z,j,]])^p);
for (i in 1:length(refID_remNoCat)){
  Phit[z,j,i] = 
sum(abs(s.sort_remNoCat$x[which(s.sort_remNoCat$ix[1:i]%in%p_ref_ix_remNoCat_rand[z,j,])])/NR[z,j]);
  Pmiss[z,j,i] = 
(1/(N-Nh[z]))*length(which(!s.sort_remNoCat$ix[1:i]%in%p_ref_ix_remNoCat_rand[z,j,]));
  es_rand[z,j,i]=Phit[z,j,i]-Pmiss[z,j,i];
  }
  max_es_rand[z,j]=max(es_rand[z,j,]);
  }
} The main problem is the second to last line, calculation of Phit, where I am 
summing the s.sort_remNoCat$x that are in p_ref_ix_remNoCat_rand so far, 
divided by NR. Thank you all for your help and sorry for the long variable 
names. Lin 
[[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] data frame manipulation with condition

2012-02-24 Thread Sarah Goslee
You need, as I already suggested, to use a value of 1 for levels you don't want
to change.

> mult <- c(AA = 10, BB = 25, CC=1, DD=15)
> mult[df$x]
AA BB CC AA DD DD
10 25  1 10 15 15
> df$y * mult[df$x]
AA BB CC AA DD DD
10 50  3 40 75 90


On Fri, Feb 24, 2012 at 11:36 AM, Arnaud Gaboury
 wrote:
>> df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
>> mult <- c(AA = 10, BB = 25,DD=15)
>> df$y <- df$y * mult[df$x]
>> df
>   x  y
> 1 AA 10
> 2 BB 50
> 3 CC 45
> 4 AA 40
> 5 DD NA
> 6 DD NA
>
> My df is in fact much more longer than the chosen example shown here. It 
> seems your tip didn't do the job.
> I am expecting this as result :
>
>> df
>   x  y
> 1 AA 10  > if df$x==AA, df$y<-1*10
> 2 BB 50   > if df$x==BB, df$y<-2*25
> 3 CC 3         NOTHING
> 4 AA 40    > if df$x==AA, df$y<-4*10
> 5 DD 75   > if df$x==DD, df$y<-5*15
> 6 DD 90   > if df$x==DD, df$y<-6*15
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> -Original Message-
> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
> Sent: vendredi 24 février 2012 17:07
> To: Arnaud Gaboury
> Cc: r-help@r-project.org
> Subject: Re: [R] data frame manipulation with condition
>
>
>
> On 24.02.2012 16:59, Arnaud Gaboury wrote:
>> TY Uwe,
>>
>> So I will have to write a line for each condition? Right?
>>
>> In fact I was trying to do something with apply in one line, but couldn't 
>> achieve any result. In fact, all my transformation will be multiplying one 
>> object by a specific number according to the value of df$x.
>
> In that case:
>
> mult <- c(AA = 10, BB = 25)
>
> Then:
>
>
> df$y <- df$y * mult[df$x]
>
>
> Uwe Ligges
>
>
>>
>> Arnaud Gaboury
>>
>> A2CT2 Ltd.
>>
>>
>> -Original Message-
>> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
>> Sent: vendredi 24 février 2012 16:33
>> To: Arnaud Gaboury
>> Cc: r-help@r-project.org
>> Subject: Re: [R] data frame manipulation with condition
>>
>>
>>
>> On 24.02.2012 16:25, Arnaud Gaboury wrote:
>>> Dear list,
>>>
>>> n00b question, but still can't find any easy answer.
>>>
>>> Here is a df:
>>
>>
>> Change
>>
 df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
>>
>> to
>>
>>    df<- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)
>>
>> to make your object a sensible data.frame.
>>
>>
>>
 df
>>>      x y
>>> 1 AA 1
>>> 2 BB 2
>>> 3 CC 3
>>> 4 AA 4
>>>
>>>
>>> I want to modify this df this way :
>>>    if df$x=="AA" then df$y=df$y*10
>>
>> df$y[df$x=="AA"]<- df$y[df$x=="AA"] * 25
>>
>> ...
>>
>>
>> Uwe Ligges
>>
>>
>>>    if df$x=="BB" then df$y=df$y*25
>>
>>
-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] data frame manipulation with condition

2012-02-24 Thread Uwe Ligges



On 24.02.2012 17:36, Arnaud Gaboury wrote:

df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
mult<- c(AA = 10, BB = 25,DD=15)
df$y<- df$y * mult[df$x]
df

x  y
1 AA 10
2 BB 50
3 CC 45
4 AA 40
5 DD NA
6 DD NA

My df is in fact much more longer than the chosen example shown here. It seems 
your tip didn't do the job.
I am expecting this as result :



This is not the I do the job for you hotline. You are free to think a 
little bit yourself given you have not managed in two attempts to 
describe your problem sufficiently well!


Uwe Ligges




df

x  y
1 AA 10  >  if df$x==AA, df$y<-1*10
2 BB 50   >  if df$x==BB, df$y<-2*25
3 CC 3 NOTHING
4 AA 40>  if df$x==AA, df$y<-4*10
5 DD 75   >  if df$x==DD, df$y<-5*15
6 DD 90   >  if df$x==DD, df$y<-6*15

Arnaud Gaboury

A2CT2 Ltd.

-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Sent: vendredi 24 février 2012 17:07
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition



On 24.02.2012 16:59, Arnaud Gaboury wrote:

TY Uwe,

So I will have to write a line for each condition? Right?

In fact I was trying to do something with apply in one line, but couldn't 
achieve any result. In fact, all my transformation will be multiplying one 
object by a specific number according to the value of df$x.


In that case:

mult<- c(AA = 10, BB = 25)

Then:


df$y<- df$y * mult[df$x]


Uwe Ligges




Arnaud Gaboury

A2CT2 Ltd.


-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Sent: vendredi 24 février 2012 16:33
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition



On 24.02.2012 16:25, Arnaud Gaboury wrote:

Dear list,

n00b question, but still can't find any easy answer.

Here is a df:



Change


df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))


to

df<- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)

to make your object a sensible data.frame.




df

  x y
1 AA 1
2 BB 2
3 CC 3
4 AA 4


I want to modify this df this way :
if df$x=="AA" then df$y=df$y*10


df$y[df$x=="AA"]<- df$y[df$x=="AA"] * 25

...


Uwe Ligges



if df$x=="BB" then df$y=df$y*25






and so on with other conditions.

TY for any help.

Trading

A2CT2 Ltd.


Arnaud Gaboury

A2CT2 Ltd.

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

2012-02-24 Thread Arnaud Gaboury
> df<- data.frame(x = c("AA","BB","CC","AA","DD","DD"), y = 1:6)
> mult <- c(AA = 10, BB = 25,DD=15)
> df$y <- df$y * mult[df$x]
> df
   x  y
1 AA 10
2 BB 50
3 CC 45
4 AA 40
5 DD NA
6 DD NA

My df is in fact much more longer than the chosen example shown here. It seems 
your tip didn't do the job.
I am expecting this as result :

> df
   x  y
1 AA 10  > if df$x==AA, df$y<-1*10 
2 BB 50   > if df$x==BB, df$y<-2*25 
3 CC 3 NOTHING
4 AA 40> if df$x==AA, df$y<-4*10 
5 DD 75   > if df$x==DD, df$y<-5*15
6 DD 90   > if df$x==DD, df$y<-6*15

Arnaud Gaboury
 
A2CT2 Ltd.

-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: vendredi 24 février 2012 17:07
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition



On 24.02.2012 16:59, Arnaud Gaboury wrote:
> TY Uwe,
>
> So I will have to write a line for each condition? Right?
>
> In fact I was trying to do something with apply in one line, but couldn't 
> achieve any result. In fact, all my transformation will be multiplying one 
> object by a specific number according to the value of df$x.

In that case:

mult <- c(AA = 10, BB = 25)

Then:


df$y <- df$y * mult[df$x]


Uwe Ligges


>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
>
> -Original Message-
> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
> Sent: vendredi 24 février 2012 16:33
> To: Arnaud Gaboury
> Cc: r-help@r-project.org
> Subject: Re: [R] data frame manipulation with condition
>
>
>
> On 24.02.2012 16:25, Arnaud Gaboury wrote:
>> Dear list,
>>
>> n00b question, but still can't find any easy answer.
>>
>> Here is a df:
>
>
> Change
>
>>> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
>
> to
>
>df<- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)
>
> to make your object a sensible data.frame.
>
>
>
>>> df
>>  x y
>> 1 AA 1
>> 2 BB 2
>> 3 CC 3
>> 4 AA 4
>>
>>
>> I want to modify this df this way :
>>if df$x=="AA" then df$y=df$y*10
>
> df$y[df$x=="AA"]<- df$y[df$x=="AA"] * 25
>
> ...
>
>
> Uwe Ligges
>
>
>>if df$x=="BB" then df$y=df$y*25
>
>
>
>
>> and so on with other conditions.
>>
>> TY for any help.
>>
>> Trading
>>
>> A2CT2 Ltd.
>>
>>
>> Arnaud Gaboury
>>
>> A2CT2 Ltd.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] data frame manipulation with condition

2012-02-24 Thread Sarah Goslee
I sent it to you and the list, as is standard practice.

You must know in advance what level of your factor goes with what multiplicand.
Use that information to set up the association. The order within your data frame
is irrelevant, only the order R uses for factor levels is of importance.

Sarah

On Fri, Feb 24, 2012 at 11:16 AM, Arnaud Gaboury
 wrote:
> No sorry! Your email was in fact NOT in the lsit, and was not watching my 
> regular box, but only the list one.
>
> TY for your tip. But in fact my df is much more complex, and objects, numbers 
> of it and their order will change
>
> Have a good weekend
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
> Trade: +41 22 849 88 63
> Fax:   +41 22 849 88 66
> arnaud.gabo...@a2ct2.com
>
> -Original Message-
> From: Sarah Goslee [mailto:sarah.gos...@gmail.com]
> Sent: vendredi 24 février 2012 17:12
> To: Arnaud Gaboury
> Subject: Re: [R] data frame manipulation with condition
>
> Did you not see my solution?
>
> On Fri, Feb 24, 2012 at 10:59 AM, Arnaud Gaboury  
> wrote:
>> TY Uwe,
>>
>> So I will have to write a line for each condition? Right?
>>
>> In fact I was trying to do something with apply in one line, but couldn't 
>> achieve any result. In fact, all my transformation will be multiplying one 
>> object by a specific number according to the value of df$x.
>>
>> Arnaud Gaboury
>>
>> A2CT2 Ltd.
>>
>>
>> -Original Message-
>> From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
>> Sent: vendredi 24 février 2012 16:33
>> To: Arnaud Gaboury
>> Cc: r-help@r-project.org
>> Subject: Re: [R] data frame manipulation with condition
>>
>>
>>
>> On 24.02.2012 16:25, Arnaud Gaboury wrote:
>>> Dear list,
>>>
>>> n00b question, but still can't find any easy answer.
>>>
>>> Here is a df:
>>
>>
>> Change
>>
 df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
>>
>> to
>>
>>  df <- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)
>>
>> to make your object a sensible data.frame.
>>
>>
>>
 df
>>>     x y
>>> 1 AA 1
>>> 2 BB 2
>>> 3 CC 3
>>> 4 AA 4
>>>
>>>
>>> I want to modify this df this way :
>>>   if df$x=="AA" then df$y=df$y*10
>>
>> df$y[df$x=="AA"] <- df$y[df$x=="AA"] * 25
>>
>> ...
>>
>>
>> Uwe Ligges
>>
>>
>>>   if df$x=="BB" then df$y=df$y*25
>>
>>
>>
>>
>>> and so on with other conditions.
>>>
>>> TY for any help.
>>>
>>> Trading
>>>
>>> A2CT2 Ltd.
>>>
>>>
>>> Arnaud Gaboury
>>>
>>> A2CT2 Ltd.
>>>


-- 
Sarah Goslee
http://www.functionaldiversity.org

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


[R] Rugarch-Package - df of std

2012-02-24 Thread barb
Hey Guys,

i want the degrees of freedom of the student-t distribution to be given out. 
Since, i only get the shape parameter, i wanted to ask for help. 

On one side i found the same parameter being used for the shape parameter
and df. But df of a std. aren´t allowed to equal decimal numbers!?

Thanks for your help


--
View this message in context: 
http://r.789695.n4.nabble.com/Rugarch-Package-df-of-std-tp4417607p4417607.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] R CMD INSTALL fails where R CMD check succeeds.

2012-02-24 Thread Rob Steele
This is in a 64 bit CentOS 5.6 instance at Amazon AWS with R version 
2.14.1 (2011-12-22).  It happens on several packages: RMySQL, RODBC, 
FastICA.  Many other packages install just fine.


Here's an example error message:

* installing *source* package 'RODBC' ...
** package 'RODBC' successfully unpacked and MD5 sums checked
sh: ./configure: /bin/sh: bad interpreter: Permission denied
ERROR: configuration failed for package 'RODBC'
* removing '/usr/share/R/library/RODBC'
* restoring previous '/usr/share/R/library/RODBC'

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

2012-02-24 Thread A2CT2 Trading
Dear list,

n00b question, but still can't find any easy answer.

Here is a df:

> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
> df
   x y
1 AA 1
2 BB 2
3 CC 3
4 AA 4


I want to modify this df this way :
 if df$x=="AA" then df$y=df$y*10
 if df$x=="BB" then df$y=df$y*25

and so on with other conditions.

TY for any help.

Trading
 
A2CT2 Ltd.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Advice on exploration of sub-clusters in hierarchical dendrogram

2012-02-24 Thread kosmo7
Ok, I was able to work it out finally.
As I have been aided myself numerous times from posted questions by other
users who have reached in the end a solution to their problem, I will put
the code that worked for me for future googlers - it is certainly not
optimal but it works:

# Initial clustering
df=read.table('mydata.txt', head=T, row.names=1) #read file with distance
matrix
d=as.dist(df) #format table as distance matrix
z<-hclust(d,method="complete", members=NULL)
x<-as.dendrogram(z)
plot(x, xlab="mydata complete-LINKAGE", ylim=c(0,4)) #visualization of the
dendrogram
clusters<-cutree(z, h=1.6) #obtain clusters at cutoff height=1.6
ord<-cmdscale(d, k=2) #Multidimensional scaling of the data down to 2
dimensions
clusplot(ord,clusters, color=TRUE, shade=TRUE,labels=4, lines=0)
#visualization of the clusters in 2D map 

# Local sub-clustering (actually re-clustering on a specific tree
node/cluster)

h<-as.matrix(d)  # transform the distance matrix to a simple matrix. We
should ideally  work with the initial data table but  it sometimes contains
an "X" letter preceding labels and there is a risk labels aren't recognized
by comparison to name vectors. Distance matrices don't contain the preceding
"X" so I transformed it back to a simple matrix  (this step might not be
required, depending on your initial data table format).

clid<-c(1)  # Just a column containing the number of the clusters of the
initial clustering that you want to pick - separate with commas if more than
one clusters,. Here we only want cluster 1.
ysub<-h[names(clusters[clusters%in%clid]),]  #Remove all rows from the h
table that do not begin by the label of a member of cluster 1
ysub<-t(ysub)[names(clusters[clusters%in%clid]),]  #We want a rectangular
table to be used as distance matrix later on, so we transpose the previous
table ysub and remove again the unneeded rows.
hrsub<-hclust(as.dist(ysub),method="average") #Perform your preferred
hierarchical method on just the initial clusters selected with clid 
plot(hrsub)
ord2<-cmdscale(ysub, k=2) 
plot(ord2) # Now we can visually "zoom" on the data configuration of just
the selected cluster by 2d MDS
aa<-silhouette(cutree(hrsub,h=1.2),as.dist(ysub)) #We can perform silhouette
analysis localy on the selected cluster (by clid)
plot(aa)
clusplot(ord2,cutree(hrsub,h=1.2), color=TRUE, shade=TRUE,labels=4, lines=0)
# clusterplot of the subclusters


Thanks for reading - take care all.

PS. If anyone can write all these things in a more efficient way, please
feel free to add a comment.


--
View this message in context: 
http://r.789695.n4.nabble.com/Advice-on-exploration-of-sub-clusters-in-hierarchical-dendrogram-tp4414277p4417419.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] data frame manipulation with condition

2012-02-24 Thread Uwe Ligges



On 24.02.2012 16:59, Arnaud Gaboury wrote:

TY Uwe,

So I will have to write a line for each condition? Right?

In fact I was trying to do something with apply in one line, but couldn't 
achieve any result. In fact, all my transformation will be multiplying one 
object by a specific number according to the value of df$x.


In that case:

mult <- c(AA = 10, BB = 25)

Then:


df$y <- df$y * mult[df$x]


Uwe Ligges




Arnaud Gaboury

A2CT2 Ltd.


-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Sent: vendredi 24 février 2012 16:33
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition



On 24.02.2012 16:25, Arnaud Gaboury wrote:

Dear list,

n00b question, but still can't find any easy answer.

Here is a df:



Change


df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))


to

   df<- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)

to make your object a sensible data.frame.




df

 x y
1 AA 1
2 BB 2
3 CC 3
4 AA 4


I want to modify this df this way :
   if df$x=="AA" then df$y=df$y*10


df$y[df$x=="AA"]<- df$y[df$x=="AA"] * 25

...


Uwe Ligges



   if df$x=="BB" then df$y=df$y*25






and so on with other conditions.

TY for any help.

Trading

A2CT2 Ltd.


Arnaud Gaboury

A2CT2 Ltd.

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

2012-02-24 Thread Arnaud Gaboury
TY Uwe,

So I will have to write a line for each condition? Right?

In fact I was trying to do something with apply in one line, but couldn't 
achieve any result. In fact, all my transformation will be multiplying one 
object by a specific number according to the value of df$x.

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: vendredi 24 février 2012 16:33
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition



On 24.02.2012 16:25, Arnaud Gaboury wrote:
> Dear list,
>
> n00b question, but still can't find any easy answer.
>
> Here is a df:


Change

>> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))

to

  df <- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)

to make your object a sensible data.frame.



>> df
> x y
> 1 AA 1
> 2 BB 2
> 3 CC 3
> 4 AA 4
>
>
> I want to modify this df this way :
>   if df$x=="AA" then df$y=df$y*10

df$y[df$x=="AA"] <- df$y[df$x=="AA"] * 25

...


Uwe Ligges


>   if df$x=="BB" then df$y=df$y*25




> and so on with other conditions.
>
> TY for any help.
>
> Trading
>
> A2CT2 Ltd.
>
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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.fields inconsistent with read.table?

2012-02-24 Thread Sam Steingold
> * peter dalgaard  [2012-02-24 08:41:07 +0100]:
> On Feb 24, 2012, at 06:58 , Sam Steingold wrote:
>
>> batch is a vector of lines returned by readLines from a
>> NL-line-terminated file, here is the relevant section:
>> =
>> AA   BB  CC  DD  EE  FF
>> GG   H
>> 
>> HJJ  KK  LL  MM
>> =
>> as you can see, a line is corrupt; two CRLF's are inserted.
>
> Actually, I don't see... (It's pretty hard to count TAB characters by eye.)

how about this?
>> =
>> AA^IBB^ICC^IDD^I^I^IEE^IFF
>> GG^IH^M
>> ^M
>> H^IJJ^IKK^I^I^ILL^IMM
>> =

I replaced TAB with ^I and CR with ^M.
is this better?

here I use  and  instead:
>> =
>> AABBCCDDEEFF
>> GGH
>> 
>> HJJKKLLMM
>> =

so, you see, there are two data lines here: A..F - good, with 8 fields.
G..M - BAD two CRLF's inserted inside the 2nd field, turning one line
into 3 lines.
so I must drop 3 input lines from the input.

>> This is okay, I drop the bad lines, at least I hope I do:
>> 
>>  conn <- textConnection(batch)
>>  field.counts <- count.fields(conn, sep="\t", comment.char="", quote="")
>>  close(conn)
>>  good <- field.counts == 8  # this should drop all bad lines
>>  if (!all(good))
>>batch <- batch[good]
>>  conn <- textConnection(batch)
>>  ret <- read.table(conn, sep="\t", comment.char="", quote="")
>>  close(conn)
>> 
>> I get this error in read.table():
>> 
>> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  
>> : 
>>  line 7151 did not have 8 elements
>> 
>> how come?!
>
> You can do better than this in terms of providing clues for us:
> "batch" is a character vector, right? So recheck that count.fields
> returns all 8's after removal of bad lines. Also check that dimensions
> match -- is length(batch) actually the same as length(field.counts)?

 batch <- lines[807000:808000]
 conn <- textConnection(batch)
 field.counts <- count.fields(conn, sep="\t", comment.char="", quote="")
 close(conn)
 good <- field.counts == length(col.names)
 which(!good)
[1] 152 153

## WRONG: it should be 3 lines, 154 is also bad - see above

 batch[!good]
[1] "GG\tH" "" 
 length(batch)
[1] 1001
 length(good)
[1] 1000

## WRONG: batch, field.counts and good should have the same length
 
AHA! blank.lines.skip !!!
I must set it to FALSE!!!
and it does fix the problem...

> Finally, what is in line 7151?

that's the first line with a :

GGH


>> also, is there some error recovery?
>
> Well you can try().

it appears that try gives me access to the error message, not the
erroneous data, i.e., I still have to reload the file to get the batch
string vector.


-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://www.memritv.org http://americancensorship.org
http://memri.org http://jihadwatch.org http://dhimmi.com http://iris.org.il
Democracy is like a car: you can ride it or you can run people over with 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] help with winbugs glm

2012-02-24 Thread Adan Jordan-Garza
Ohh! about the reference code for the categorical predictor,
from the McCarthy book, Bayesian Methods for Ecology
(ISBN978-0-521-85057-5) the following ANCOVA model has a Refuge as a
categorical predictor with 3 levels coded as "1", "2" and "3".

This is the cited model:

model
{
a ~ dnorm(1.01, 24.826) # intercept
b[1] ~ dnorm(0.628, 56.70) # effect of density at resource level 1 (low)
b[2] ~ dnorm(0.488, 110.83) # effect of density at resource level 2 (medium)
b[3] ~ dnorm(0.180, 70.144) # effect of density at resource level 3 (high)
intnS[1] ~ dnorm(0, 1.0E-6) # interaction terms for small plots at 3 refuge
densities
intnS[2] ~ dnorm(0, 1.0E-6)
intnS[3] ~ dnorm(0, 1.0E-6)
intnL[1] ~ dnorm(0, 1.0E-6) # interaction terms for large plots at 3 refuge
densities
intnL[2] ~ dnorm(0, 1.0E-6)
intnL[3] ~ dnorm(0, 1.0E-6)
prec ~ dgamma(0.001, 0.001) # precision
for (i in 1:25) # for each of the 25 plots
{
pred[i] <- a + b[Refuge[i]]*Density[i] +
intnS[Refuge[i]]*Small[i]*Density[i] + intnL[Refuge[i]]*Large[i]*Density[i]
Mortality[i] ~ dnorm(pred[i], prec)
}
}
Initial values
list(a=0, b=c(0,0,0), intnS=c(0,0,0), intnL=c(0,0,0), prec=1)
Data
Small[] Large[] Density[] Refuge[] Mortality[]

0 1 0.3125 1 1.6

1 0 0.75 1 0

0 1 0.75 1 2.22

1 0 1 1 1.19

1 0 1.25 1 5.19

0 0 1.5 1 1.73

0 0 1.9375 1 5.15

1 0 1 2 0.83

0 1 1.1875 2 1.44

0 0 1.375 2 1.5

0 0 1.4375 2 1.73

1 0 1.75 2 0

1 0 1.75 2 2.5

1 0 3.5 2 2.82

0 0 4 2 1.81

1 0 1.75 3 1.5

0 1 1.84375 3 1.33

1 0 2 3 1.66

1 0 2.25 3 0.73

0 0 2.5 3 1.6

0 1 3 3 1.99

1 0 3.25 3 1.09

1 0 4.25 3 1.54

1 0 5 3 1.6

1 0 5.5 3 1.73

END





On Fri, Feb 24, 2012 at 9:28 AM, Adan Jordan-Garza <
ajordangarza2...@my.fit.edu> wrote:

> Ok this makes a lot of sense, thank you very much Ilai!
> Cheers
> Guillermo
>
>   On Fri, Feb 24, 2012 at 12:16 AM, ilai  wrote:
>
>> On Thu, Feb 23, 2012 at 8:32 PM, Adan Jordan-Garza
>>  wrote:
>> > Hello Ilai,
>> > thank you very much for your response,
>> > can I bother you a little further?
>> > What do you mean my model is not identifiable?
>>
>> You should read up on model identifiably or consult your local
>> statistician for a complete explanation, especially if you are to be
>> doing more analysis. An incomplete explanation just regarding your
>> bugs code: you are estimating "a" (an overall mean) and the three
>> levels b[1:3]. That's too much, you need to remove "a". Think what you
>> are asking of bugs to estimate (I'll make up some numbers): for bugs,
>> the solution
>> a = 10
>> b[1] = 0
>> b[2] = -2
>> b[3] = -5
>> is no different than
>> a = 8
>> b[1] = 2
>> b[2] = 0
>> b[3] = -3
>> or
>> a = 5
>> b[1] = 5
>> b[2] = 3
>> b[3] = 0
>>
>> This is why you're getting large intervals - even with convergence
>> etc. the MCMC is simply skipping between these options with no way to
>> "identify" which is it since it knows the means for depths 1:3, but
>> nothing about "a". a could be 100 and all others -99,-95 etc.
>> Makes sense?
>>
>> It is, for e.g., the reason why summary(glm(y~Depth)) gave you
>> intercept (in R the first level) and estimates for the DIFFERENCES of
>> all other factor levels from the first. It was not just to make it
>> harder on you, it's because the same idea holds for the frequentist
>> approach.
>>
>> It runs ok (1
>> > iteractions) no autocorrelation, and it does converge but the credible
>> > intervals are too big. Yes Depth has 3 levels and I coded them as 1, 2,
>> and
>> > 3. In all the examples I have seen for winBugs they use this type of
>> coding
>> > for categorical predictors.
>>
>> Like I said, winBugs may have some feature where it will build the
>> design matrix internally, so you can pass categorical variables as
>> column vectors (like R) but I seriously doubt it can guess your
>> variable coded 1,2,3 is categorical. If you can reference an example
>> like that from winBugs examples (not some random code from the
>> Internet) I'd really appreciate it.
>> What I think is happening is you're fitting
>> y1 = 1b[1]  + e1
>> y2 = 3b[3]  + e2
>> ...
>> y232 = ... + e232
>>
>> But why should b[3] be 3 times b[1] ? that makes no sense for
>> categories. And the estimates are completely off (as you've noted in
>> your post) not just large variance.
>>
>>  I have read about the matrix of dummy variables
>> > but I am not sure if I am supposed to code that explicitly in winBugs
>> or how
>> > to do it. I already got the dummy matrix from R.
>>
>> There are R2winbugs and other packages to let you run winbugs from R
>> or pass the data. I don't use them so I don't know. At the end what
>> you want is Depth to be a 3 column matrix, either the same as glm to
>> get estimate of Depth1,Depth2-1,Depth3-1 :
>> 1 0 0
>> 1 0 0
>> 1 1 0
>> 1 1 0
>> 1 0 1
>> 1 0 1
>>
>> Or you could have an estimate for every depth:
>> 1 0 0
>> 1 0 0
>> 0 1 0
>> 0 1 0
>> 0 0 1
>> 0 0 1
>>
>> And your code:
>> model
>>  {
>>  for (i in 1:232)
>>  {
>>  Recruitment[i]~dpois(lambda[i])
>>  log(lambda[i])<- b[1]*Depth[,1]+b[2]*

Re: [R] To define a function which includes two functions as arguments such as "plot" and "text"

2012-02-24 Thread Uwe Ligges



On 24.02.2012 12:22, Yashwanth M.R wrote:

Here is the two functions which I have used during my practice.

*plot(Telco.rpart.METHOD.CLASS,compress=FALSE,uniform=TRUE)

text(Telco.rpart.METHOD.CLASS,use.n = TRUE, cex = .75))*

"Telco.rpart.METHOD.CLASS" is my "rpart" object of the method "class".

If I run this,

*Telco.Rpart.PLOT.TEXT<-
c(plot(Telco.rpart.METHOD.CLASS,compress=FALSE,uniform=TRUE),
 
text(Telco.rpart.METHOD.CLASS,use.n = TRUE, cex =
.75))



c() concatenates the returned values of the two functions. If you want 
to define a sequence of function calls, define them within your own 
function, calling that new function will produce your desired results, 
as far as I understand.


Uwe Ligges



http://r.789695.n4.nabble.com/file/n4416881/Rpart.gif

the output is getting generated as shown in the figure. But if I solely run
the same command "Telco.Rpart.PLOT.TEXT" right after the above, the output
is as below,

/$x
  [1]  4.035156  1.00  7.070312  3.015625  2.00  4.031250
  [7]  3.00  5.062500  4.00  6.125000  5.00  7.25
[13]  6.50  6.00  7.00  8.00 11.125000 10.25
[19]  9.50  9.00 10.00 11.00 12.00

$y
  [1] 1.125 1.000 1.000 0.875 0.750 0.750 0.625 0.625 0.500 0.500 0.375
[12] 0.375 0.250 0.125 0.125 0.250 0.875 0.750 0.625 0.500 0.500 0.625
[23] 0.750
/


Please help me in getting the output which is there is the Image..

Regards,
Yashwanth M,R

--
View this message in context: 
http://r.789695.n4.nabble.com/To-define-a-function-which-includes-two-functions-as-arguments-such-as-plot-and-text-tp4416881p4416881.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] data frame manipulation with condition

2012-02-24 Thread Uwe Ligges



On 24.02.2012 16:25, Arnaud Gaboury wrote:

Dear list,

n00b question, but still can't find any easy answer.

Here is a df:



Change


df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))


to

 df <- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)

to make your object a sensible data.frame.




df

x y
1 AA 1
2 BB 2
3 CC 3
4 AA 4


I want to modify this df this way :
  if df$x=="AA" then df$y=df$y*10


df$y[df$x=="AA"] <- df$y[df$x=="AA"] * 25

...


Uwe Ligges



  if df$x=="BB" then df$y=df$y*25






and so on with other conditions.

TY for any help.

Trading

A2CT2 Ltd.


Arnaud Gaboury

A2CT2 Ltd.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] segfault when using data.table package in conjunction with foreach

2012-02-24 Thread Uwe Ligges

0. Read the posting guide! It tells you to

1. Do not cross post!

2. Do try a recent version of R and all packages you have in use.

3. If it still fails, send a reproducible example.


Uwe Ligges





On 23.02.2012 18:04, Matthew Keller wrote:

Hi all,

I'm trying to use the package read.table within a foreach loop. I'm
grabbing 500M rows of data at a time from two different files and then
doing an aggregate/tapply like function in read.table after that. I
had planned on doing a foreach loop 39 times at once for the 39 files
I have, but obviously that won't work until I figure out why the
segfault is occurring. The sessionInfo, code, and error are pasted
below. If you have any ideas, would love to hear them. (I have no
control over the version of R - 2.13.0 - being used). Best

Matt


SESSION INFO:


sessionInfo()

R version 2.13.0 (2011-04-13)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 LC_MONETARY=C
  [6] LC_MESSAGES=en_US.UTF-8LC_PAPER=en_US.UTF-8   LC_NAME=C
LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] data.table_1.7.10 doMC_1.2.2multicore_0.1-5
foreach_1.3.2 codetools_0.2-8   iterators_1.0.3



MY CODE:

computeAllPairSums<- function(filename, nbindiv,nrows.to.read)
{
con<- file(filename, open="r")
on.exit(close(con))
ans<- matrix(numeric(nbindiv * nbindiv), nrow=nbindiv)
chunk<- 0L
while (TRUE) {
#read.table faster than scan
df0<- read.table(con,col.names=c("ID1", "ID2", "ignored", "sharing"),
 colClasses=c("integer", "integer", "NULL",
"numeric"),nrows=nrows.to.read,comment.char="")

DT<- data.table(df0)
setkey(DT,ID1,ID2)
ss<- DT[,sum(sharing),by="ID1,ID2"]

if (nrow(df0) == 0L)
break

chunk<- chunk + 1L
cat("Processing chunk", chunk, "... ")

   idd<- as.matrix(subset(ss,select=1:2))
   newvec<- as.vector(as.matrix(subset(ss,select=3)))
   ans[idd]<- ans[idd] + newvec

  cat("OK\n")
  }
ans
  }



require(foreach)
require(doMC)
registerDoMC(cores=2)


num<- 8891
nr<-  5L   #500 million rows at a time


MMM<-  foreach(IT = 1:2) %dopar% {
   require(data.table)
   if (IT==1){ x<- system.time({computeAllPairSums(
paste(GERMLINE,"bc.chr22.q.20.file",sep=''),num,nr)}) } #Run it on
regular file PID 6489, 24 gb
   if (IT==2){ z<- system.time({computeAllPairSums.gz(
paste(GERMLINE,"bc.chr22.q.20.gz",sep=''),num,nr)}) } #Run it on gz
file PID 6490, 24 gb
}


MY R OUTPUT/ERROR:

MMM<-  foreach(IT = 1:2) %dopar% {
+   require(data.table)
+   if (IT==1){ x<- system.time({computeAllPairSums(
paste(GERMLINE,"bc.chr22.q.20.file",sep=''),num,nr)}) } #Run it on
regular file PID 6053, 5.9 gb
+   if (IT==2){ z<- system.time({computeAllPairSums.gz(
paste(GERMLINE,"bc.chr22.q.20.gz",sep=''),num,nr)}) } #Run it on gz
file PID 6054, 4 gb
+ }

Loading required package: data.table
Loading required package: data.table
data.table 1.7.10  For help type: help("data.table")
data.table 1.7.10  For help type: help("data.table")

  *** caught segfault ***
address 0x2ae93df9, cause 'memory not mapped'

Traceback:
  1: .Call("dogroups", x, xcols, o__, f__, len__, jsub, SDenv, testj,
   byretn, byval, i, as.integer(icols), i[1, ivars, with = FALSE],
if (length(ivars)) paste("i.", ivars, sep = ""), is.na(nomatch),
verbose, PACKAGE = "data.table")
  2: `[.data.table`(DT, , sum(sharing), by = "ID1,ID2")
  3: DT[, sum(sharing), by = "ID1,ID2"]
  4: computeAllPairSums(paste(GERMLINE, "bc.chr22.q.20.file", sep =
""), num, nr)
  5: system.time({computeAllPairSums(paste(GERMLINE,
"bc.chr22.q.20.file", sep = ""), num, nr)})
  6: eval(expr, envir, enclos)
  7: eval(c.expr, envir = args, enclos = envir)
  8: doTryCatch(return(expr), name, parentenv, handler)
  9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
10: tryCatchList(expr, classes, parentenv, handlers)
11: tryCatch(eval(c.expr, envir = args, enclos = envir), error = function(e) e)
12: FUN(X[[1L]], ...)
13: lapply(S, FUN, ...)
14: doTryCatch(return(expr), name, parentenv, handler)
15: tryCatchOne(expr, names, parentenv, handlers[[1L]])
16: tryCatchList(expr, classes, parentenv, handlers)
17: tryCatch(expr, error = function(e) {call<- conditionCall(e)
  if (!is.null(call)) {if (identical(call[[1L]],
quote(doTryCatch))) call<- sys.call(-4L)dcall<-
deparse(call)[1L]prefix<- paste("Error in", dcall, ": ")
   LONG<- 75Lmsg<- conditionMessage(e)sm<-
strsplit(msg, "\n")[[1L]]w<- 14L + nchar(dcall, type = "w") +
nchar(sm[1L], type = "w")if (is.na(w)) w<- 14L +
nchar(dcall, type = "b") + nchar(sm[1L], type = "b"

Re: [R] help with winbugs glm

2012-02-24 Thread Adan Jordan-Garza
Ok this makes a lot of sense, thank you very much Ilai!
Cheers
Guillermo

On Fri, Feb 24, 2012 at 12:16 AM, ilai  wrote:

> On Thu, Feb 23, 2012 at 8:32 PM, Adan Jordan-Garza
>  wrote:
> > Hello Ilai,
> > thank you very much for your response,
> > can I bother you a little further?
> > What do you mean my model is not identifiable?
>
> You should read up on model identifiably or consult your local
> statistician for a complete explanation, especially if you are to be
> doing more analysis. An incomplete explanation just regarding your
> bugs code: you are estimating "a" (an overall mean) and the three
> levels b[1:3]. That's too much, you need to remove "a". Think what you
> are asking of bugs to estimate (I'll make up some numbers): for bugs,
> the solution
> a = 10
> b[1] = 0
> b[2] = -2
> b[3] = -5
> is no different than
> a = 8
> b[1] = 2
> b[2] = 0
> b[3] = -3
> or
> a = 5
> b[1] = 5
> b[2] = 3
> b[3] = 0
>
> This is why you're getting large intervals - even with convergence
> etc. the MCMC is simply skipping between these options with no way to
> "identify" which is it since it knows the means for depths 1:3, but
> nothing about "a". a could be 100 and all others -99,-95 etc.
> Makes sense?
>
> It is, for e.g., the reason why summary(glm(y~Depth)) gave you
> intercept (in R the first level) and estimates for the DIFFERENCES of
> all other factor levels from the first. It was not just to make it
> harder on you, it's because the same idea holds for the frequentist
> approach.
>
> It runs ok (1
> > iteractions) no autocorrelation, and it does converge but the credible
> > intervals are too big. Yes Depth has 3 levels and I coded them as 1, 2,
> and
> > 3. In all the examples I have seen for winBugs they use this type of
> coding
> > for categorical predictors.
>
> Like I said, winBugs may have some feature where it will build the
> design matrix internally, so you can pass categorical variables as
> column vectors (like R) but I seriously doubt it can guess your
> variable coded 1,2,3 is categorical. If you can reference an example
> like that from winBugs examples (not some random code from the
> Internet) I'd really appreciate it.
> What I think is happening is you're fitting
> y1 = 1b[1]  + e1
> y2 = 3b[3]  + e2
> ...
> y232 = ... + e232
>
> But why should b[3] be 3 times b[1] ? that makes no sense for
> categories. And the estimates are completely off (as you've noted in
> your post) not just large variance.
>
>  I have read about the matrix of dummy variables
> > but I am not sure if I am supposed to code that explicitly in winBugs or
> how
> > to do it. I already got the dummy matrix from R.
>
> There are R2winbugs and other packages to let you run winbugs from R
> or pass the data. I don't use them so I don't know. At the end what
> you want is Depth to be a 3 column matrix, either the same as glm to
> get estimate of Depth1,Depth2-1,Depth3-1 :
> 1 0 0
> 1 0 0
> 1 1 0
> 1 1 0
> 1 0 1
> 1 0 1
>
> Or you could have an estimate for every depth:
> 1 0 0
> 1 0 0
> 0 1 0
> 0 1 0
> 0 0 1
> 0 0 1
>
> And your code:
> model
>  {
>  for (i in 1:232)
>  {
>  Recruitment[i]~dpois(lambda[i])
>  log(lambda[i])<- b[1]*Depth[,1]+b[2]*Depth[,2]+b[3]*Depth[,3]
>  }
>  b[1]~dnorm(0,0.01)
>  b[2]~dnorm(0,0.01)
>  b[3]~dnorm(0,0.01)
>  }
>
> Now compare the result to glm.
>
> > from R. Do you recommend JAGS over winBugs?
>
> I don't use winBugs because I'm not on a Win OS. I don't think JAGS
> has an advantage for simple models like this.
>
> Good luck, and please cc the r-help list in your answer so the thread
> is complete.
>
> Elai.
>
>
> > Thank you very much for your time, I really appreciate it.
> >
> > This is my whole code in winBugs:
> >
> > model
> > {
> > for (i in 1:232)
> > {
> > Recruitment[i]~dpois(lambda[i])
> > log(lambda[i])<-a+b[Depth[i]]*Depth[i]
> > }
> > a~dnorm(0,0.01)
> > b[1]~dnorm(0,0.01)
> > b[2]~dnorm(0,0.01)
> > b[3]~dnorm(0,0.01)
> > }
> > list(a=0, b=c(0,0,0))
> >
> > Depth[] Recruitment[]
> >
> > 1 0
> >
> > 1 0
> >
> > 1 1
> >
> > 1 0
> >
> > 1 1
> >
> > 1 1
> >
> > 1 1
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 1
> >
> > 1 1
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 8
> >
> > 1 0
> >
> > 1 0
> >
> > 1 2
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 1
> >
> > 1 2
> >
> > 1 1
> >
> > 1 0
> >
> > 1 1
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 0
> >
> > 1 8
> >
> > 2 2
> >
> > 2 0
> >
> > 2 0
> >
> > 2 4
> >
> > 2 0
> >
> > 2 0
> >
> > 2 0
> >
> > 2 0
> >

[R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
Dear list,

n00b question, but still can't find any easy answer.

Here is a df:

> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
> df
   x y
1 AA 1
2 BB 2
3 CC 3
4 AA 4


I want to modify this df this way :
 if df$x=="AA" then df$y=df$y*10
 if df$x=="BB" then df$y=df$y*25

and so on with other conditions.

TY for any help.

Trading
 
A2CT2 Ltd.


Arnaud Gaboury
 
A2CT2 Ltd.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Advice on exploration of sub-clusters in hierarchical dendrogram

2012-02-24 Thread ilai
Inline:

On Thu, Feb 23, 2012 at 8:23 PM, R. Michael Weylandt
  wrote:
> Inline:
>
> On Feb 23, 2012, at 6:20 PM, kosmo7  wrote:
>
>> Dear Elai,
>> thank you very much for your suggestion. I tried cutting the dendrogram
>> instead of the hclust tree with:
>> clusters<-cut(x, h=1.6)
>>
>> but then when I try to call/plot cluster 1 for example, with:
>> plot(clusters$lower[[1]])
>>
>> I get only 2 members that are joined together at distance=0  (cluster 1 for
>> instance, consists of several hundred of members).
>> So it looks like / plot(clusters$lower[[1]])/ only calls the very first node
>> of the tree and not the content of the respective cluster [[1]] at the
>> defined cutoff=1.6.

The "suggestions" in my original post are just pointers to the fact
there are methods for class dendrogram to achieve what you wanted.
Since you got as far as x<-as.dendrogram(z) I assumed that's all you
needed.

Maybe /cut/ instead of /cutree/ doesnt do the work? Or
>> maybe I am just doing something  wrong?...

The examples in ?as.dendrogram and ?dendrapply are self contained,
very clear and straight forward. If you haven't done so already I
suggest you try them. Most likely the problem is in your data
(row.names ? ) or your interpretation of who is "cluster1" or the 1.6
cutoff.

>>
>>
>>
>> In another post I read that with /df[value %in% v, ] / I can extract
>> specific subsets of a data frame/table.
>

Seems I missed some back and forth on this post already, so my
apologies if this is no longer an issue. Personally I find that
because there are many more nodes and info in a tree than rows in the
data set (leaf nodes only) much of the "usual" generic R solutions get
distorted when it comes to trees. Better to use appropriate methods
for the class (dendrapply helps as I've said before).

Hope that helps dig you out of the hole.
Elai


> That was me and there's a slight mistake in that post (corrected by Sarah): 
> should be
>
> df[df$value %in% v, ]
>
> Sorry for any confusion that might have caused
>
> Michael
>> Maybe I could use this to extract
>> only the distances of members of a specific cluster as defined by cutree
>> from the initial distance matrix? But still, I am afraid I don't get what I
>> should use as /value/ and /v/
>>
>> --
>> View this message in context: 
>> http://r.789695.n4.nabble.com/Advice-on-exploration-of-sub-clusters-in-hierarchical-dendrogram-tp4414277p4415589.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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

2012-02-24 Thread Ben Bolker
jurgen_vercauteren  hotmail.com> writes:

> I am analysing my data wit a mixed model. I used SAS but I want to redo the
> same analysis in R. Here the SAS code and what I wrote in R. It seems to
> work but the results are not the same. I don't know how to specify the class
> variable in R or specify the variance matrix. Can you please help me?
> 
> Thanks
> Jurgen
> 
> ## SAS:
> proc glimmix data=trend method=RSPL;
>class pid;
>model mdrfinal (event = '1') = time therapy comment / dist=binary
> link=logit solution cl;
>random intercept / subject=pid type=un;
> run;
> 
> ## R:
> model_GLMM<- glmmPQL(mdrfinal ~ time + therapy + comment, data = data,
> family = binomial, random = ~1| time)
> summary(model_GLMM) 

  This question would probably get a better reception on the r-sig-mixed-models
 r-project.org mailing list.

  I think you want random = ~1|pid , although with an unstructured
variance-covariance matrix you may want random=~factor(time)|pid --
keep in mind that's what on the RHS of the bar is a grouping factor,
the LHS of the bar is the random effect(s) term.

  If you do ~1|pid you'll get a compound-symmetry model with positive rho;
if ftime is a factor variable and you do ~ftime|pid you'll get an
unstructured matrix.

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

2012-02-24 Thread Prof Brian Ripley

On Fri, 24 Feb 2012, diyanah wrote:


hello,

I think my EBImage is succesfully unpacked using R and I receive this
message


On Windows it seems, but EBImage is a Bioconductor package and they 
have their own lists.




package 'EBImage' successfully unpacked and MD5 sums checked

The downloaded packages are in
   C:\Users\Yana-Chan\AppData\Local\Temp\Rtmp7VFmH5\downloaded_packages

but when I try to call the library, I receive this


library("EBImage")

Loading required package: abind
Error in inDL(x, as.logical(local), as.logical(now), ...) :
 unable to load shared object 'C:/Program
Files/R/R-2.13.2/library/EBImage/libs/i386/EBImage.dll':
 LoadLibrary failure:  The specified module could not be found.

Error: package/namespace load failed for 'EBImage'

Do you have an explanation what went wrong?


You didn't read the documentation.  EBImage needs appropriate 
versions of ImageMagick and Gtk+ in your PATH: the information is in 
the vignette EBImage-installation.pdf .  (At least in the version of 
EBImage I looked at the vignette was not very accurate.)




Thank you



PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


The 'at a minimum' information we asked for would have been very 
useful.  But we can deduce that you need to update from R 2.13.2.



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

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


Re: [R] saving all data in r object

2012-02-24 Thread R. Michael Weylandt
You have three problems:

1) You don't post with context
2) You have a (likely OS permissions) issue that keeps you from
accessing the RData file
3) You can't put a whole bunch of data in a single element of an
object (ie., you are trying to put a column of data in a single
element of an object: if the column is long, this is a problem)

Michael

On Thu, Feb 23, 2012 at 9:50 AM, uday  wrote:
> Michael , the first error which I got is
> "number of items to replace is not a multiple of replacement length"
> sorry last time it did not copied whole thing
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/saving-all-data-in-r-object-tp4413092p4414058.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.


  1   2   >