Skip to content

replace values of a table !!!

3 messages · Taiseer Aljazzar, PIKAL Petr, Wolfgang Raffelsberger

#
Dear all,

Dear all,

I am a relatively new user.
I have an ascii file with 550 rows and 400 columns. The file contain values ranging from 1 to 2000 and some values with -9999.

I want to generate a new file where the -9999 values are replaced with 0 values, the other values with the 1.0 value.

What should I do,

Thanks
Taiseer
#
Hi

r-help-bounces at r-project.org napsal dne 21.12.2010 09:59:31:
values
Do you want to use R for it? If yes you can read the file and set -9999 as 
missing value
see ?read.table

further on you can

change not NA values to 1 by

your.data[!is.na(your.data)] <- 1

and NA values to 0 by

your.data[is.na(your.data)] <- 0

Regards
Petr
http://www.R-project.org/posting-guide.html
#
I suppose what you want to do is something like:

dat <- matrix(c(2:13,-9999),nc=4)
dat
dat[dat== -9999] <- 1   # replace the -9999 by 0
dat


Please be careful to think twice what you are doing to you data by changing some values.  Maybe you rather want to replace the -9999 values by NA ?

HTH,
Wolfgang
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wolfgang Raffelsberger, PhD
Laboratoire de BioInformatique et G?nomique Int?gratives
IGBMC,
1 rue Laurent Fries,  67404 Illkirch  Strasbourg,  France
Tel (+33) 388 65 3300         Fax (+33) 388 65 3276
wolfgang.raffelsberger at igbmc.fr

________________________________________
De : r-help-bounces at r-project.org [r-help-bounces at r-project.org] de la part de Taiseer Aljazzar [taljazzar at yahoo.com]
Date d'envoi : mardi 21 d?cembre 2010 09:59
? : r-help at r-project.org
Objet : [R] replace values of a table !!!

Dear all,

Dear all,

I am a relatively new user.
I have an ascii file with 550 rows and 400 columns. The file contain values ranging from 1 to 2000 and some values with -9999.

I want to generate a new file where the -9999 values are replaced with 0 values, the other values with the 1.0 value.

What should I do,

Thanks
Taiseer

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.