[R] a question on CSV file
Gabor Grothendieck
ggrothendieck at myway.com
Tue Mar 9 03:24:45 CET 2004
In rereading what I had written there is an error.
The first statement selecting Med as 1 should be as follows:
x[x$Med == 1,]
---
Date: Mon, 8 Mar 2004 20:53:48 -0500 (EST)
From: Gabor Grothendieck <ggrothendieck at myway.com>
To: <cindy197901 at yahoo.com>, <R-help at stat.math.ethz.ch>
Subject: RE: [R] a question on CSV file
Note that a CSV file is one in which data elements
are separated by commas. There are no commas in
what you display so I assume that you are displaying
the data after you have read it in, not the CSV file.
If you read a file into a data frame x you can refer to
row i column j of the data frame as x[i,j].
The subset of rows of data frame x with column Med equal to 1 is
x[,x$Med == 1]
or equivalently
subset(x, Med == 1)
See ?subset for more info.
See ?save and ?write
You can plot column heartrate vs. column ex in data frame x
like this:
plot( heartrate ~ ex, data = x )
You might find it helpful to read or re-read the document
An Introduction to R .
---
Date: Mon, 8 Mar 2004 08:54:09 -0800 (PST)
From: Cindy Juncker <cindy197901 at yahoo.com>
To: <R-help at stat.math.ethz.ch>
Subject: [R] a question on CSV file
I have a csv file,
heartrate excercise medicine Time
12 0 0 4:30 am
23 5 0 5:00 am
34 6 0 5:30 am
56 3 0 6:00 am
24 12 1 6:30 am
35 2 0 7:00 am
26 5 0 7:30 am
63 4 0 8:00 am
24 3 1 8:30 am
45 9 0 9:00 am
I did the folllowing:
x <- read.table("heart.csv",sep=",")
names(x) <- c("heartrate","ex","Med","Time")
x.newtime <- strptime(x$Time, format= "%H:%M %p")
What I am tring to do is:
First I am trying to get all the data from when there was a medicine taken in previous hour.
Second I will plot heartrate VS median Excercise in previous hour.
In the first problem, how can I get the desired data? after I got it, should I put it in a new file? How?
How can I refer to a specific cell in a csv file?
I appreciate your kindly help!
More information about the R-help
mailing list