[R] Newbie: Selecting data

Zembower, Kevin kzembowe at jhuccp.org
Thu Oct 19 22:12:54 CEST 2006


I've been working with R for all of about 8 hours, so anyone with more
experience than this should be able to help me. General comments about
my methods of work are also welcomed.

I have a table that I've imported thusly:
> w <- read.table("woodford.data", header=T)
> w
       start therms    gas KWHs  elect temp days
1  10-Jun-98      9  16.84  613  63.80   75   40
2  20-Jul-98      6  15.29  721  74.21   76   29
3  18-Aug-98      7  15.73  597  62.22   76   29
4  16-Sep-98     42  35.81  460  43.98   70   33
5  19-Oct-98    105  77.28  314  31.45   57   29
6  17-Nov-98    106  77.01  342  33.86   48   30
<snip>

[This is real data on my house.] 'days' is number of days in bill,
'temp' is average temperature in Fahrenheit. I'd like to see if there is
a relationship between the gas burned (therms) and the number of heating
degree days.

I compute therms per day and heating degree days like this:
> thermsperday <- w[,2]/w[,7]
> hdd <- (w[,6] -65)*w[,7]

However, I only want the data for the months in which the average
temperature is less than 65 (otherwise, it's a cooling degree day). I
tried ifelse, but couldn't get it to work. What simple technique am I
overlooking?

Thanks so much for your help and suggestions, especially for your
patience with a newbie.

-Kevin

Kevin Zembower
Internet Services Group manager
Center for Communication Programs
Bloomberg School of Public Health
Johns Hopkins University
111 Market Place, Suite 310
Baltimore, Maryland  21202
410-659-6139



More information about the R-help mailing list