Re: [R] convert data.frame to matrix -> NA factor problem

2010-07-14 Thread Erik Iverson
syrvn wrote: Thanks again for your quick reply. I understood your procedure but now it is even more strange why my conversion does not work. In your example, the NA values are in "brackets" and what your procedure does is to convert these values into NA and then it seems to be possible to us

Re: [R] convert data.frame to matrix -> NA factor problem

2010-07-14 Thread syrvn
Thanks again for your quick reply. I understood your procedure but now it is even more strange why my conversion does not work. In your example, the NA values are in "brackets" and what your procedure does is to convert these values into NA and then it seems to be possible to use data.matrix to

Re: [R] convert data.frame to matrix -> NA factor problem

2010-07-14 Thread Joshua Wiley
More importantly than just that they are factors, NA is actually a level of X3. If it was a factor column, but NA was not a level, than in the conversion to numeric, it would not change into a 4, but it is a level (in fact the 4th level), so it becomes a 4. From ?factor here is the recommended wa

Re: [R] convert data.frame to matrix -> NA factor problem

2010-07-14 Thread syrvn
Hi, I used str() on my data set: $ X1: num 1 1 0 1 1 1 1 1 1 1 ... $ X2: num 0 1 0 2 1 2 0 2 2 0 ... $ X3: Factor w/ 4 levels "0","1","2","NA": 2 1 3 1 1 1 1 1 1 3 ... The difference to your str() output is that in your case NA columns are "num" colum

Re: [R] convert data.frame to matrix -> NA factor problem

2010-07-14 Thread Joshua Wiley
Hi, Can you show the results of str() on your original dataframe? Also it would help if you could make an example that demonstrates your problem. I used this little example, and did not notice any problems: samp.frame <- data.frame(a = 1:10, b = c(3,2,5,3,1,5,NA,4,5,NA)) str(samp.frame) samp.ma

[R] convert data.frame to matrix -> NA factor problem

2010-07-14 Thread syrvn
Hi list, I tried to convert a data.frame into a matrix using data.matrix. Unfortunately my matrix contains missing values (NA) wherefore all columns including NA's were changed into factors. I thought that many people stumbled across that problem already wherefore there must be a simple solution