[6552] in s-news-athena
No subject found in mail header
daemon@ATHENA.MIT.EDU (Chang Yu)
Thu Mar 2 12:52:24 1995
To: s-news-athena@MIT.EDU
Date: Thu, 2 Mar 95 10:11:50 CST
From: "Chang Yu" <chang@muskie.biostat.umn.edu>
Apparently-To: S-news@utstat.toronto.edu
Dear All:
Last night I posted this question. Following is a summary of the
responses. I thank you all who responded!
Basically, the nice format
dlsoa.data[dlsoa.data==-99]<-NA
works only for matrix, not for data.frame, which is what I tried with
frustration. It seems the best way is to convert the data.frame to a
matrix, replace -99 by NA, then convert it back to data.frame.
There are some other ways to get around. For your interest they are in
the summary.
Once again, Thanks to everyone!
Chang Yu
chang@muskie.biostat.umn.edu
****************************************************************************
QUESTION*******************************************************************
It is a simple question. I just could not get it.
Here is part of my data:
> dlsoa.data
pid weight cad no-social male age75-79 age80-84 age85+ low-income stroke
1 1 2128 0 0 0 0 1 0 0 0
2 2 4396 1 0 1 0 0 0 -99 0
5 7 2128 0 0 0 0 1 0 0 0
6 8 2128 0 0 0 0 1 0 1 0
cancer arthritis diabets control status dement3
1 0 1 0 0 1 0
2 0 0 1 1 0 0
5 0 0 1 -99 1 0
6 0 0 0 -99 0 0
In the data file the missing data were coded as -99 and they were read into
a data frame as -99 by function "read.table".
Now I want to replace -99 by NA so tree() function will know it, otherwise
it will work on it as if they are numerical values -99. I tried the argument
"na.strings=" -99"" without any luck. It is the wrong way to do it.
Could anyone give me a hint?
Thanks a lot!
Chang Yu
chang@muskie.biostat.umn.edu
****************************************************************************
RESPONSES*******************************************************************
From david@c255.ucsf.EDU Wed Mar 1 21:01:50 1995
a_matrix(3,3,3)
a[2,3]_-99
a_data.frame(a)
print(a)
a_as.matrix(a)
a[a==-99]_NA
a_data.frame(a)
print(a)
Davide Verotta, Dr, PhD e-mail: davide@c255.ucsf.edu
Asst Prof Pharmacy and Biostatistics Phone: (415) 476-1556
University California at San Francisco
521 Parnassus Avenue, San Francisco, CA 94143-0446
Fax: (415) 476-1556
Fax alternative: (415) 476-1556 #11
Fax alternative (if none of the above works): (415) 476-1508
From scw@io.harvard.edu Wed Mar 1 21:33:16 1995
dlsoa.data[dlsoa.data==-99]<-NA
It is a simple question. I just could not get it.
Here is part of my data:
> dlsoa.data
pid weight cad no-social male age75-79 age80-84 age85+ low-income stroke
1 1 2128 0 0 0 0 1 0 0 0
2 2 4396 1 0 1 0 0 0 -99 0
5 7 2128 0 0 0 0 1 0 0 0
6 8 2128 0 0 0 0 1 0 1 0
cancer arthritis diabets control status dement3
1 0 1 0 0 1 0
2 0 0 1 1 0 0
5 0 0 1 -99 1 0
6 0 0 0 -99 0 0
In the data file the missing data were coded as -99 and they were read into
a data frame as -99 by function "read.table".
Now I want to replace -99 by NA so tree() function will know it, otherwise
it will work on it as if they are numerical values -99. I tried the argument
"na.strings=" -99"" without any luck. It is the wrong way to do it.
Could anyone give me a hint?
Thanks a lot!
Chang Yu
chang@muskie.biostat.umn.edu
******************************************************************************
From ashar@kernel.uwrl.usu.edu Wed Mar 1 22:10:08 1995
> a_matrix(1,3,3)
> a[2,3]_-99
> a
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 -99
[3,] 1 1 1
> a[a==-99]_NA
> a
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 NA
[3,] 1 1 1
Hope this helps.
Ashish
----------------------------------------------
Ashish Sharma <ashar@kernel.uwrl.usu.edu>
UWRL, USU, Logan, UT-84321
Tel.#(801)797-3152
----------------------------------------------
***************************************************************************
From tap@epi.terryfox.ubc.ca Wed Mar 1 22:14:21 1995
Here's how I did it:
> d <- data.frame(x=1:10, y=0:9)
> d$y[3] <- -99
> d$y[7] <- -99
> d$x[1] <- -99
> d$x[6] <- -99
> d
x y
1 -99 0
2 2 1
3 3 -99
4 4 3
5 5 4
6 -99 5
7 7 -99
8 8 7
9 9 8
10 10 9
> d$x <- replace(d$x, d$x==-99, NA)
> d$y <- replace(d$y, d$y==-99, NA)
> d
x y
1 NA 0
2 2 1
3 3 NA
4 4 3
5 5 4
6 NA 5
7 7 NA
8 8 7
9 9 8
10 10 9
>
******************************************************************************
From chi@maz.sma.ch Thu Mar 2 01:01:23 1995
Hi Chang Yu
Tri it like this:
e.g.: dlsoa.data$control[dlsoa.data$control == -99] <- NA
It worked in my lists.
Regards
Christian Haeberli, Swiss Meteorological Institute
******************************************************************************
From olafe@wirbel.vmsmail.ethz.ch Thu Mar 2 02:03:59 1995
Hithere,
what do you think about the following workaround (let me know if some
more sophisticated solution appears ...)
data.df_read.tbale(.....)
data.mat_as.matrix.data.frame(data.df)
data.mat[data.mat==-99]_NA
data.df_as.data.frame(data.mat)
Good luck,
OLAF
=============================================================================
Olaf Eichstaedt +++++
Swiss Federal Institute of Technology +++++
Institute of Process- and Cryogenic Engineering +++++++++++++
Zuerich - Switzerland +++++++++++++
Tel. INT+41+1+633 6267 +++++++++++++
FAX. INT+41+1+633 1119 +++++
MAIL olafe@wirbel.vmsmail.ethz.ch +++++
*****************************************************************************
From hellmic@medsun01.uni-muenster.de Thu Mar 2 02:04:01 1995
try
dlsoa.data<-as.matrix(dlsoa.data)
dlsoa.data[dlsoa.data==-99]<-NA
dlsoa.data<-as.data.frame(dlsoa.data)
.
|||
Martin Hellmich |||||
|||||||
Department of Medical Informatics and Biomathematics |||||||
University of Muenster |||||||
Domagkstr. 9 VOICE +49 (251) 83-5276 | | | |
D-48129 Muenster FAX +49 (251) 83-5277
Germany E-MAIL hellmic@medsun01.uni-muenster.de
=============================================================================
From m1mmk00@frb.gov Thu Mar 2 07:44:58 1995
Dear Chang,
Here's a little function which does what you want. df, of course,
is a data.frame. The simplest solution seems to be to convert your
data frame to a matrix.
foo<- function(df)
{ df2<- as.matrix(df)
df2[df2==-99]<- NA
as.data.frame(df2)
}
Margi Keating