Thanks to all who responded to my query regarding subsetting a data frame
and keeping only the attributes that apply to the new data frame. Anne
York provided the fix that worked best for me. Below is a synopsis of the
replies along with my original posting.
German Rodriguez:
> dat$ANALYTE <- factor(dat$ANALYTE)
Bruce Aldridge:
unfactor <- function(x)
{
if(is.factor(x))
attributes(x)$levels[x]
else x
}
Anne York:
> newframe$ANALYTE <- factor(as.character(newframe$ANALYTE))
Samuel Buttrey:
> dat$Analyte <- factor (as.character(as.vector(dat$Analyte)))
Douglas Bates:
> dat$ANALYTE <- dat$ANALYTE[, drop = TRUE]
#----------------------------------------------
From: owner-s-news@wubios.wustl.edu
[mailto:owner-s-news@wubios.wustl.edu]On Behalf Of Debbie Carlson
Sent: Monday, February 21, 2000 7:41 PM
To: s-news@wubios.wustl.edu
Subject: [S] Data frame subsetting question
I'm using S-PLUS 2000 on Windows '98 machine, but I've also run into this
on Unix Solaris machines.
I've managed in about 8 years of programming in Splus to ignore this, but,
alas, no longer. When creating a new data frame that is a subset of an
existing one, I don't want all of the attributes of the old data frame,
just the ones that apply to the new data frame.
How can I achieve this?
Example code follows for a data frame in which one of the variables is
ANALYTE and there are 225 ANALYTES possible.
> dim(Sedgrer2)
[1] 37200 26
> ind_Sedgrer2$ANALYTE=="ZINC" &
Sedgrer2$AREA!="SF Bay Reference Location" & Sedgrer2$METHOD!="CLP
INORGANICS-ROUT-SEMETAL"
> dat_Sedgrer2[ind,]
>unique(dat$ANALYTE)
[1] ZINC
Levels (first 5 out of 225):
[1] "0.075 MM" "0.106 MM" "0.250 MM" "0.425 MM" "0.850 MM"
Deborah Carlson
Neptune and Company, Inc.
Phone: 505-662-0730 ext. 14
Fax: 505-662-0736
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|