[R] [OOPS] beginner's questions ... sorry

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu Sep 13 22:39:21 CEST 2007


OOPS!! When I wrote "use readline()" below, I meant

  use readLInes()

Sorry! For more information see ?readLines

Ted.

On 13-Sep-07 20:32:37, Ted Harding wrote:
> On 13-Sep-07 20:06:35, Maura E Monville wrote:
>> I have 316 files. Each file represents a patient's breathing
>> track (respiratory signal recorded for a variable number of
>> cycles).
>> All files have the same are made up of a header followed by
>> a variable number of records.
>> Each record contains 7 comma separated fields.
>> The patient ID is recorded in the header which is stripped
>> off when reading the file into a R data.frame.
>> Since I need to keep this piece of information, I need to add
>> the 8th column to a patient's data.frame. All elements of
>> such a column store the patient's ID.
>> The problem is trivial. I guess it can be done in a matter of
>> a few seconds.
>> But I (a R novice) could not find an automatic or fast way to
>> do that.
> 
> Hi Maura,
> There could be several ways to do it, but the important thing
> is to know how to "parse out" the Patient ID from the header.
> 
> What is the structure of the header?
> 
> One possibility could be to use readline() to read the header
> from the file, before reading the file into R as a dataframe.
> 
> Then parse out the Patient ID, and assign it to a variable.
> Then read in the file as a dataframe, find out how many records
> are in it, make a column of that number of copies of the Patient
> ID, and glue it onto the dataframe.
> 
> Hoping that helps; but if not come back with more info about
> that header!
> 
> Of course, once you have the Patient ID in a variable to start
> with, perhaps you don't need it as part of the dataframe any more?
> 
> Best wishes,
> Ted.
> 
>> I started up editing the patient's data.frame and figured out I can
>> only
>> copy and past 1 cell at a time ... but I had 4991 cells so  ... In
>> addition,
>> I could not find a way to close the editing session while preserving
>> the
>> changes in the data.frame.
>> So I generated a vector with 4991 elements, all recording the same
>> patient-ID call is patient_ID.
>> Then I used  *cbind(patient.data.frame, patient_ID)*
>> to generate a new.patient.data.frame made up of 8 columns, the last
>> added
>> one recording the patient's ID.
>> 
>> I have no doubt R experienced users would accomplish the same task in
>> a
>> couple of strokes .... HOW ????
>> 
>> Another question is: how can multiple cells copy&past be performed
>> with
>> R
>> editor ?
>> And how shall I instruct R to save my changes when I close the editing
>> session ?
>> 
>> Thank you very much,
>> -- 
>> Maura E.M
>> 
>>       [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> 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.
> 
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 13-Sep-07                                       Time: 21:32:34
> ------------------------------ XFMail ------------------------------
> 
> ______________________________________________
> 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.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 13-Sep-07                                       Time: 21:39:17
------------------------------ XFMail ------------------------------



More information about the R-help mailing list