Re: [R] question about matrix

2004-02-16 Thread Spencer Graves
outer(0:2, 1:2, "^")
[,1] [,2]
[1,]00
[2,]11
[3,]24
 Is this what you want? 

 spencer graves

Cynthia He wrote:

Hello there,

How to write this matrix in R?  The "^" sign is a power symbol.

Thanks a lot!

0^1   0^2  .  0^n 
1^1   1^2  .  1^n
2^1   2^2  .  2^n


q^1   q^2  .  q^n

-

	[[alternative HTML version deleted]]

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


Re: [R] question about matrix

2004-02-16 Thread Douglas Bates
Cynthia He <[EMAIL PROTECTED]> writes:

>  How to write this matrix in R?  The "^" sign is a power symbol.
>  
>  Thanks a lot!
>  
>  
>  0^1   0^2  .  0^n 
>  1^1   1^2  .  1^n
>  2^1   2^2  .  2^n
> 
> 
>  q^1   q^2  .  q^n

Use the outer product function, as in

> outer(0:5, 1:4, "^")
 [,1] [,2] [,3] [,4]
[1,]0000
[2,]1111
[3,]248   16
[4,]39   27   81
[5,]4   16   64  256
[6,]5   25  125  625

__
[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] question about matrix

2004-02-16 Thread Cynthia He
Hello there,
 
 How to write this matrix in R?  The "^" sign is a power symbol.
 
 Thanks a lot!
 
 
 0^1   0^2  .  0^n 
 1^1   1^2  .  1^n
 2^1   2^2  .  2^n


 q^1   q^2  .  q^n


-


[[alternative HTML version deleted]]

__
[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] question about matrix

2003-11-12 Thread Gabor Grothendieck


You could consider storing your data in 3d array.

If A and B are your matrices of first and second 
numbers, respectively, with both being of the same
shape, then:

   C <- array(c(A,B), dim=c(dim(A),2))

gives you a 3d array.  For example, 

   C[,,1] is A
   C[,,2] is B
   C[2,1,] is the the vector: c(A[2,1],B[2,1])

---
Date: Wed, 12 Nov 2003 11:41:17 -0600 (CST) 
From: Mikyoung Jun <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]> 
Subject: [R] question about matrix 

 
 
Hello,

I have a few questions about matrix in R. 

Can we make a matrix whose elements are list? I would like to save two
different values in each elements of matrix. If there is a package or
something which can deal with complex numbers, that will do it too. Also,
I am wondering whether there is a function to calculate the rank of the
matrix. I found a matrix package, but it doesn't have functions like that.

Thanks a lot in advance!

Mikyoung Jun

__
[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] question about matrix

2003-11-12 Thread Thomas W Blackwell
Mikyoung  -

All answers are "yes", but IMHO you are trying to be
too clever with your data structure.  Programming is
*much* easier if you keep things simple.

Specifically:

(1)  The function  matrix()  will happily build you
a matrix of type "list", with each element of the list
occupying one cell in the matrix.  For example,

tma <- matrix(as.list(letters), nrow=13, ncol=2)
is.list(tma)
[1] TRUE
is.matrix(tma)
[1] TRUE
tma[5,2]
[[1]]
[1] "r"

Same effect with

tma <- as.list(letters)
dim(tma) <- c(13,2)

(2)  Complex numbers - see  help("complex").  This
help page even gives an example which constructs a
matrix of complex numbers.

(3)  To find the rank of matrix  x,  qr(x)$rank.
I don't think there is a specific extractor function
for this component, but I could be wrong.

(4)  But, once again, I think you would be better served by
storing your two values of different types either as two
separate matrices, or as two columns in a data frame, with
additional columns of repetitive integers to indicate the
row and column in your conceptual matrix.

See  help("tapply"),  help("aggregate")  for two functions
which can operate on such a data structure, and  help("gl")
help("col"), help("row")  for functions that will generate
the additional columns.

HTH  -  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Wed, 12 Nov 2003, Mikyoung Jun wrote:

> Hello,
>
> I have a few questions about matrix in R.
>
> Can we make a matrix whose elements are list? I would like to save two
> different values in each elements of matrix. If there is a package or
> something which can deal with complex numbers, that will do it too. Also,
> I am wondering whether there is a function to calculate the rank of the
> matrix. I found a matrix package, but it doesn't have functions like that.
>
> Thanks a lot in advance!
>
> Mikyoung Jun
>
> __
> [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


[R] question about matrix

2003-11-12 Thread Mikyoung Jun
Hello,

I have a few questions about matrix in R. 

Can we make a matrix whose elements are list? I would like to save two
different values in each elements of matrix. If there is a package or
something which can deal with complex numbers, that will do it too. Also,
I am wondering whether there is a function to calculate the rank of the
matrix. I found a matrix package, but it doesn't have functions like that.

Thanks a lot in advance!

Mikyoung Jun

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