Or this slick one:
ifelse(data[,1]=="NA",data[,2],data[,1])
From:
s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On
Behalf Of Dimitrios Chalvatzis
Sent: 23 April 2006 16:54
To: 'GRAHAM LEASK';
s-news@lists.biostat.wustl.edu
Subject: Re: [S] Data manipulation
Many ways to do this, so here is one
suggestion:
replace(data[,6],which.na(data[,6]),data[which.na(data
[,6]),7])
Dimitrios
From:
s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On
Behalf Of GRAHAM LEASK
Sent: 23 April 2006 14:41
To: s-news@lists.biostat.wustl.edu
Subject: [S] Data manipulation
I have a file with several thousand rows consisting of 7 columns.
Some of the data in Col6 are characters, the rest are numeric or NA's. I
wish to replace the data in Col6 which are characters (not NAs) with the data
in the adjacent cell of Col7. How do I do this simply in S plus?
Any help greatly appreciated
Kind regards
Dr Graham Leask
Economics and Strategy Group
Aston Business School
Aston University
Aston Triangle
Birmingham
B4 7ET
Tel: Direct line 0121 204 3150
email g.leask@aston.ac.uk