[R] array

2007-08-07 Thread Tiandao Li
Hello,

I have some files generated from microarray experiments. I used scan() to
read the files, and assigned each file to a unique name with many rows and
columns. Now I want to create a array (ArrayA) with unique names, and I can
use ArrayA[1,2][[6]] to refer the data in each file. Is there any packages
available for array of array?

Thanks!

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array

2007-08-07 Thread Roland Rau
Hi,

Tiandao Li wrote:
 Hello,
 
 I have some files generated from microarray experiments. I used scan() to
 read the files, and assigned each file to a unique name with many rows and
 columns. Now I want to create a array (ArrayA) with unique names, and I can
 use ArrayA[1,2][[6]] to refer the data in each file. Is there any packages
 available for array of array?
 
if all of your initial arrays only consist of rows and columns
(i.e. matrices) and have the same number of rows and columns, you can
store it conveniently in a three dimensional array:

mat1a - matrix(1:10, ncol=2)
mat2a - matrix(11:20, ncol=2)
mat1a
mat2a

arr3D - array(numeric(0), dim=c(nrow(mat1a), ncol(mat1a), 2))
arr3D[,,1] - mat1a
arr3D[,,2] - mat2a

arr3D
arr3D[,,2]

if your initial arrays (assuming again that you have matrices) have
varying amount of rows and columns, I would suggest to use lists:

mat1b - matrix(1:10, ncol=2)
mat2b - matrix(101:133, ncol=3)
mat1b
mat2b
list3D - list(numberone=mat1b, numbertwo=mat2b)
list3D

list3D[[1]]
list3D[[1]]
list3D[[numberone]]
list3D[[numbertwo]]


I hope this helps.

Best,
Roland

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array

2007-08-07 Thread Tiandao Li
Hello,

I have 30 GenePix tab-delimited files generated from 10 microarray 
experiments, each has 3 replicates. I used scan() to read the files, and 
assigned each file to a unique name (such as A1, A2, A3 for experment A, 
and B1, B2, and B3 for experiment B) with 1000 rows and 56 columns.

Now I want to create a array (ArrayA) with these file names,

ArrayA
[,1][,2]... [,10]
[1,]A1  B1  C1
[2,]A2  B2  C2
[3,]A3  B3  C3

so I can use ArrayA[1,2][[6]] to refer the data in column6 of experimentB, 
replicate 1. Is there any packages available for array of array?

Thanks!

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array loop

2007-08-01 Thread Petr PIKAL
Hi

Dong GUO 郭东 [EMAIL PROTECTED] napsal dne 31.07.2007 15:27:35:

 Thanks, Petr.
 
 I changed the equation mark from = to -, then, it works fine. Dont 
know 
 what difference it has made between the = and -..

from help page

The operators - and = assign into the environment in which they are 
evaluated. The operator- can be used anywhere, whereas the operator = is 
only allowed at the top level (e.g., in the complete expression typed at 
the command prompt) or as one of the subexpressions in a braced list of 
expressions. 

Although I do not fully understand where I can use - and where =, to be 
on safe side I use - everywhere when I want to do assignment of some 
value(s).

Regards

Petr

 
 Regards,
 Dong 

 On 7/31/07, Petr PIKAL [EMAIL PROTECTED] wrote:
 Hi
 
 as you say that the computing is part of a function than the best way to
 see what is hapenning is to use
 
 debug(your.function)
 
 see ?debug for options.
 
 Regards
 
 Petr
 [EMAIL PROTECTED]
 
 [EMAIL PROTECTED] napsal dne 31.07.2007 00:11:00:
 
  Dear all,
 
  here are two arrays: region(26,31,8), nation(8) 
 
  I tried to get a new array, say, giGi(26,31,8)
 
  giGi - array(0,dim = c(region_dim))
 
  for (i in (1:region_dim[3]))
  {
  giGi[,,i] = region[,,i]-nation[,i]
 
  }
 
  As the above is part of function, but results shows only giGi[,,1] has
 the
  right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I 
have
  checked array of region and nation, they are not zeros at all 
 
  when I do manually, it is not the case, giGi has meanful numbers.
 
  can some one tell me the trick in this process??
 
  Many thanks in advance.
  Dong
 
 [[alternative HTML version deleted]] 
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array loop

2007-08-01 Thread Dong GUO 郭东
Thanks again, Petr. Following the reference, that would be true that =
only assign values to the top level...So apparently using '-' is the safe
all the time to assign values.

Dong


On 8/1/07, Petr PIKAL [EMAIL PROTECTED] wrote:

 Hi

 Dong GUO ¹ù¶« [EMAIL PROTECTED] napsal dne 31.07.2007 15:27:35:

  Thanks, Petr.
 
  I changed the equation mark from = to -, then, it works fine. Dont
 know
  what difference it has made between the = and -..

 from help page

 The operators - and = assign into the environment in which they are
 evaluated. The operator- can be used anywhere, whereas the operator = is
 only allowed at the top level (e.g., in the complete expression typed at
 the command prompt) or as one of the subexpressions in a braced list of
 expressions.

 Although I do not fully understand where I can use - and where =, to be
 on safe side I use - everywhere when I want to do assignment of some
 value(s).

 Regards

 Petr

 
  Regards,
  Dong

  On 7/31/07, Petr PIKAL [EMAIL PROTECTED] wrote:
  Hi
 
  as you say that the computing is part of a function than the best way to
  see what is hapenning is to use
 
  debug(your.function)
 
  see ?debug for options.
 
  Regards
 
  Petr
  [EMAIL PROTECTED]
 
  [EMAIL PROTECTED] napsal dne 31.07.2007 00:11:00:
 
   Dear all,
  
   here are two arrays: region(26,31,8), nation(8)
  
   I tried to get a new array, say, giGi(26,31,8)
  
   giGi - array(0,dim = c(region_dim))
  
   for (i in (1:region_dim[3]))
   {
   giGi[,,i] = region[,,i]-nation[,i]
  
   }
  
   As the above is part of function, but results shows only giGi[,,1] has
  the
   right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I
 have
   checked array of region and nation, they are not zeros at all
  
   when I do manually, it is not the case, giGi has meanful numbers.
  
   can some one tell me the trick in this process??
  
   Many thanks in advance.
   Dong
  
  [[alternative HTML version deleted]]
  
   __
   R-help@stat.math.ethz.ch mailing list
   https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array loop

2007-07-31 Thread Dong GUO 郭东
Thanks, Petr.

I changed the equation mark from = to -, then, it works fine. Dont know
what difference it has made between the = and -..

Regards,
Dong

On 7/31/07, Petr PIKAL [EMAIL PROTECTED] wrote:

 Hi

 as you say that the computing is part of a function than the best way to
 see what is hapenning is to use

 debug(your.function)

 see ?debug for options.

 Regards

 Petr
 [EMAIL PROTECTED]

 [EMAIL PROTECTED] napsal dne 31.07.2007 00:11:00:

  Dear all,
 
  here are two arrays: region(26,31,8), nation(8)
 
  I tried to get a new array, say, giGi(26,31,8)
 
  giGi - array(0,dim = c(region_dim))
 
  for (i in (1:region_dim[3]))
  {
  giGi[,,i] = region[,,i]-nation[,i]
 
  }
 
  As the above is part of function, but results shows only giGi[,,1] has
 the
  right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I have
  checked array of region and nation, they are not zeros at all
 
  when I do manually, it is not the case, giGi has meanful numbers.
 
  can some one tell me the trick in this process??
 
  Many thanks in advance.
  Dong
 
 [[alternative HTML version deleted]]
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array writing and their filenames

2007-07-30 Thread Dong GUO 郭东
Hi,

I want to save a array (say, array[6,7,8]) write a cvs file. How can I do
that??? can I write in one file?

if I could not write in one file, i want to use a loop to save in different
files (in the matrix[6,7,8], should be 8 csv files), such as the filename
structure should be: file =filename +str(i) +. +csv

Many thanks.
Dong

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array writing and their filenames

2007-07-30 Thread Dong GUO 郭东
Many thanks to Edna and Roland.
I followed the suggestions, and it worked well.

Regards,
Dong

