An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090215/6c31d954/attachment-0001.pl>
matrix transpose
5 messages · Roger, Rolf Turner, Daniel Viar +1 more
On 16/02/2009, at 8:36 AM, Roger wrote:
This is supposed to be an easy operation, but R 2.8.1 on Mac OS X gives me a lot trouble. the t() function simply does not work properly. What I mean is it works sometimes but does not work at the most of the time, even with the same matrix. this is an example taken from R help
a <- matrix(1:30, 5,6) t(a)
Error in t(a) : unused argument(s) (1:30) It just gives this error. If I restart my Mac (Yeah, have to restart the OS), then there are chances t() works, but sometimes it still does not work. Can anyone give me another way to compute the transpose in R?
No. That's the only way. :-)
(1) I have no problem doing your example (on Mac OS X).
(2) The error is weird in that you passed the argument ``1:30'' to
matrix()
not to t(). Something is corrupted in your system. What
happens when
you just type ``a'' (rather than t(a)) after creating a? What
happens
when you type ``t'' (no parentheses) and ``matrix'' (no
parentheses)?
(3) Possibly you have a workspace that is corrupted in some way. Try
starting
R with the --no-restore-data flag and see what happens. Or
move .RData
to (say) ``save.RData'' before you start R, and see what happens.
(4) Good luck!
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Roger wrote:
This is supposed to be an easy operation, but R 2.8.1 on Mac OS X gives me a lot trouble. the t() function simply does not work properly. What I mean is it works sometimes but does not work at the most of the time, even with the same matrix. this is an example taken from R help
a <- matrix(1:30, 5,6)
t(a)
Error in t(a) : unused argument(s) (1:30) It just gives this error. If I restart my Mac (Yeah, have to restart the OS), then there are chances t() works, but sometimes it still does not work.
does it ever fail if you try the example in a fresh r session (i.e., one without anything executed before this code)? when it fails, what is t? have you redefined t to be some other function, in particular, a no-argument one, as here: t = function() NULL a = matrix(1:30, 5, 6) t(a) # Error in t(a) : unused argument(s) (1:30) this is most likely what happens here. vQ
Here's one way that seems to work:
a <- matrix(1:30,5,6)
# Create a target for the transpose
b <- matrix(1:(nrow(a)*ncol(a)),ncol(a),nrow(a))
# populate b with the transpose of a
for (i in 1:ncol(a)) { b[i,1:(nrow(a))] <- a[1:(nrow(a)),i]}
# Check: Did it work?
all.equal(b,t(a))
I'm sure there's a more "R-like" way of doing this...
Cheers,
Dan Viar
Chesapeake, VA
On Sun, Feb 15, 2009 at 3:05 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
On 16/02/2009, at 8:36 AM, Roger wrote:
This is supposed to be an easy operation, but R 2.8.1 on Mac OS X gives me a lot trouble. the t() function simply does not work properly. What I mean is it works sometimes but does not work at the most of the time, even with the same matrix. this is an example taken from R help
a <- matrix(1:30, 5,6) t(a)
Error in t(a) : unused argument(s) (1:30) It just gives this error. If I restart my Mac (Yeah, have to restart the OS), then there are chances t() works, but sometimes it still does not work. Can anyone give me another way to compute the transpose in R?
No. That's the only way. :-)
(1) I have no problem doing your example (on Mac OS X).
(2) The error is weird in that you passed the argument ``1:30'' to matrix()
not to t(). Something is corrupted in your system. What happens when
you just type ``a'' (rather than t(a)) after creating a? What happens
when you type ``t'' (no parentheses) and ``matrix'' (no parentheses)?
(3) Possibly you have a workspace that is corrupted in some way. Try
starting
R with the --no-restore-data flag and see what happens. Or move .RData
to (say) ``save.RData'' before you start R, and see what happens.
(4) Good luck!
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
______________________________________________ R-help at 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.
Rolf Turner wrote:
On 16/02/2009, at 8:36 AM, Roger wrote:
This is supposed to be an easy operation, but R 2.8.1 on Mac OS X gives me a lot trouble. the t() function simply does not work properly. What I mean is it works sometimes but does not work at the most of the time, even with the same matrix. this is an example taken from R help
a <- matrix(1:30, 5,6) t(a)
Error in t(a) : unused argument(s) (1:30) It just gives this error. If I restart my Mac (Yeah, have to restart the OS), then there are chances t() works, but sometimes it still does not work. Can anyone give me another way to compute the transpose in R?
No. That's the only way. :-)
nonsense. the other way is: base::t(a) if this works while t(a) fails, the problem is solved (= do *not* redefine t). if this doesn't work, complain again ;) vQ