[R] exponentiate elements of a whole matrix
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Wed Oct 13 12:57:37 CEST 2010
On Wed, Oct 13, 2010 at 11:51 AM, Maas James Dr (MED) <J.Maas at uea.ac.uk> wrote:
> I've tried hard to find a way to exponentiate each element of a whole matrix such that if I start with A
>
> A = [ 2 3
> 2 4]
>
> I can get back B
>
> B = [ 7.38 20.08
> 7.38 54.60]
>
> I've tried
>
> B <- exp(A) but no luck.
Your matrix notation looks unlike R. We prefer cut n paste examples
here. In which case:
> A=matrix(1:4,2,2)
> A
[,1] [,2]
[1,] 1 3
[2,] 2 4
> exp(A)
[,1] [,2]
[1,] 2.718282 20.08554
[2,] 7.389056 54.59815
> B=exp(A)
> B
[,1] [,2]
[1,] 2.718282 20.08554
[2,] 7.389056 54.59815
so, works for me (as I expected it would).
Either you've redefined the exp function or you've accidentally
started matlab instead.
Barry
More information about the R-help
mailing list