On 7/30/07, Edna Bell [EMAIL PROTECTED] wrote:

  #Original 3x4x2 array
  xb
 , , 1

  [,1] [,2] [,3] [,4]
 [1,]  0.4  0.9  5.6  0.1
 [2,]  0.3  2.3  3.3  0.7
 [3,]  0.6  0.8  0.2  0.7

 , , 2

  [,1] [,2] [,3] [,4]
 [1,]  0.4  0.9  5.6  0.1
 [2,]  0.3  2.3  3.3  0.7
 [3,]  0.6  0.8  0.2  0.7

  for(i in 1:2) {
 + write(file=stuff4,t(xb[,,i]),ncol=4,append=T)
 + xx - paste(end of array ,i,sep=)
 + write(file=stuff4,xx,append=T)
 + }
  file.show(stuff4)
  #All is well
 


 On 7/29/07, Dong GUO ¹ù¶« [EMAIL PROTECTED] wrote:
  Hi,
 
  I want to save a array (say, array[6,7,8]) write a cvs file. How can I
 do
  that??? can I write in one file?
 
  if I could not write in one file, i want to use a loop to save in
 different
  files (in the matrix[6,7,8], should be 8 csv files), such as the
 filename
  structure should be: file =filename +str(i) +. +csv
 
  Many thanks.
  Dong
 
 [[alternative HTML version deleted]]
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array loop

2007-07-30 Thread Dong GUO 郭东
Dear all,

here are two arrays: region(26,31,8), nation(8)

I tried to get a new array, say, giGi(26,31,8)

giGi - array(0,dim = c(region_dim))

for (i in (1:region_dim[3]))
{
giGi[,,i] = region[,,i]-nation[,i]

}

As the above is part of function, but results shows only giGi[,,1] has the
right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I have
checked array of region and nation, they are not zeros at all

when I do manually, it is not the case, giGi has meanful numbers.

can some one tell me the trick in this process??

Many thanks in advance.
Dong

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array writing and their filenames

2007-07-30 Thread Roland Rau
Dong GUO 郭东 wrote:
 Hi,
 
 I want to save a array (say, array[6,7,8]) write a cvs file. How can I do
 that??? can I write in one file?
For array[6,7,8], you don't need a csv(!) file since it is only a 
scalar. If this is what you want, check
?write.table

But what you probably meant is how to write a three-dimensional array to 
disk. Have a look at this code:
##
roland - array(1:(6*7*8), dim=c(6,7,8))
roland
dump(list=roland, file = H:\\dumpdata.R)

ls()
rm(list=ls())
ls()
source(H:\\dumpdata.R)
ls()
roland
##

Does this help?
Roland

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array searches

2007-02-23 Thread Murali Menon
Hi,

This is truly amazing stuff. Inspired by Jim's and Olivier's suggestions, 
I'm trying to expand it to work with a m x n matrix, where the first column 
is dates and the next columns are all signals. I dare say a suitable 
application of 'apply' should work.

Thanks a ton.
Murali


From: jim holtman [EMAIL PROTECTED]
To: Murali Menon [EMAIL PROTECTED]
CC: r-help@stat.math.ethz.ch
Subject: Re: [R] array searches
Date: Fri, 16 Feb 2007 10:21:40 -0500

try this:

x - scan(textConnection(30/01/2007  0
+ 31/01/2007  -1
+ 01/02/2007  -1
+ 02/02/2007  -1
+ 03/02/2007  1
+ 04/02/2007  1
+ 05/02/2007  1
+ 06/02/2007  1
+ 07/02/2007  1
+ 08/02/2007  1
+ 09/02/2007  0
+ 10/02/2007  0
+ 11/02/2007  0
+ 12/02/2007  1
+ 13/02/2007  1
+ 14/02/2007  1
+ 15/02/2007  0
+ 16/02/2007  0
+ ), what=list(date=, value=0))
Read 18 records
x$date - as.Date(x$date, %d/%m/%Y)
# determine the breaks
x.breaks - c(TRUE, diff(x$value) != 0)
# determine the value at the break; assume that it is the minimum
x.bdate - x$date[x.breaks]
data.frame(date=x.bdate[cumsum(x.breaks)], value=x$value)
 date value
1  2007-01-30 0
2  2007-01-31-1
3  2007-01-31-1
4  2007-01-31-1
5  2007-02-03 1
6  2007-02-03 1
7  2007-02-03 1
8  2007-02-03 1
9  2007-02-03 1
10 2007-02-03 1
11 2007-02-09 0
12 2007-02-09 0
13 2007-02-09 0
14 2007-02-12 1
15 2007-02-12 1
16 2007-02-12 1
17 2007-02-15 0
18 2007-02-15 0






On 2/16/07, Murali Menon [EMAIL PROTECTED] wrote:

Folks,

I have a dataframe comprising a column of dates and a column of signals
(-1,
0, 1) that looks something like this:

30/01/2007  0
31/01/2007  -1
01/02/2007  -1
02/02/2007  -1
03/02/2007  1
04/02/2007  1
05/02/2007  1
06/02/2007  1
07/02/2007  1
08/02/2007  1
09/02/2007  0
10/02/2007  0
11/02/2007  0
12/02/2007  1
13/02/2007  1
14/02/2007  1
15/02/2007  0
16/02/2007  0

What I need to do is for each signal *in reverse chronological order* to
find the date that it first appeared. So, for the zero on 16/02/2007 and
15/02/2007, the 'inception' date would be 15/02/2007, because the day
before, the signal was 1. Likewise, the 'inception' date for the signal 1
on
08/02/2007 and the five days prior, would be 03/02/2007. I need to create
a
structure of inception dates that would finally look as follows:

-1  31/01/2007
-1  31/01/2007
-1  31/01/2007
1   03/02/2007
1   03/02/2007
1   03/02/2007
1   03/02/2007
1   03/02/2007
1   03/02/2007
0   09/02/2007
0   09/02/2007
0   09/02/2007
1   12/02/2007
1   12/02/2007
1   12/02/2007
0   15/02/2007
0   15/02/2007

Is there a clever way of doing this? My sadly C-oriented upbringing can
only
think in terms of for-loops.

Thanks!

Murali

_
The average US Credit Score is 675. The cost to see yours: $0 by Experian.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

_

fast as 1 year

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array searches

2007-02-16 Thread Murali Menon
Folks,

I have a dataframe comprising a column of dates and a column of signals (-1, 
0, 1) that looks something like this:

30/01/2007  0
31/01/2007  -1
01/02/2007  -1
02/02/2007  -1
03/02/2007  1
04/02/2007  1
05/02/2007  1
06/02/2007  1
07/02/2007  1
08/02/2007  1
09/02/2007  0
10/02/2007  0
11/02/2007  0
12/02/2007  1
13/02/2007  1
14/02/2007  1
15/02/2007  0
16/02/2007  0

What I need to do is for each signal *in reverse chronological order* to 
find the date that it first appeared. So, for the zero on 16/02/2007 and 
15/02/2007, the 'inception' date would be 15/02/2007, because the day 
before, the signal was 1. Likewise, the 'inception' date for the signal 1 on 
08/02/2007 and the five days prior, would be 03/02/2007. I need to create a 
structure of inception dates that would finally look as follows:

-1  31/01/2007
-1  31/01/2007
-1  31/01/2007
1   03/02/2007
1   03/02/2007
1   03/02/2007
1   03/02/2007
1   03/02/2007
1   03/02/2007
0   09/02/2007
0   09/02/2007
0   09/02/2007
1   12/02/2007
1   12/02/2007
1   12/02/2007
0   15/02/2007
0   15/02/2007

Is there a clever way of doing this? My sadly C-oriented upbringing can only 
think in terms of for-loops.

Thanks!

Murali

_
The average US Credit Score is 675. The cost to see yours: $0 by Experian.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array searches

2007-02-16 Thread jim holtman
try this:

 x - scan(textConnection(30/01/2007  0
+ 31/01/2007  -1
+ 01/02/2007  -1
+ 02/02/2007  -1
+ 03/02/2007  1
+ 04/02/2007  1
+ 05/02/2007  1
+ 06/02/2007  1
+ 07/02/2007  1
+ 08/02/2007  1
+ 09/02/2007  0
+ 10/02/2007  0
+ 11/02/2007  0
+ 12/02/2007  1
+ 13/02/2007  1
+ 14/02/2007  1
+ 15/02/2007  0
+ 16/02/2007  0
+ ), what=list(date=, value=0))
Read 18 records
 x$date - as.Date(x$date, %d/%m/%Y)
 # determine the breaks
 x.breaks - c(TRUE, diff(x$value) != 0)
 # determine the value at the break; assume that it is the minimum
 x.bdate - x$date[x.breaks]
 data.frame(date=x.bdate[cumsum(x.breaks)], value=x$value)
 date value
