[R] tm[,-1]

Greg Snow Greg.Snow at imail.org
Thu Mar 11 23:12:47 CET 2010


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of ManInMoon
> Sent: Thursday, March 11, 2010 4:22 AM
> To: r-help at r-project.org
> Subject: [R] tm[,-1]
> 

[snip]

> 
> 
> Please don't tell me to check the manual - I tried and failed
> dismally...
> 

But often the best answer is to read the manual, or reread the manual, there is nothing wrong with asking for suggestions on which parts of the manual to read (there is a lot out there now), or for clarifications of parts that you do not understand.  If you can tell why you failed, then that gives others information that can be used to improve the manuals, but what you said is very unhelpful.

There seems to be more and more people that feel a quick answer on the list is preferable to trying to understand the manuals.  What if someone asked about the best shape for a wheel and did not want to read the manual, they mention that they have a square wheel that doesn't work, and when they tried a triangle it was even worse.  Someone else then replies that they have had better luck with pentagons and hexagons look promising.  Someone else mentions that they tried and octagon and it worked even better.  Then someone comes in with the theory that a decagon would be even better, provided you can create a regular decagon, but they unfortunately have only succeeded at creating irregular ones that don't work as well as the octagon.  A side branch then develops discussing smooth shapes of constant radius that would work as rollers, but don't quite work as wheels.  All this time the manual has a good description of circles used as wheels including a simple way to make them, but you won't look there, so you are doomed to a suboptimal solution.

Let's look at the replies you received for the tm[,-1] query.  They were of 2 general types: "go read the manual anyway" (which I would consider the best answer) and "it means the matrix without the 1st column" which is a dodecagon type answer, consider the following:

> tm <- matrix(1:12, ncol=3)
> tm
     [,1] [,2] [,3]
[1,]    1    5    9
[2,]    2    6   10
[3,]    3    7   11
[4,]    4    8   12
> tm[,-1]
     [,1] [,2]
[1,]    5    9
[2,]    6   10
[3,]    7   11
[4,]    8   12


OK, tm is a matrix and tm[,-1] looks like the same matrix without the 1st column.  But what if we change the example a little bit:

> tm <- matrix(1:8, ncol=2)
> tm
     [,1] [,2]
[1,]    1    5
[2,]    2    6
[3,]    3    7
[4,]    4    8
> tm[,-1]
[1] 5 6 7 8

This result looks different, what happened? And what should you do if you want results more like the first example?  The answer is in the manual ?"[".


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111

 


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111



More information about the R-help mailing list