Skip to content

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:
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:
a b added
1 1 3   foo
2 2 4   foo
3 3 5   foo
write.table
write.csv

or my favorite way of keeping data well organized is RSqlite or sqldf
(related)
#
On 13-Sep-07 20:06:35, Maura E Monville wrote:
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.
--------------------------------------------------------------------
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:
--------------------------------------------------------------------
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 ------------------------------