1  2007-01-30 0
2  2007-01-31-1
3  2007-01-31-1
4  2007-01-31-1
5  2007-02-03 1
6  2007-02-03 1
7  2007-02-03 1
8  2007-02-03 1
9  2007-02-03 1
10 2007-02-03 1
11 2007-02-09 0
12 2007-02-09 0
13 2007-02-09 0
14 2007-02-12 1
15 2007-02-12 1
16 2007-02-12 1
17 2007-02-15 0
18 2007-02-15 0






On 2/16/07, Murali Menon [EMAIL PROTECTED] wrote:

 Folks,

 I have a dataframe comprising a column of dates and a column of signals
 (-1,
 0, 1) that looks something like this:

 30/01/2007  0
 31/01/2007  -1
 01/02/2007  -1
 02/02/2007  -1
 03/02/2007  1
 04/02/2007  1
 05/02/2007  1
 06/02/2007  1
 07/02/2007  1
 08/02/2007  1
 09/02/2007  0
 10/02/2007  0
 11/02/2007  0
 12/02/2007  1
 13/02/2007  1
 14/02/2007  1
 15/02/2007  0
 16/02/2007  0

 What I need to do is for each signal *in reverse chronological order* to
 find the date that it first appeared. So, for the zero on 16/02/2007 and
 15/02/2007, the 'inception' date would be 15/02/2007, because the day
 before, the signal was 1. Likewise, the 'inception' date for the signal 1
 on
 08/02/2007 and the five days prior, would be 03/02/2007. I need to create
 a
 structure of inception dates that would finally look as follows:

 -1  31/01/2007
 -1  31/01/2007
 -1  31/01/2007
 1   03/02/2007
 1   03/02/2007
 1   03/02/2007
 1   03/02/2007
 1   03/02/2007
 1   03/02/2007
 0   09/02/2007
 0   09/02/2007
 0   09/02/2007
 1   12/02/2007
 1   12/02/2007
 1   12/02/2007
 0   15/02/2007
 0   15/02/2007

 Is there a clever way of doing this? My sadly C-oriented upbringing can
 only
 think in terms of for-loops.

 Thanks!

 Murali

 _
 The average US Credit Score is 675. The cost to see yours: $0 by Experian.

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array vs matrix vs dataframe?

2006-10-01 Thread Duncan Murdoch
On 10/1/2006 7:02 PM, r user wrote:
 What is the difference among an array, a dataframe and
 a matrix?

Really, r, I think this is pretty well documented.  Could you let us 
know what you've read that left this ambiguous?

 
 Why is the size of a dataframe so much larger? (see
 example below)

I suspect it's the row names.

Duncan Murdoch

 
 a-c(rep(1:100,1))
 b-c(rep(1:100,1))
 c1-cbind(a,b)
 cdf-as.data.frame(cbind(a,b))
 cm-as.matrix(cbind(a,b))
 
 object.size(a)/100
 object.size(b)/100
 object.size(c1)/100
 object.size(cdf)/100
 object.size(cm)/100
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] array vs matrix vs dataframe?

2006-10-01 Thread Duncan Murdoch
On 10/1/2006 7:02 PM, r user wrote:
 What is the difference among an array, a dataframe and
 a matrix?
 
 Why is the size of a dataframe so much larger? (see
 example below)

I forgot to mention:  there will be very little difference in 2.4+; the 
row names were a problem in earlier releases, but Brian Ripley fixed that:

  a-c(rep(1:100,1))
  b-c(rep(1:100,1))
  c1-cbind(a,b)
  cdf-as.data.frame(cbind(a,b))
  cm-as.matrix(cbind(a,b))
 
  object.size(a)/100
[1] 4.24
  object.size(b)/100
[1] 4.24
  object.size(c1)/100
[1] 8.000296
  object.size(cdf)/100
[1] 8.000448
  object.size(cm)/100
[1] 8.000296

(These are in a recent release candidate of 2.4.0.)

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Array

2006-06-15 Thread stat stat
Dear all R users,
   
  I am wondering if there is any way to define a 3 dimentional or 4 dimentional 
array in R.
   
  Sincerely yours,
   


thanks in advance
 Send instant messages to your online friends http://in.messenger.yahoo.com 

 Stay connected with your friends even when away from PC.  Link: 
http://in.mobile.yahoo.com/new/messenger/  
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Array

2006-06-15 Thread Petr Pikal
Hi

see ?array if you are interested

array(0, c(5,5,5,5,5))

gives you 5 dimensional array.

HTH
Petr


On 15 Jun 2006 at 15:34, stat stat wrote:

Date sent:  Thu, 15 Jun 2006 15:34:29 +0100 (BST)
From:   stat stat [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Subject:[R] Array

 Dear all R users,
 
   I am wondering if there is any way to define a 3 dimentional or 4
   dimentional array in R.
 
   Sincerely yours,
 
 
 
 thanks in advance
  Send instant messages to your online friends
  http://in.messenger.yahoo.com 
 
  Stay connected with your friends even when away from PC.  Link:
  http://in.mobile.yahoo.com/new/messenger/  [[alternative HTML version
  deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html

Petr Pikal
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] what are the limits on R array sizes?

2006-02-08 Thread Mike Miller
I have some computers with a massive amount of memory, and I have some 
jobs that could use very large matrix sizes.  Can R handle matrices of 
larger than 2GB?  If I were to create a matrix of 1,000,000 x 1,000, it 
would use about 8GB.  Can R work with an array of that size if I have 
compiled R on an IA64 Linux system with 15GB of RAM?

Mike

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] what are the limits on R array sizes?

2006-02-08 Thread Prof Brian Ripley
On Wed, 8 Feb 2006, Mike Miller wrote:

 I have some computers with a massive amount of memory, and I have some
 jobs that could use very large matrix sizes.  Can R handle matrices of
 larger than 2GB?  If I were to create a matrix of 1,000,000 x 1,000, it
 would use about 8GB.  Can R work with an array of that size if I have
 compiled R on an IA64 Linux system with 15GB of RAM?

Yes. See ?Memory-limits.

help.search(limits) gets you there.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Converting a Perl Array of Arrayrefs to an R array or matrix using RS Perl

2006-01-18 Thread Aaron Day
Dear R/RS-Perl users,

I have a perl script in which I parse a large number of files and 
construct an array of arrayrefs from the data in the files.  I then 
pass that construct to R using the RS Perl interface.  I want to be 
able to use the construct as an R array or matrix so that I can use the 
R function colSums.

So far, I've tried constructing an R matrix with dummy values, and then 
populating each row of the new matrix with the nested Arrays of the 
passed construct. But that just converts the R matrix to type list, so 
I get an error when I try the function colSums.  I then tried 
converting each nested Array using as.numeric() before putting the 
values into the matrix.  But for some reason as.numeric doesn't convert 
the nested arrays to numeric, so I still get an error when I try 
colSums.  If I check the values (say matrix[1][1]) the correct values 
are in the correct locations, but it still won't perform colSums.

I've been hammering away on this for longer than I would like to admit. 
  Any help you could provide would be greatly appreciated.

Best regards,

Aaron

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array question

2006-01-17 Thread Chang Shen
Hi all,

I want to create an array of datetime.

If I have a datetime object dt

dt - strptime(10Jan2006 00:00:15, %d%b%Y %H:%M:%S)
dt
[1]2006-01-10 00:00:15

I want to make an array of dt, say 100 size.  I got those error.

[1] 2006-01-10 00:00:15
 dtarray-array(dt, dim=c(100));
Error in array(dt, dim = c(100)) : dim- : dims [product 100] do not match
the length of object [9]


 dtarray-array(, dim=c(100));
 dtarray[1]-dt;
Warning message:
number of items to replace is not a multiple of replacement length



Any help?

Thanks

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] array question

2006-01-17 Thread Prof Brian Ripley
Please use POSIXct and not POSIXlt objects, which are lists.

On Tue, 17 Jan 2006, Chang Shen wrote:

 Hi all,

 I want to create an array of datetime.

 If I have a datetime object dt

 dt - strptime(10Jan2006 00:00:15, %d%b%Y %H:%M:%S)
 dt
 [1]2006-01-10 00:00:15

 I want to make an array of dt, say 100 size.  I got those error.

 [1] 2006-01-10 00:00:15
 dtarray-array(dt, dim=c(100));
 Error in array(dt, dim = c(100)) : dim- : dims [product 100] do not match
 the length of object [9]


 dtarray-array(, dim=c(100));
 dtarray[1]-dt;
 Warning message:
 number of items to replace is not a multiple of replacement length



 Any help?

 Thanks

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array of lists? is this the best way to do it?

