Win, This could probably be done cleaner, and shorter, but it works
----
# FILL IN MISSING HOURS
tmp <- data.frame(
hour = c(0, 1, 2, 3, 4, 6, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23),
strikes = c(152, 97, 29, 15, 3, 1, 1, 2, 9, 15, 14, 21, 31, 45, 60, 72,
98, 158, 201, 225)
)
tmp1 <- tmp$hour[1]:tmp$hour[dim(tmp)[1]]
tmp1 <- data.frame(
hour = tmp1,
strikes = 0
)
tmp1$strikes[match(tmp$hour, tmp1$hour)] <- tmp$strikes
tmp1
----
Lee De Cola, PhD, MCP
U.S. Geological Survey
521 National Center
Reston VA 20192 USA
Room 2D324
703-648-4178, fax 4603
W77°22'10" N38°56'48"
703-709-6972 home
LDECOLA@USGS.GOV
ldecola.net
"Crawford.Winnie"
<crawford.winnie@
ensco.com> To
Sent by: "S-PLUS Newsgroup"
s-news-owner@list <s-news@lists.biostat.wustl.edu>
s.biostat.wustl.e cc
du
Subject
[S] fill in table names
2009/01/29 04:35
PM
All,
I am running S-PLUS 8 on a Windows XP PC.
I have data that I want to table to find the number of lightning
occurrences per hour, even if it is 0. If no lightning occurred during a
certain hour, the hour is not in the data frame. The table() function only
outputs names for the hours that are in the data frame, e.g.
>table(dataframe$Hour) yields
0 1 2 3 4 6 9 11 12 13 14 15 16 17 18
19 20 21 22 23
152 97 29 15 3 1 1 2 9 15 14 21 31 45 60
72 98 158 201 225
This shows there were no lightning strikes at 5:00, 7:00, 8:00 and 10:00.
How can I get 5, 7, 8, and 10 to show up in the table with values of 0
associated with them? Thanks for the help.
Win Crawford
*****************************************************************
Winifred C. Crawford Staff Scientist/Senior Meteorologist
ENSCO, Inc.
Aerospace Sciences and Engineering Division
1980 N. Atlantic Ave., Suite 830
Cocoa Beach, FL 32931
VOICE: 321.853.8130 FAX: 321.853.8415
EMAIL: crawford.winnie@ensco.com
AMU Quarterly Reports are available online:
http://science.ksc.nasa.gov/amu
*****************************************************************
The information contained in this email message is intended only for the
use of the individual(s) to whom it is addressed and may contain
information that is privileged and sensitive. If you are not the intended
recipient, or otherwise have received this communication in error, please
notify the sender immediately by email at the above referenced address and
note that any further dissemination, distribution or copying of this
communication is strictly prohibited.
The U.S. Export Control Laws regulate the export and re-export of
technology originating in the United States. This includes the electronic
transmission of information and software to foreign countries and to
certain foreign nationals. Recipient agrees to abide by these laws and
their regulations -- including the U.S. Department of Commerce Export
Administration Regulations and the U.S. Department of State International
Traffic in Arms Regulations -- and not to transfer, by electronic
transmission or otherwise, any content derived from this email to either a
foreign national or a foreign destination in violation of such laws.
|