[R] degree-min-sec data
George_Heine@blm.gov
George_Heine at blm.gov
Fri Jan 9 23:05:24 CET 2004
Hello -
Have both astronomic and geodetic data sets with values in the form
"ddd:mm:ss.sssss", where dd is an integer between -180 and 180, mm is an
integer between 0 and 60, and ss is a floating-point
number between 0 and 60.0. In order to do anything useful with these
values they need to be turned into their "decimal degree" equivalent.
Assuming the data is a vector y, the following works, sort of:
z<-strsplit(as.character(y),split=":")
zz<-sapply(z,as.numeric)
x<- t(c(1,1/60,1/3600) %*% zz)
Trouble comes if there are any NA's in the data. In this case, R refuses
to coerce zz into matrix form, but leaves it as a "list of lists". How can
the above routine be patched up to pass NAs through?
I can think of some inelegant solutions (e.g. recoding NA as "-200:-1:-1")
but surely there is a better way!
Or is this the wrong technique?
More generally, is there a way to "unzip" a character vector along some
split marker, handling irregulatirites gracefully? For example, from
y<-c("aaa#bbb", "ccc#ddd", "eee","fff"),
strsplit(y,split="#") would produce
c(c("aaa","bbb"), c("ccc","ddd"), c("eee","fff")).
Is there a way to produce instead
c(c("aaa","ccc","eee"),c("bbb","ddd","fff")) ?
Thanks for your assistance.
<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
George Heine, PhD
Mathematical Analyst
National IRM Center
U.S. Bureau of Land Management
voice (303) 236-0099
fax (303) 236-1974
pager (303) 826-8182 or gheine at my2way.com
<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
More information about the R-help
mailing list