2005-12-06 Thread John McHenry
[Q.] How to create an array of lists, or structures the most elegant way? 
   
  There have been questions in the past but none too recently...I want to know 
if the following looks OK to you guys or if there is a better way to create an 
array of lists:
   
   # PREAMBLE ... JUST TO GET THINGS GOING
 makeList- function(data, anythingElse) {
  rval - list( data = data,   
anythingElse = anythingElse 
   )
  class(rval) - myListOfArbitraryThings
  return(rval)
 }
 # make up some arbitrary data
 payload- list( as.matrix(cbind(1,1:3)), 
   10:15, 
   data.frame(cbind(x=1, y=1:10), fac=sample(LETTERS[1:3], 10, repl=TRUE))
)
   
   # HERE'S THE ARRAY-CONSTRUCTION PART THAT I WANT CRITIQUED:
 n- 3 # number of lists in the array of lists
 v- vector(list, n) # --- IS THIS THE BEST WAY TO CREATE AN ARRAY OF LISTS?
 # fill the array with essentially arbitrary stuff:
 for (i in 1:n) v[[i]]- makeList(payload[[i]], i)
   
   
  Thanks,
   
  Jack.
  
 


-


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] array of lists? is this the best way to do it?

2005-12-06 Thread Gabor Grothendieck
On 12/6/05, John McHenry [EMAIL PROTECTED] wrote:
 [Q.] How to create an array of lists, or structures the most elegant way?

  There have been questions in the past but none too recently...I want to know 
 if the following looks OK to you guys or if there is a better way to create 
 an array of lists:

   # PREAMBLE ... JUST TO GET THINGS GOING
  makeList- function(data, anythingElse) {
  rval - list( data = data,
anythingElse = anythingElse
   )
  class(rval) - myListOfArbitraryThings
  return(rval)
  }
  # make up some arbitrary data
  payload- list( as.matrix(cbind(1,1:3)),
   10:15,
   data.frame(cbind(x=1, y=1:10), fac=sample(LETTERS[1:3], 10, repl=TRUE))
)

   # HERE'S THE ARRAY-CONSTRUCTION PART THAT I WANT CRITIQUED:
  n- 3 # number of lists in the array of lists
  v- vector(list, n) # --- IS THIS THE BEST WAY TO CREATE AN ARRAY OF 
 LISTS?
  # fill the array with essentially arbitrary stuff:
  for (i in 1:n) v[[i]]- makeList(payload[[i]], i)

You could use lapply to avoid having to set up the empty list:

lapply(1:n, function(i) makeList(payload[[i]], i))  # untested

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Array reversed

2005-12-01 Thread Julio Thomas
Dear R-helper,
   
  Is there a command to get an array indexed 1 to T from T to 1?
   
  For example:
   
  a - c(1, 2, 3)
   
  and by applying such a command I can get
   
  a[1] = 3
  a[2] = 2
  a[3] = 1 
   
  Thanks a lot and best regards
  Julio


-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Array reversed

2005-12-01 Thread Berton Gunter
Please use R's existing help system before posting to the list.

help.search('reverse') is an obvious first thing to try, don't you think
(and gives you the almost obvious answer immediately)?

-- Bert Gunter
Genentech 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Julio Thomas
Sent: Thursday, December 01, 2005 8:44 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Array reversed

Dear R-helper,
   
  Is there a command to get an array indexed 1 to T from T to 1?
   
  For example:
   
  a - c(1, 2, 3)
   
  and by applying such a command I can get
   
  a[1] = 3
  a[2] = 2
  a[3] = 1 
   
  Thanks a lot and best regards
  Julio


-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array indices in synced vectors

2005-09-08 Thread Erich Neuwirth
Let us start with the following definitions

xxx-rep(c(1,2),times=5)
yyy-rep(c(1,2),each=5)
a-c(11,12)
b-matrix(1:4,2,2)

a[xxx] produces
[1] 11 12 11 12 11 12 11 12 11 12

b[xxx,yyy] produces
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]111113333 3
 [2,]222224444 4
 [3,]111113333 3
 [4,]222224444 4
 [5,]111113333 3
 [6,]222224444 4
 [7,]111113333 3
 [8,]222224444 4
 [9,]111113333 3
[10,]222224444 4

so it does an implicit outer for the indices in xxx and yyy.

sapply(1:length(xxx),function(x)b[xxx[x],yyy[x]])
does what I need and produces
 [1] 1 2 1 2 1 4 3 4 3 4

Is there a function taking xxx,yyy, and b as arguments
producing the same result?

Essentially, I am asking for a version of lapply and/or sapply
which works with functions of more than one argument and takes the
iteration arguments as vectors or lists of equal length.




-- 
Erich Neuwirth, Didactic Center for Computer Science
University of Vienna
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39902 Fax: +43-1-4277-9399

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] array indices in synced vectors

2005-09-08 Thread Thomas Lumley
On Thu, 8 Sep 2005, Erich Neuwirth wrote:

 sapply(1:length(xxx),function(x)b[xxx[x],yyy[x]])
 does what I need and produces
 [1] 1 2 1 2 1 4 3 4 3 4

 Is there a function taking xxx,yyy, and b as arguments
 producing the same result?

b[cbind(xxx,yyy)]

 Essentially, I am asking for a version of lapply and/or sapply
 which works with functions of more than one argument and takes the
 iteration arguments as vectors or lists of equal length.

More generally there is mapply(), but the matrix subscript solution is 
better in this example
 mapply(function(i,j) b[i,j], xxx,yyy)
  [1] 1 2 1 2 1 4 3 4 3 4

-thomas

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array indexing and which

2005-04-17 Thread Werner Wernersen
Hi R friends!

I am stuck with a stupid question: I can circumvent it
but I would like to 
understand why it is wrong. It would be nice if you
could give me a hint...

I have an 2D array d and do the following:
ids - which(d[,1]0)

then I have a vector gk with same column size as d and
do:
ids2 - which(gk[ids]==1)

but I can't interprete the result I get in ids2.

I get the expected result when I use:
which(gk==1  d[,1]0)

Why is the first version wrong?

The reason why I try to use the ids vectors is that I
want to avoid recomputation.

Thanks for your help!
   Werner

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] array indexing and which

2005-04-17 Thread Marc Schwartz
On Sun, 2005-04-17 at 19:13 +0200, Werner Wernersen wrote:
 Hi R friends!
 
 I am stuck with a stupid question: I can circumvent it
 but I would like to 
 understand why it is wrong. It would be nice if you
 could give me a hint...

Having a reproducible example, as per the posting guide, would be
helpful here. We'll use a contrived example that hopefully explains what
I can only presume you are seeing.

 I have an 2D array d and do the following:
 ids - which(d[,1]0)

Here ids contains the indices of the values in the vector d[, 1] that
are  0.

For example:

 d - matrix(sample(0:1, 12, replace = TRUE), ncol = 2)
 d
 [,1] [,2]
[1,]11
[2,]11
[3,]01
[4,]00
[5,]01
[6,]10

 ids - which(d[, 1]  0)
 ids
[1] 1 2 6

Note that c(1, 2, 6) are the indices into the vector:

 d[, 1]
[1] 1 1 0 0 0 1

of the values that are  0.

 then I have a vector gk with same column size as d and
 do:
 ids2 - which(gk[ids]==1)

Here ids2 contains the indices of the values in gk[ids] that equal 1.

 gk - sample(0:1, 6, replace = TRUE)
 gk
[1] 1 1 1 0 1 1


 gk[ids]  # same as gk[c(1, 2, 6)]
[1] 1 1 1

 ids2 - which(gk[ids] == 1)
 ids2
[1] 1 2 3

All three of the values in gk[ids] == 1.

 but I can't interprete the result I get in ids2.
 
 I get the expected result when I use:
 which(gk==1  d[,1]0)

Here you are getting the result of logically comparing the two vectors:

 gk == 1
[1]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE

AND

 d[, 1]  0
[1]  TRUE  TRUE FALSE FALSE FALSE  TRUE


where the result of the comparison is the index value of each pair in
the two vectors where both values are TRUE.

Thus:

 which(gk == 1  d[, 1]  0)
