[R] beginner's questions ... sorry

Daniel Lakeland dlakelan at street-artists.org
Thu Sep 13 22:22:55 CEST 2007


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



More information about the R-help mailing list