A while back I requested suggestions for the "Tip of the Day" in S-PLUS 6.
Thanks to everyone who responded. A summary of the tips I received is
provided below, most of which made it into S-PLUS 6 in one form or another.
Surprisingly I only got one "frivolous" tip and unfortunately that didn't
make it into the final list (thanks anyway, Andrew!).
# David Smith
Kevin Wright [Kevin.Wright@pioneer.com]:
Q: How do I make a splom with loess lines?
A:
panel=function(x,y,...){
panel.xyplot(x,y,...)
panel.loess(x,y)
}
---------------------------------------------------------------------------
Q: How do I remove shading in the "strip" of a trellis plot?
strip = function(...) strip.default(..., style = 1)
---------------------------------------------------------------------------
Q: How do I trap errors?
A: Use "try".
---------------------------------------------------------------------------
Q: How do I drop unused factor levels from a data.frame X?
A: For each column, do this: X$a<-X$a[,drop=T]
----------------------------------------------------------------------------
Bert Gunter [bert_gunter@merck.com]:
Say something about silent automatic conversion of character columns into
factors in data frames -- a frequent gotcha!
Anona Thorne (CTN) [anona@hivnet.ubc.ca]:
Since I'm using Splus 3.4 on Unix, this may or may not be useful or
relevant, but thought I'd send it along just in case. I found it
rather subtle when I was first trying to figure it out.
If you want to have "horizontal" axis labels, i.e. labels for the
y-axis that you don't have to turn your head to read, use par(las=1)
before you create the plot. (The default is las=0.) This will only
work, however, if you're using the axis command without using the "at"
option. If you don't use the "at" option, the values of crt, srt, and
adj are all ignored.
If you do use "at" to determine where your labels should appear, the
values of "las" and "side" are ignored, so you should use crt=0 in your axis
command to control the label rotation.
Naomi B. Robbins [n.robbins@att.net]:
I think that the task that gave me the most trouble was changing colors
of
graphical objects in Windows. I see a number of questions on that in
S-News. It's easy to change the colors under tools / color schemes.
The problem is how to let S-Plus know which color scheme you are using.
I now use the graphsheet command for that purpose, but it wasn't
immediately obvious that I should.
To turn that into a tip:
You can change the colors of graphical objects by choosing color schemes
on the tools menu. Then use the graphsheet command to tell S-Plus which
color scheme to use.
Bill Venables [Bill.Venables@CMIS.CSIRO.AU]:
>From what I see the major under-used elementary feature of S is the matrix
as index facility. I don't know how to capture this in a tip, but here is a
weak suggestion.
----
Did you know that the elements of a k-dimensional array can be accessed in
arbitrary order by giving the array a single index that is an n x k matrix
with rows containing the actual numerical indices of the elements to be
accessed? For example
A <- matrix(1:9, nrow=3, ncol=3)
M <- cbind(1:3, 1:3)
A[M] <- 0
replaces the diagonal entries of a 3x3 array with zeros. In this special
case
diag(A) <- 0
does the same thing.
----
The other tips I can think of are all to do with arrays and their
manipulation. People do not know about lower.tri, aperm, outer, &c and they
also don't know that matrix operators are often the quickest way to get
something done. For example
The fastest way to find the row means of a matrix is
rmeans <- X %*% rep(1, ncol(X))/ncol(X)
Karen Jonson [Karen_Johnson@bd.com]:
I stumbled around S+ several months befor I came across V&R's book and the
list server. Information on either would have saved me moutains of time.
Andrew Jack [andrew_jack@merck.com]:
"Before you spend hours trying to solve a problem, try searching the S-news
archives, or send an e-mail to the S-news list. You'll be amazed at the
response!"
"S-plus has functions called c, q, s, t, C, D, and I. So it's better not to
use these names for your own objects."
"Insightful is not such a bad name; it just takes a bit of getting used to."
"! at the start of a line sends a command to the external operating system;
otherwise, ! means logical NOT. If you want a NOT at the start of a line,
put the whole expression in parentheses"
"Don't use data frames if you have a lot of data manipulation to do; matrix
objects are much faster"
"If you're doing a lot of programming with functions, make sure you learn
how to use the browser() tool"
--
David M Smith <dsmith@insightful.com>
S-PLUS Product Marketing Manager, Insightful Corp, Seattle WA
Tel: +1 (206) 283 8802 x360
Fax: +1 (206) 283 0347
Insightful Corporation provides analytical solutions leveraging
S-PLUS, StatServer, S-PLUS Analytic Server and consulting services.
See www.insightful.com for details.
|