[1] 1 2 6

versus:

 ids2
[1] 1 2 3

 Why is the first version wrong?

It's not wrong. It is giving you what you asked for.

Your question was wrong.  :-)

 The reason why I try to use the ids vectors is that I
 want to avoid recomputation.
 
 Thanks for your help!
Werner

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] array indexing and which

2005-04-17 Thread Bill.Venables
You need to think about it just a bit harder.

[Hint: what happens if you leave out the first 'which' and just make

ids - (d[, 1]  0)

does it work then...?]

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Werner Wernersen
Sent: Monday, 18 April 2005 3:13 AM
To: r-help@stat.math.ethz.ch
Subject: [R] array indexing and which


Hi R friends!

I am stuck with a stupid question: I can circumvent it
but I would like to 
understand why it is wrong. It would be nice if you
could give me a hint...

I have an 2D array d and do the following:
ids - which(d[,1]0)

then I have a vector gk with same column size as d and
do:
ids2 - which(gk[ids]==1)

but I can't interprete the result I get in ids2.

I get the expected result when I use:
which(gk==1  d[,1]0)

Why is the first version wrong?

The reason why I try to use the ids vectors is that I
want to avoid recomputation.

Thanks for your help!
   Werner

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Array Manipulation

2005-01-27 Thread cdsmith
I have a data set that looks like the following:
ID  Responce
1   57
1   63
1   49
2   31
2   45
2   67
2   91
3   56
3   43
4   23
4   51
4   61
4   76
4   68
5   34
5   35
5   45
I used sample(unique(ID)) to select a sample if ID's, say, (1,4,5).  Now
I want to pull out the rows with ID's 1, 4, and 5.  I've tried forceing
the matrix into a vector but it does not create and appropriate vector.
 I've also tried the if statment but it didn't work right either.  Any
suggestions?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] Array Manipulation

2005-01-27 Thread Liaw, Andy
Something like:

dat[dat$ID %in% sample(unique(dat$ID), 3), ]

Andy

 From: [EMAIL PROTECTED]
 
 I have a data set that looks like the following:
 ID  Responce
 1   57
 1   63
 1   49
 2   31
 2   45
 2   67
 2   91
 3   56
 3   43
 4   23
 4   51
 4   61
 4   76
 4   68
 5   34
 5   35
 5   45
 I used sample(unique(ID)) to select a sample if ID's, say, 
 (1,4,5).  Now
 I want to pull out the rows with ID's 1, 4, and 5.  I've 
 tried forceing
 the matrix into a vector but it does not create and 
 appropriate vector.
  I've also tried the if statment but it didn't work right either.  Any
 suggestions?
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Array Manipulation

2005-01-27 Thread Douglas Bates
Liaw, Andy wrote:
Something like:
dat[dat$ID %in% sample(unique(dat$ID), 3), ]
or
subset(dat, ID %in% sample(unique(ID), 3))
which I find to be more readable.
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Array Manipulation

2005-01-27 Thread Eric Rodriguez
and something like that:

dat[dat$ID == sample(unique(dat$ID), 3), 2]   ?

I'm not sure about the ,2 maybe you need the full matrix ?


ps: first time, i forgot the list

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] array problem and for looping

2004-10-29 Thread Petr Pikal
Hi

Beter not to give a same name your values (variables) as is 
function name. R is quite clever and

sample - rnorm(10)
sample - sample(sample,3)

works as expected, but it is not a rule.

Cheers
Petr

On 28 Oct 2004 at 17:54, Kunal Shetty wrote:

 Dear R- users and Helpers
 
 Is there some way to re initialise or clear the array elements? 
 Pardon me for being vague but the problem itself quite vague. I have
 attached the code along with email. When I run the saved r- code using
 source(random1.txt) , command.
 
 The program runs fine..but at times there is an error see below # ; 
 but again after the error if re-excuted it would work fine?I  probably
 missed some array detail in my program any suggestions
 
 #Error in var(parrX[1, ]) : missing observations in cov/cor
 
 parrX[] is an array .
 
  2) Also pardon me for the lengthy procedural code
 but as you could see in it..i have used the for loop for
 finding the positions (indexes) of the missing values and
 later carry out updating the new array element values at those
 particular positions/
  So how can I escape the for loop in this case ?  i.e get the
  missing position indexes and save another object ay vector or
  array ?
 
 And also later wanted to use matrix or vector multiplication
 (%*%)  for the updating statement
 newy[i]- u2 + covXY/varX * (sample$x[i] - u1)
 
  is any of the apply function good out here ?
 
   I really feel that I am doing something very routine and donkey work
   and I am most certain that powerful R ? functions could just execute
   the same 10 liner for loop condition to mere 4 lines ? but how?I am
   getting lost in the sea of functions here?
 
 Thank u for reading
 Regards
 Kunal
 

Petr Pikal
[EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array problem and for looping

2004-10-28 Thread Kunal Shetty
Dear R- users and Helpers

Is there some way to re initialise or clear the array elements?  Pardon me for being 
vague but the problem itself quite vague. I have attached the code along with email. 
When I run the saved r- code using source(random1.txt) , command.

The program runs fine..but at times there is an error see below # ;  but again after 
the error if re-excuted it would work fine…I  probably missed some array detail in my 
program any suggestions

#Error in var(parrX[1, ]) : missing observations in cov/cor

parrX[] is an array .

 2) Also pardon me for the lengthy procedural code
but as you could see in it..i have used the for loop for finding the positions 
(indexes) of the missing values and later carry out updating the new array element 
values at those particular positions/
 So how can I escape the for loop in this case ?  i.e get the missing position 
indexes and save another object ay vector or array ?

And also later wanted to use matrix or vector multiplication (%*%)  for the 
updating statement
newy[i]- u2 + covXY/varX * (sample$x[i] - u1)

 is any of the apply function good out here ?

  I really feel that I am doing something very routine and donkey work and I am most 
certain that powerful R – functions could just execute the same 10 liner for loop 
condition to mere 4 lines ? but how…I am getting lost in the sea of functions here…

Thank u for reading
Regards
Kunal

# creation for random data set
x - rnorm(100,17,24)
y - rnorm(100,7,11)
A - matrix(c(10,25,8,40),nrow=2,ncol=2)

z - rbind(x, y) # now 2 x 100
w - A %*% z # 2 x 100

x - w[1,]
y - w[2,]


 print(meanX  meanY   varX   varY   covar) 


 # mean of the variates

 u1 - mean(x)
 u2 - mean(y)
  
 # Variances of the variates
 varX - var(x)
 varY - var(y)
 
 # coVariances of the variates
 covXY - cov(x,y)
 

 # printing mean , var , covar


 print(c(u1,u2,varX,varY,covXY))



# now replace randomly with NA
x[sample(1:length(x), 10)] - NA
y[sample(1:length(y), 10)] - NA

# just a variable
sample - data.frame(x=x,y=y)


# Vector for missing values
missing - is.na(sample$x) | is.na(sample$y)
xNA - array(sample$x[missing], dim=c(1,length(sample$x[missing])))
yNA - array(sample$y[missing], dim=c(1,length(sample$y[missing])))


# find the  mean of the non missing values in the array

mX - mean(sample$x,na.rm=TRUE)
mY - mean(sample$y,na.rm=TRUE)


# Imputing the missing values with current estimated means

 x-array(ifelse(is.na(sample$x), mX, sample$x),dim=c(1,length(sample$x)))
 y-array(ifelse(is.na(sample$y), mY, sample$y),dim=c(1,length(sample$y)))


 print(  meanX  meanY   varX   varY   covar) 

# algorithm function to find out new estimate values

algoResult - function(parrX,parrY,parrXNA,parrYNA,ictr) {

# Variables for New X and Y
newx - array(parrX, dim=c(1,length(parrX)))
newy - array(parrY, dim=c(1,length(parrY)))

 # mean of the variates

 u1 - mean(parrX)
 u2 - mean(parrY)
  
 # Variances of the variates
 varX - var(parrX[1,])
 varY - var(parrY[1,])
 
 # coVariances of the variates
 covXY - cov(parrX[1,],parrY[1,])
 

 # printing mean , var , covar


 print(c(u1,u2,varX,varY,covXY))


  # Expected or updated values for the missing values 

   
  # loop for finding positon of missing vectors
  for (i in 1:length(missing)) {


 if (missing[i]==TRUE) 


{
  
 if (is.na(sample$x[i]== TRUE))
  {
newx[i] - u1 + covXY/varY * (sample$y[i] -u2)

  } 
 if (is.na(sample$y[i]== TRUE))
  {

newy[i]- u2 + covXY/varX * (sample$x[i] - u1)

 
  } 

}
 }

l - list(c(newx),c(newy)) 
names(l)-c(X1,Y1); as.data.frame(l)  
return(l)  

   }


