Laura Quinn wrote:

thanks, have used

temp [temp==0]<- NA

Please use is.na(temp[temp==0]) <- TRUE


and this seems to have worked, though it won't let me access individual
columns (ie temp$t1 etc)

No! temp$t1 is a list element or column of a data.frame, but not a column of a matrix. *PLEASE*, read manuals, help pages, or books on R how to use index / extract elements.


Please read my previous answer on how to access individual columns.


to work on - is there any real advantage in using
a matrix, or would i be better advised to deal with dataframes? (I have
double checked and temp is currently a matrix).

Working on matrices is supposed to be faster. But matrices have the restriction of one data type for all columns (e.g. numeric).


Uwe Ligges


On Tue, 7 Oct 2003, Prof Brian Ripley wrote:


On Tue, 7 Oct 2003, Laura Quinn wrote:


I am dealing with a huge matrix in R (20 columns, 54000 rows) and have
lots of missing values within the dataset which are currently displayed as
the value "-999.00" I am trying to create a new matrix (or change the
existing one) to display these values as "NA" so that I can then perform
the necessary analysis on the columns within the matrix.

The matrix name is temp and the column names are t1 to t20 inclusive.

I have tried the following command:

temp$t1[temp$t1 == -999.00] <- NA

and it returns a segmentation fault, can someone tell me what I am doing
wrong?

Well, R should not segfault, so there is bug here somewhere. However, I don't think what you have described can actually work. Is temp really a matrix? If so temp$t1 will return NULL, and you should get an error message.


If temp is a matrix


temp[temp == -999.00] <- NA

will do what you want.


If as is more likely temp is a data frame with all columns numeric, there are several ways to do this, e.g.

temp[] <- lapply(temp, function(x) ifelse(x == -999, NA, x))

temp[as.matrix(temp) == -999] <- NA # only in recent versions of R

as well as explicit looping over columns.

--
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to