[R] iplots

2011-10-07 Thread fernando.cabrera
Hi guys,

I am trying to plot a scatterplot with lines instead of with points using 
function iplot in library iplots. 

The best I can come up with is 

x =(1:100)
y = rnorm(100)
iplot(x,y,ptDiam=0)
ilines(x,y)

Do you guys know of any paramter to set the type in iplot or iplot.opt?

Thanks,

Fernando Álvarez

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


Re: [R] Populate a matrix

2011-10-06 Thread fernando.cabrera
This last solution is what I was looking for, I was trying to avoid loops. 
Thanks!

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Rainer Schuermann
Sent: 5. oktober 2011 18:29
To: r-help@r-project.org
Subject: Re: [R] Populate a matrix

m - matrix( rep( y, length( x ) ), length( y ), length( x ) )


On Wednesday 05 October 2011 18:11:18 fernando.cabr...@nordea.com wrote:
 Hi guys
 
 I have vectors x - c(1,2,3,4) and y - c(4,3,9) and would like to generate a 
 matrix which has 3 rows (length(y)) and 4 
columns (length(x)), and each row is the corresponding y element repeated 
length(x) times.
 
 4,4,4,4
 3,3,3,3
 9,9,9,9
 
 Thanks.
 
 Fernando Álvarez
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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

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


[R] Populate a matrix

2011-10-05 Thread fernando.cabrera
Hi guys

I have vectors x - c(1,2,3,4) and y - c(4,3,9) and would like to generate a 
matrix which has 3 rows (length(y)) and 4 columns (length(x)), and each row is 
the corresponding y element repeated length(x) times.

4,4,4,4
3,3,3,3
9,9,9,9

Thanks.

Fernando Álvarez

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


Re: [R] Matrix/Vector manipulation

2011-10-04 Thread fernando.cabrera
Stylish, but ifelse only includes a cumsum less or equal than v and ignores the 
remainder, if v does not fit equally in say the first two weight buckets.
 
 R  - c(1.2, 1.3, 1.5)
 W - c(3,2,5)
 my_cumsum(4, R, W) # should take 3*1.2 + 1*1.3
[1] 4.0 
 sum(ifelse(cumsum(W) = 4, W, 0) * R) # ignores the 1*1.3 part because 3+2  4
[1] 3.6

Cheers,
Fer

-Original Message-
From: David Reiner [mailto:david.rei...@xrtrading.com] 
Sent: 3. oktober 2011 17:57
To: Cabrera, Fernando Álvarez; r-help@r-project.org
Subject: RE: [R] Matrix/Vector manipulation

sum(ifelse(cumsum(W)=v, W, 0) * R)

HTH,
David L. Reiner


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of fernando.cabr...@nordea.com
Sent: Monday, October 03, 2011 9:50 AM
To: r-help@r-project.org
Subject: [SPAM] - [R] Matrix/Vector manipulation - Bayesian Filter detected spam

Hi guys,

Have the following problem computing vectors with pure vector algebra and end 
up reverting to recursion or for-looping.

Function my_cumsum calculates a weighted average (W) of ratios (R), but only up 
to the given size/volume (v). Now I recurse into the vector (from left to 
right) with what you have left from the difference of volume minus current 
weight, and stop when the difference is less than or equal to the current 
weight.

Vectors W and R have the same length, and v is always a positive integer.

W: {w_1 w_2 .. w_m}
R: {r_1 r_2 .. r_m}

my_cumsum - function(v, R, W) {
if (v = W[1]) # check the head
v*R[1]
else
W[1]*R[1] + my_cumsum(v - W[1], R[2:length(R)], W[2:length(W)]) 
# recurse the tail }

Any help is greatly appreciated!

Fernando Alvarez

Great ideas originate in the muscles. ~ Thomas A. Edison

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, XR Content) are confidential 
and proprietary to XR Trading, LLC (XR) and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

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


Re: [R] Matrix/Vector manipulation

2011-10-04 Thread fernando.cabrera
Correction to my previous mail: my_cumsum(4,R,W) does not return 4.0, it 
returns 4.9!

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of fernando.cabr...@nordea.com
Sent: 4. oktober 2011 08:37
To: r-help@r-project.org
Subject: Re: [R] Matrix/Vector manipulation

Stylish, but ifelse only includes a cumsum less or equal than v and ignores the 
remainder, if v does not fit equally in say the first two weight buckets.
 
 R  - c(1.2, 1.3, 1.5)
 W - c(3,2,5)
 my_cumsum(4, R, W) # should take 3*1.2 + 1*1.3
[1] 4.0 
 sum(ifelse(cumsum(W) = 4, W, 0) * R) # ignores the 1*1.3 part because 3+2  4
[1] 3.6

Cheers,
Fer

-Original Message-
From: David Reiner [mailto:david.rei...@xrtrading.com] 
Sent: 3. oktober 2011 17:57
To: Cabrera, Fernando Álvarez; r-help@r-project.org
Subject: RE: [R] Matrix/Vector manipulation

sum(ifelse(cumsum(W)=v, W, 0) * R)

HTH,
David L. Reiner


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of fernando.cabr...@nordea.com
Sent: Monday, October 03, 2011 9:50 AM
To: r-help@r-project.org
Subject: [SPAM] - [R] Matrix/Vector manipulation - Bayesian Filter detected spam

Hi guys,

Have the following problem computing vectors with pure vector algebra and end 
up reverting to recursion or for-looping.