# the iteration loop to do the algorithm
for (ctr in 1:50) {

   Output - algoResult(x,y,xNA,yNA,ctr); Output

   x - array(Output$X1, dim=c(1,length(Output$X1)))
   y - array(Output$Y1, dim=c(1,length(Output$Y1)))


   }



















__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

RE: [R] array problem and for looping

2004-10-28 Thread Huntsinger, Reid
First, the condition 

  if (is.na(sample$x[i]== TRUE))

asks if sample$x[i] is equal to TRUE, and then checks whether the result of
this comparison is NA. Because the comparison returns NA when one or the
other argument is NA, this works, but note that it would work as well with
FALSE in place of TRUE. I suppose you meant to say if (is.na(sample$x[i]) ==
TRUE) which is the same as if(is.na(sample$x[i])). 

Second, your code could generate data with *both* x and y missing
simultaneously. That would produce missing results in your regression
imputation. You probably want to check for these and drop them or otherwise
handle them.

Third, you might gain some insight by running your function algoResult on
known data, and examining the results. The missing values have to come from
somewhere, but because you run the entire script which generates random data
each time you never get this check. 

Fourth, you function doesn't use its last 3 arguments, but does use the
dataframe sample and the vector missing. As these are not passed as
arguments, they are searched for in the enclosing environment. Do you want
that? 

Fifth, yes, you don't need the loop. Just use subscripting for example, as
you did to insert NAs randomly, or ifelse as you used to impute by means. 

Reid Huntsinger
 
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Kunal Shetty
Sent: Thursday, October 28, 2004 1:55 PM
To: [EMAIL PROTECTED]
Subject: [R] array problem and for looping


Dear R- users and Helpers



Is there some way to re initialise or clear the array elements?  Pardon me
for being vague but the problem itself quite vague. I have attached the code
along with email. 

When I run the saved r- code using source(random1.txt) , command.



The program runs fine..but at times there is an error see below # ;  but
again after the error if re-excuted it would work fine...I  probably missed
some array detail in my program any suggestions



#Error in var(parrX[1, ]) : missing observations in cov/cor



parrX[] is an array .



 2) Also pardon me for the lengthy procedural code

but as you could see in it..i have used the for loop for finding the
positions (indexes) of the missing values and later carry out updating the
new array element values at those particular positions/

 So how can I escape the for loop in this case ?  i.e get the
missing position indexes and save another object ay vector or array ?



And also later wanted to use matrix or vector multiplication (%*%)
for the updating statement

newy[i]- u2 + covXY/varX * (sample$x[i] - u1)



 is any of the apply function good out here ?



  I really feel that I am doing something very routine and donkey work and I
am most certain that powerful R - functions could just execute the same 10
liner for loop condition to mere 4 lines ? but how...I am getting lost in
the sea of functions here...



Thank u for reading

Regards

Kunal

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array construction

2004-09-28 Thread Poizot Emmanuel
Hi all,

I've got a file of the following format:

X  Y  Z  u  v  w
0  0  0  x  x  x
0  0  1  x  x  x
0  0  2  x  x  x
..  ..  ..  ..  ..  ..
0  1  0  x  x  x
0  1  1  x  x  x
0  1  2  x  x  x
..  ..  ..  ..  ..  ..
1  0  0  x  x  x
1  0  1  x  x  x
1  0  2  x  x  x
 etc

x stand for decimal values
X coordinate is 3h, Y and Z are h length.
I read that file with:
data - read.table(filename, fill=T)
I extract coordinates with:
coord - data[1:length,1:3]with length the number of lines of the file
I get the x values with:
values-data[1:length,4:6]

I would like now to create an 3D array storing the values on the correct 
order:
uvw - array(data[1:length],dim=c(3h,h,h))   with h predifened of course

Is that command correct ?

-- 
Cordialement
~~~
Emmanuel Poizot
Cnam/Intechmer
B.P. 324
50103 Cherbourg Cedex
Tél: (33)(0)233887342
Fax: (33)(0)233887339
~~~

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] array addition doesn't recycle!

2004-04-01 Thread Robin Hankin
At 01:39 pm -0500 31/03/04, Raubertas, Richard wrote:
Another alternative is to use the underappreciated function
'sweep()':
sweep(A, 1:2, a, +)

I find the following helpful (it's not due to me but I cannot find 
the original poster):


 %.+% - function(a,x){sweep(a , 2:1 , x ,+ )}
 %+.% - function(a,x){sweep(a , 1:2 , x ,+ )}

 A - matrix(1:16,4,4)
 x - 10^(0:3)

 A %+.% x
 [,1] [,2] [,3] [,4]
[1,]26   10   14
[2,]   12   16   20   24
[3,]  103  107  111  115
[4,] 1004 1008 1012 1016
 A %.+% x
 [,1] [,2] [,3] [,4]
[1,]2   15  109 1013
[2,]3   16  110 1014
[3,]4   17  111 1015
[4,]5   18  112 1016



For 3d arrays this generalizes to

 %+..% - function(a,x){sweep(a , 1 , x ,+ )}
 %.+.% - function(a,x){sweep(a , 2 , x ,+ )}
 %..+% - function(a,x){sweep(a , 3 , x ,+ )}
Then if A - array(1:8,rep(2,3)) and x - c(10,100)

A %+..% x et seq give you a consistent method for addition.

--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
[EMAIL PROTECTED] (edit in obvious way; spam precaution)
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array addition doesn't recycle!

2004-03-31 Thread Tamas Papp
Hi,

I have noticed the following:

 a - array(1:4, c(2, 2))
 A - array(1:4, c(2,2,2))
 A + a
Error in A + a : non-conformable arrays

It works with a matrix + a vector, why doesn't it work with arrays?
Am I missing something?

How would you do the above operation efficiently (ie I need to add a
matrix to each plane of 3-dim array)?  At the moment I am using
something like

A + array(a, c(2,2,2))

but it doesn't seem that efficient.

Thanks

Tamas

-- 
Tamás K. Papp
E-mail: [EMAIL PROTECTED] (preferred, especially for large messages)
[EMAIL PROTECTED]
Please try to send only (latin-2) plain text, not HTML or other garbage.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] array addition doesn't recycle!

2004-03-31 Thread Raubertas, Richard
Another alternative is to use the underappreciated function 
'sweep()':

sweep(A, 1:2, a, +)

Internally this is about the same as your 'A + array(a, c(2,2,2))'.
But it has the advantage that it makes explicit what the 
relationship between the dimensions of 'A' and 'a' is.  I find 
that relying on implicit recycling tends to produce errors that
are hard to trace, and code that is hard to understand six months
later.

