Just as I was about to write this message, I got two emails from Prof.
Ripley and Alan Gross. They both provided the same solution (which
works, by the way):
> good.30 <- MyDF$DIR < 30 & !is.na(MyDF$DIR)
Just before I got those emails, however, I discovered that
> MyDF.30 <- MyDF[na.exclude(good.30),]
also works if the logical has NAs in it. However, my solution requires
two steps whereas the other requires only one. Incidently, Prof. Ripley
thinks the values in the error statement are due to a bug, but he could
not replicate it. Thanks all!
Win
-----Original Message-----
From: Winifred Lambert [mailto:lambert.winifred@ensco.com]
Sent: Saturday, September 29, 2001 12:31 PM
To: S-PLUS Newsgroup (E-mail)
Subject: [S] NAs in Numeric Columns
SPlus 2000, Windows 2000
All,
I have done alot of looking the last couple of days and can't seem to
find a cure to this issue. I have a data frame with 13 columns of
numeric data (mixture of integer and floating point columns) and 8902
rows. Some of the data are missing and are designated with NA. I would
like to stratify the data by value ranges (0-30, 30-60, 60-90, etc) in
one of the integer columns, named DIR. In the past, I have stratified
data in this way:
> good.30 <- MyDF$DIR < 30
> MyDF.30 <- MyDF[good.30,]
and have never had a problem. However, I must have always used vectors
that did not contain NAs. Because of the NAs in DIR, corresponding NAs
occurred in the logical vector good.30, and the second command above
produced the following error:
Error in dimnames(x) <- list(rn, dimnames(x)[[2]]): Component 1 of
dimnames has length 7438, should be 1115
To find out how many Fs, Ts and NAs there were in the logical vector, I
fumbled around with the table command until I figured out to do the
following:
> table(na.include(as.factor(good.test)))
FALSE TRUE NA
7787 1003 112
I can see that TRUE + NA = 1115, but I can't figure out where the 7438
came from in the error statement. I manually edited good.30 so that all
the NAs were Fs and got the desired results. After looking in help at
various commands and in the Programmers Guide, I cannot find a way to
create a logical using a numeric vector containing NAs. I am now trying
to figure out how to automatically change the NAs in the logical to Fs.
Does anyone know of a command that is more succint than creating a
logical then editing it? I'd also like some advice on how to
automatically edit the logical vector if you know how to do it. I'm
currently looking at the if() function. Thanks much for the help.
*************************************************
Winifred C. Lambert Senior Scientist/Meteorologist
ENSCO, Inc.
Aerospace Sciences and Engineering Division
1980 N Atlantic Ave, Suite 230
Cocoa Beach, FL 32931
VOICE: 321.853.8130 FAX: 321.853.8415
lambert.winifred@ensco.com
AMU Quarterly Reports are available online:
http://science.ksc.nasa.gov/amu/home.html
*************************************************
---------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|