s-news
[Top] [All Lists]

Re: Data manipulation

To: "'Dimitrios Chalvatzis'" <dimitrios.stats@btopenworld.com>, "'GRAHAM LEASK'" <grahamleask@btopenworld.com>, <s-news@lists.biostat.wustl.edu>
Subject: Re: Data manipulation
From: "Dimitrios Chalvatzis" <dimitrios.stats@btopenworld.com>
Date: Sun, 23 Apr 2006 16:57:21 +0100
In-reply-to: <000001c666ee$1f8cd250$599a8451@dimitrios>
Thread-index: AcZm25IA+8M1ERpmR3iVavRUQBb1jQAEhIEgAAA4+yA=

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

 

Best wishes

 

 

Graham



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

<Prev in Thread] Current Thread [Next in Thread>