Rich Raubertas
Merck  Co.

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Prof 
 Brian Ripley
 Sent: Wednesday, March 31, 2004 10:00 AM
 To: Tamas Papp
 Cc: R-help mailing list
 Subject: Re: [R] array addition doesn't recycle!
 
 
 The recycling rules are documented and this is not amongst them.
 Computer packages do have a tendency to follow their rules 
 rather than 
 read your mind.
 
 I suspect A + as.vector(a) is what you intended.
 
 On Wed, 31 Mar 2004, Tamas Papp wrote:
 
  Hi,
  
  I have noticed the following:
  
   a - array(1:4, c(2, 2))
   A - array(1:4, c(2,2,2))
   A + a
  Error in A + a : non-conformable arrays
  
  It works with a matrix + a vector, why doesn't it work with arrays?
  Am I missing something?
  
  How would you do the above operation efficiently (ie I need to add a
  matrix to each plane of 3-dim array)?  At the moment I am using
  something like
  
  A + array(a, c(2,2,2))
  
  but it doesn't seem that efficient.
 
 Why do you think is `not that efficient'?  Does you have a 
 need to save 
 microseconds?
 
 -- 
 Brian D. Ripley,  [EMAIL PROTECTED]
 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
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! 
 http://www.R-project.org/posting-guide.html
 


__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array of variable length vectors

2004-02-02 Thread Giampiero Salvi
Hi,
I'd like to store N vectors of different lengths, and to be able to
access them with an index, and eventually free the memory for one
of them without modifying the indexes to the others.

In C this would be a vector of N pointers that point to memory cells
independently allocated.

For example

int *pv[3];

pv[0] = (int *) malloc(13 * sizeof(int));
pv[1] = (int *) malloc(7 * sizeof(int));
pv[2] = (int *) malloc(110 * sizeof(int));

free(pv[1])
...

What is the best data type (or class) in R to do such a thing?

Thank you!
Giampiero
_
Giampiero Salvi, M.Sc.  www.speech.kth.se/~giampi
Speech, Music and Hearing   Tel:  +46-8-790 75 62
Royal Institute of Technology   Fax:  +46-8-790 78 54
Drottning Kristinasv. 31,  SE-100 44,  Stockholm,  Sweden

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] array of variable length vectors

2004-02-02 Thread Barry Rowlingson
Giampiero Salvi wrote:
Hi,
I'd like to store N vectors of different lengths, and to be able to
access them with an index, and eventually free the memory for one
of them without modifying the indexes to the others.

int *pv[3];

pv[0] = (int *) malloc(13 * sizeof(int));
pv[1] = (int *) malloc(7 * sizeof(int));
pv[2] = (int *) malloc(110 * sizeof(int));
free(pv[1])
...
What is the best data type (or class) in R to do such a thing?
 A list, with vector elements (index starts at 1 in R):

 pv = list()
 pv[[1]] = real(13)
 pv[[2]] = real(7)
 pv[[3]] = real(110)
 then the equivalent of freeing the memory and keeping the indexing 
would be:

 pv[[2]] = real(0)

 and NOT

 pv[[2]] = NULL  (which deletes element 2)

 *BUT* I dont know if R will really free() the memory at that point. 
You may need to force the garbage collection with gc()

Baz

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] array of variable length vectors

2004-02-02 Thread Prof Brian Ripley
On Mon, 2 Feb 2004, Giampiero Salvi wrote:

 Hi,
 I'd like to store N vectors of different lengths, and to be able to
 access them with an index, and eventually free the memory for one
 of them without modifying the indexes to the others.
 
 In C this would be a vector of N pointers that point to memory cells
 independently allocated.
 
 For example
 
 int *pv[3];
 
 pv[0] = (int *) malloc(13 * sizeof(int));
 pv[1] = (int *) malloc(7 * sizeof(int));
 pv[2] = (int *) malloc(110 * sizeof(int));
 
 free(pv[1])
 ...
 
 What is the best data type (or class) in R to do such a thing?

Sounds like an R list.  However, in R you cannot free memory, but what 
you can do (carefully) is to change the list element to NULL and then 
memory will be salvaged at a future garbage collection.

z - vector(list, 3)
z[[1]] - integer(13)
z[[2]] - integer(7)
z[[3]] - integer(110)

then

z[1] - list(NULL)  # and not z[[1]] - NULL

will potentially release the memory allocated for the first element.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] array of variable length vectors

2004-02-02 Thread Uwe Ligges
Giampiero Salvi wrote:

Hi,
I'd like to store N vectors of different lengths, and to be able to
access them with an index, and eventually free the memory for one
of them without modifying the indexes to the others.
In C this would be a vector of N pointers that point to memory cells
independently allocated.
For example

int *pv[3];

pv[0] = (int *) malloc(13 * sizeof(int));
pv[1] = (int *) malloc(7 * sizeof(int));
pv[2] = (int *) malloc(110 * sizeof(int));
free(pv[1])
...
What is the best data type (or class) in R to do such a thing?
See ?list

Uwe Ligges

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array(list(),c(2,5)) gives error in R 1.8.1

2004-01-14 Thread Christoph Lehmann
Hi

In R 1.7 the following worked fine:

 array(list(),c(2,5))
 [,1] [,2] [,3] [,4] [,5]
[1,] NULL NULL NULL NULL NULL
[2,] NULL NULL NULL NULL NULL

now in R 1.8.1 I get the error:

Error in rep.int(data, t1) : invalid number of copies in rep
In addition: Warning message:
NAs introduced by coercion

thanks for help, I need this possibility for storing objects (lm
results) in an array

cheers

Christoph
-- 
Christoph Lehmann [EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] array(list(),c(2,5)) gives error in R 1.8.1

2004-01-14 Thread Tony Plate
I confirmed this -- array(list(), c(2,2)) works in R 1.6.2 and R 1.7.1, but 
not in R 1.8.0.  This appears to be due to a change in array(): rep(data, 
t1) was changed to rep.int(data, t1).  When data=list(), t1==Inf, and 
rep(data, t1) returns list(), while rep.int(data, t1) gives an 
error.  Here's a transcript from R 1.8.0:

 array
function (data = NA, dim = length(data), dimnames = NULL)
{
data - as.vector(data)
vl - prod(dim)
if (length(data) != vl) {
t1 - ceiling(vl/length(data))
data - rep.int(data, t1)
if (length(data) != vl)
data - data[1:vl]
}
if (length(dim))
dim(data) - dim
if (is.list(dimnames)  length(dimnames))
dimnames(data) - dimnames
data
}
environment: namespace:base
 rep(list(), Inf)
list()
 rep.int(list(), Inf)
Error in rep.int(list(), Inf) : invalid number of copies in rep
In addition: Warning message:
NAs introduced by coercion
 array(numeric(3), 0,0)
numeric(0)

There's also the dangerous construct data[1:v1] in array() 
(data[seq(len=v1)] would be much safer).  However, it appears that the 1:0 
trap doesn't occur under normal circumstances (because if v1=0, then t1 
will be either 0 or Inf, and length(rep.int(data, t1)) will be 0 or an 
error will have occurred (with most common data types at 
least).  However^2, given that functions in R don't always produce the 
results one might expect, it might be safer to change this to 
data[seq(len=v1)].

A workaround is to give array() a data value of the correct length:

 array(list()[1:4], c(2,2))
 [,1] [,2]
[1,] NULL NULL
[2,] NULL NULL

-- Tony Plate

At Wednesday 10:35 AM 1/14/2004 +0100, you wrote:
Hi

In R 1.7 the following worked fine:

 array(list(),c(2,5))
 [,1] [,2] [,3] [,4] [,5]
[1,] NULL NULL NULL NULL NULL
[2,] NULL NULL NULL NULL NULL
now in R 1.8.1 I get the error:

Error in rep.int(data, t1) : invalid number of copies in rep
In addition: Warning message:
NAs introduced by coercion
thanks for help, I need this possibility for storing objects (lm
results) in an array
cheers

Christoph
--
Christoph Lehmann [EMAIL PROTECTED]
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] array problem

2004-01-04 Thread Z P
Dear all,

I define , for n=5 or any integer greater than 0.

A-array((1/2)^n , c(rep(2,n)))

then for any i not equal to j, and 1=i,j=n,

B-apply(a,c(i,j),sum)

now B is a 2 by 2 matrix, I also define another costant 2 by 2 matrix G,

How can I change the values of each elements of array A, according the rule 
that,

for example, i=3,j=5,

A[i1,i2,m,i4,l]-A[i1,i2,m,i4,l]*G[m,l]/B[m,l]  , where m,l=1,2 and 
i1,i2,i4=1,2

I can control this given any i and j, however, I must do the iteration

for i in 1:(n-1) {
   for j in (i,n)
 {B-apply(a,c(i,j),sum)
  here change the value of every elements of A according to my rule
   }
}
Is there any easy way to change the value of A in the iteration? Thank you.

_
Find love on MSN Personals http://personals.msn.com.sg/
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] array problem

2004-01-04 Thread Gabor Grothendieck


Replace your line that updates A with this:

p - unique(c(i,j,1:5))
f - function(x) diag( matrix(x,4,4) )
AA - apply( outer(A,G/B), p[-(1:2)], f )   # form product
A - aperm( array( AA, dim(A) ), order(p) ) # reshape

Here are a couple of tests.  You might want to do some
more tests yourself as well since these are the only
ones I did:

 
 i - 3; j - 5
 G - 100 * matrix(1:4,2)
 B - 1+0*G  # all ones
 A - array(1:32,c(2,2,2,2,2))
 A2 - A
 A2[,,1,,1] - A2[,,1,,1] * G[1,1]
 A2[,,1,,2] - A2[,,1,,2] * G[1,2]
 A2[,,2,,1] - A2[,,2,,1] * G[2,1]
 A2[,,2,,2] - A2[,,2,,2] * G[2,2]
 
 test - function(A,i,j) {
+ p - unique(c(i,j,1:5))
+ f - function(x) diag( matrix(x,4,4) )
+ AA - apply( outer(A,G/B), p[-(1:2)], f )   # form product
+ A - aperm( array( AA, dim(A) ), order(p) ) # reshape
+ A
+ }
 
 identical(test(A,i,j),A2)
[1] TRUE
 
 
 i - 2; j - 4
 A3 - A
 A3[,1,,1,] - A3[,1,,1,] * G[1,1]
 A3[,1,,2,] - A3[,1,,2,] * G[1,2]
 A3[,2,,1,] - A3[,2,,1,] * G[2,1]
 A3[,2,,2,] - A3[,2,,2,] * G[2,2]
 
 identical(test(A,i,j),A3)
[1] TRUE
 




--- 
Date: Sun, 04 Jan 2004 21:42:55 +0800 
From: Z P [EMAIL PROTECTED]
To: [EMAIL PROTECTED] 
Subject: [R] array problem 

 
 
Dear all,

I define , for n=5 or any integer greater than 0.

A-array((1/2)^n , c(rep(2,n)))

then for any i not equal to j, and 1=i,j=n,

B-apply(a,c(i,j),sum)

now B is a 2 by 2 matrix, I also define another costant 2 by 2 matrix G,

How can I change the values of each elements of array A, according the rule 
that,

for example, i=3,j=5,

A[i1,i2,m,i4,l]-A[i1,i2,m,i4,l]*G[m,l]/B[m,l] , where m,l=1,2 and 
i1,i2,i4=1,2

I can control this given any i and j, however, I must do the iteration

for i in 1:(n-1) {
for j in (i,n)
{B-apply(a,c(i,j),sum)
here change the value of every elements of A according to my rule
}
}

Is there any easy way to change the value of A in the iteration? Thank you.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Array Dimension Names

2003-10-31 Thread Benjamin . STABLER
I would like to reference array dimensions by name in an apply and a summary
function.  For example:

apply(x, workers, sum)

Is there a better way to do this than creating a new attribute for the array
and then creating new methods for apply and summary?  I don't want to name
the individual elements of each dimension (such as with dimnames) but rather
name the dimensions.  Thanks for your help.

Benjamin Stabler
Transportation Planning Analysis Unit
Oregon Department of Transportation
555 13th Street NE, Suite 2
Salem, OR 97301  Ph: 503-986-4104

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Array Dimension Names

2003-10-31 Thread Ben Bolker

  Not that I know of.  BUT dimnames can themselves have names attributes, 
so a very small hack to apply() will do what you want.

I did 

dump(apply,file=apply.R)

and added the following lines after dn - dimnames(X) (line 14) [this is 
in R 1.7.1].

if (is.character(MARGIN)) {
  if (is.null(dn) stop(dimnames(X) must have names)
  MARGIN - match(MARGIN,names(dn))
}

and then did 

source(apply.R)
x = array(1,dim=c(2,2,2))
dimnames(x) = list(a=1:2,b=1:2,c=1:2)
apply(x,a,sum)
apply(x,c(a,b),sum)

On Fri, 31 Oct 2003 [EMAIL PROTECTED] wrote:

 I would like to reference array dimensions by name in an apply and a summary
 function.  For example:
 
 apply(x, workers, sum)
 
 Is there a better way to do this than creating a new attribute for the array
 and then creating new methods for apply and summary?  I don't want to name
 the individual elements of each dimension (such as with dimnames) but rather
 name the dimensions.  Thanks for your help.
 
 Benjamin Stabler
 Transportation Planning Analysis Unit
 Oregon Department of Transportation
 555 13th Street NE, Suite 2
 Salem, OR 97301  Ph: 503-986-4104
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 

-- 
620B Bartram Hall[EMAIL PROTECTED]
Zoology Department, University of Floridahttp://www.zoo.ufl.edu/bolker
Box 118525   (ph)  352-392-5697
Gainesville, FL 32611-8525   (fax) 352-392-3704

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Array Dimension Names

2003-10-31 Thread Benjamin . STABLER
Oh yeah, thanks.  I thought I might write a function such as getNames() that
returns the dimension number of the names of the dimnames of an object.
That way I don't have to rewrite apply, sweep, and aperm.  But even better
would be for R to allow character names in addition to index numbers for the
MARGIN argument to apply and sweep, and the perm argument to aperm.

Thanks again,
Ben Stabler

-Original Message-
From: Tony Plate [mailto:[EMAIL PROTECTED]
Sent: Friday, October 31, 2003 1:07 PM
To: STABLER Benjamin; [EMAIL PROTECTED]
Subject: Re: [R] Array Dimension Names


You can already name dimensions using standard arrays (but you 
can't use 
these names for the MARGIN argument of apply) e.g.:

  x - array(1:6, 3:2, 
dimnames=list(rows=letters[1:3],cols=LETTERS[24:25]))
  x
 cols
rows X Y
a 1 4
b 2 5
c 3 6
  apply(x, 2, sum)
  X  Y
  6 15
  apply(x, cols, sum)
Error in -MARGIN : Invalid argument to unary operator
 

You could pretty easily create your own version of apply() 
that checked if 
MARGIN was character, and if it were, matched it against 
names(dimnames(X))

hope this helps,

Tony Plate

At Friday 12:50 PM 10/31/2003 -0800, 
[EMAIL PROTECTED] wrote:
I would like to reference array dimensions by name in an 
apply and a summary
function.  For example:

apply(x, workers, sum)

Is there a better way to do this than creating a new 
attribute for the array
and then creating new methods for apply and summary?  I don't 
want to name
the individual elements of each dimension (such as with 
dimnames) but rather
name the dimensions.  Thanks for your help.

Benjamin Stabler
Transportation Planning Analysis Unit
Oregon Department of Transportation
555 13th Street NE, Suite 2
Salem, OR 97301  Ph: 503-986-4104

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Array Dimension Names

2003-10-31 Thread Gabor Grothendieck


You could add attributes to your array when creating it
and then retrieve them:

  x - matrix(1:8,2,4)
  attr(x,workers) - 1
  attr(x,variables) - 2

  apply(x,attr(x,variables),sum)

or perhaps:

  y - matrix(1:8,2,4)
  attr(y,margins) - list(workers = 1, variables = 2)

  apply(y,attr(y,margins)$variables,sum) 

These are simple enough that you might not need to develop your
own apply but you could pretty them up even more if you did:

  my.apply - function(x,dim,fn) apply(x,attr(x,dim),fn)

  my.apply(x,variables,sum)

---

From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED] 
Subject: [R] Array Dimension Names 

 
 
I would like to reference array dimensions by name in an apply and a summary
function. For example:

apply(x, workers, sum)

Is there a better way to do this than creating a new attribute for the array
and then creating new methods for apply and summary? I don't want to name
the individual elements of each dimension (such as with dimnames) but rather
name the dimensions. Thanks for your help.

Benjamin Stabler
Transportation Planning Analysis Unit
Oregon Department of Transportation
555 13th Street NE, Suite 2
Salem, OR 97301 Ph: 503-986-4104


___
No banners. No pop-ups. No kidding.
Introducing My Way - http://www.myway.com

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Array of 3D

2003-01-29 Thread Francisco do Nascimento Junior
Hi,

Can be created an Array of 3 dimensions in R? How?

Tks,
Francisco.

^^
Francisco Júnior,
Computer Science - UFPE-Brazil
One life has more value that the
world whole
^^

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help



RE: [R] Array of 3D

2003-01-29 Thread Winfried Theis
Hi,

try ?array.

So long, Winfried


On 29-Jan-03 Francisco do Nascimento Junior wrote:
 Hi,
 
 Can be created an Array of 3 dimensions in R? How?
 
 Tks,
 Francisco.
 
 ^^
 Francisco Júnior,
 Computer Science - UFPE-Brazil
 One life has more value that the
 world whole
 ^^
 
 __
 [EMAIL PROTECTED] mailing list
 http://www.stat.math.ethz.ch/mailman/listinfo/r-help

-
E-Mail: Winfried Theis [EMAIL PROTECTED]
Date: 29-Jan-03

Dipl.-Math. Winfried Theis
SFB 475, Fachbereich Statistik, Universitat Dortmund, 44221 Dortmund
Tel.: +49-231-755-5903 FAX: +49-231-755-4387
--

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help