An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070913/08ac524a/attachment.pl
beginner's questions ... sorry
4 messages · Maura E Monville, Daniel Lakeland, (Ted Harding)
On Thu, Sep 13, 2007 at 03:06:35PM -0500, 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.
You can read the patient ID out of the header using scan and some manipulation of the resulting strings, depending on how complicated it is to find the patient ID in the header. Then you can read.table or read.csv etc to get the data. Then use the cbind command as you did to bind the new column with the patient id to the rest of the data. I believe that cbind will recycle the patient ID to make up the required number of rows, so you can simply cbind(your.data, yourpatientID) where instead of a large column of identical items, you have a single item for yourpatientID an example:
myframe <- cbind(as.data.frame(list(a=1:3,b=3:5)),added="foo") myframe
a b added 1 1 3 foo 2 2 4 foo 3 3 5 foo
I have no doubt R experienced users would accomplish the same task in a couple of strokes .... HOW ????
And how shall I instruct R to save my changes when I close the editing session ?
write.table write.csv or my favorite way of keeping data well organized is RSqlite or sqldf (related)
Daniel Lakeland dlakelan at street-artists.org http://www.street-artists.org/~dlakelan
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 ------------------------------
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 ------------------------------