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

zhihua li lzhtom at hotmail.com
Thu Dec 8 10:29:47 CET 2005


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!




More information about the R-help mailing list