Re: [R] how to change a dataframe with characters to a numeric matrix?

From: David Hajage <dhajage_at_gmail.com>
Date: Thu 08 Dec 2005 - 20:58:22 EST

and then, if you want a matrix and not a data.frame :

TEST <- as.matrix(TEST)

2005/12/8, David Hajage <dhajage@gmail.com>:
>
> A way to do it :
>
> TEST$Y3[TEST$Y3=="Z"] <- NA
>
> TEST$Y3 <- as.numeric(TEST$Y3)
>
>
> 2005/12/8, zhihua li <lzhtom@hotmail.com>:
> >
> > hi netters,
> >
> > i have a dataframe TEST like this:
> >
> > Y1 Y2 Y3
> > X1 4 7 8
> > X2 6 2 Z
> > X3 8 0 1
> >
> > i would like to change it to a numeric matrix, replacing "Z" with NA
> >
> > Y1 Y2 Y3
> > X1 4 7 8
> > X2 6 2 NA
> > X3 8 0 1
> >
> > i've tried the function data.matrix but it didn't work. is there any
> > easy
> > way to do this?
> >
> > thanks a lot!
> >
> >
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> >
https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> >
> >
>
>
> --
> David

--
David

	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Dec 08 21:08:42 2005

This archive was generated by hypermail 2.1.8 : Thu 08 Dec 2005 - 23:37:14 EST