Function my_cumsum calculates a weighted average (W) of ratios (R), but only up 
to the given size/volume (v). Now I recurse into the vector (from left to 
right) with what you have left from the difference of volume minus current 
weight, and stop when the difference is less than or equal to the current 
weight.

Vectors W and R have the same length, and v is always a positive integer.

W: {w_1 w_2 .. w_m}
R: {r_1 r_2 .. r_m}

my_cumsum - function(v, R, W) {
if (v = W[1]) # check the head
v*R[1]
else
W[1]*R[1] + my_cumsum(v - W[1], R[2:length(R)], W[2:length(W)]) 
# recurse the tail }

Any help is greatly appreciated!

Fernando Alvarez

Great ideas originate in the muscles. ~ Thomas A. Edison

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, XR Content) are confidential 
and proprietary to XR Trading, LLC (XR) and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

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

2011-10-03 Thread fernando.cabrera
Hi guys,

Have the following problem computing vectors with pure vector algebra and end 
up reverting to recursion or for-looping. 

Function my_cumsum calculates a weighted average (W) of ratios (R), but only up 
to the given size/volume (v). Now I recurse into the vector (from left to 
right) with what you have left from the difference of volume minus current 
weight, and stop when the difference is less than or equal to the current 
weight. 

Vectors W and R have the same length, and v is always a positive integer.

W: {w_1 w_2 .. w_m}
R: {r_1 r_2 .. r_m}

my_cumsum - function(v, R, W) {
if (v = W[1]) # check the head
v*R[1]
else
W[1]*R[1] + my_cumsum(v - W[1], R[2:length(R)], W[2:length(W)]) 
# recurse the tail
}

Any help is greatly appreciated!

Fernando Alvarez

Great ideas originate in the muscles. ~ Thomas A. Edison

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


Re: [R] Matrix and list indices

2011-09-28 Thread fernando.cabrera
Thanks Michael it works!

Have to say it is amazing what you can do in R with a few lines (a line in this 
case) of code.

Fernando

From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com]
Sent: 27. september 2011 15:43
To: Cabrera, Fernando Álvarez
Subject: Re: [R] Matrix and list indices

Untested, I believe this should work, though you might need to modify for 
floating point funny business in testing the equalities:

my_list - list( earth=array(c(0,0,45,0,0,45,0,45),dim=c(2,2,2)), 
mars=array(c(8:1),dim=c(2,2,2)))
my_list$earth[my_list$earth==0] - my_list$mars[my_list$earth==0]

Hope this helps,

Michael Weylandt
On Tue, Sep 27, 2011 at 8:49 AM, 
fernando.cabr...@nordea.commailto:fernando.cabr...@nordea.com wrote:
Hi guys,

I am trying to replace all elements of earth that are equal to zero with their 
corresponding elements in mars. I can do the replace with a bunch of for-loops, 
but I don't think this is the R way of doing things.

my_list - list( earth=array(c(0,0,45,0,0,45,0,45),dim=c(2,2,2)), 
mars=array(c(8:1),dim=c(2,2,2)))
my_list
for (i in c(1:2)) {
   for (j in c(1:2)) {
   for (k in c(1:2)) {
   if (my_list$earth[i,j,k] == 0) {
   
my_list$earth[i,j,k] - my_list$mars[i,j,k]
   }
   }
   }
}
my_list

Do you guys have any suggestions for getting rid of the ugly for-loops?

Many thanks,

Fernando Álvarez

Nordea e-Markets
Strandgade 3
PO Box 850
DK-0900 Copenhagen C
Denmark
Tel.: +45 33 33 32 67tel:%2B45%2033%2033%2032%2067
Mobile: +45 61 55 27 54tel:%2B45%2061%2055%2027%2054

This transmission is intended solely for the person or entity to whom it is 
addressed. It may contain privileged and confidential information. If you are 
not the intended recipient, please be notified that any dissemination, 
distribution or copying is strictly prohibited. If you have received this 
transmission by mistake, please let us know and then delete it from your system.

P Please consider the impact on the environment before printing this e-mail.


   [[alternative HTML version deleted]]


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

2011-09-27 Thread fernando.cabrera
Hi guys,

I am trying to replace all elements of earth that are equal to zero with their 
corresponding elements in mars. I can do the replace with a bunch of for-loops, 
but I don't think this is the R way of doing things.

my_list - list( earth=array(c(0,0,45,0,0,45,0,45),dim=c(2,2,2)), 
mars=array(c(8:1),dim=c(2,2,2)))
my_list
for (i in c(1:2)) {
for (j in c(1:2)) {
for (k in c(1:2)) {
if (my_list$earth[i,j,k] == 0) {

my_list$earth[i,j,k] - my_list$mars[i,j,k]
}
}
}
}
my_list

Do you guys have any suggestions for getting rid of the ugly for-loops?

Many thanks,

Fernando Álvarez

Nordea e-Markets
Strandgade 3
PO Box 850
DK-0900 Copenhagen C
Denmark
Tel.: +45 33 33 32 67
Mobile: +45 61 55 27 54

This transmission is intended solely for the person or entity to whom it is 
addressed. It may contain privileged and confidential information. If you are 
not the intended recipient, please be notified that any dissemination, 
distribution or copying is strictly prohibited. If you have received this 
transmission by mistake, please let us know and then delete it from your system.

P Please consider the impact on the environment before printing this e-mail.


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