Tena koe Sadz One way:
tt <- c('122:45:45','-69:38:27') tt <- lapply(strsplit(tt,':'), as.numeric) lapply(tt, function(x) x[1]+((x[1]>0)-0.5)*(x[2]+x[3]/60)/30) To understand how this work you might need to break up the bits. HTH .... Peter Alspach > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Sadz A > Sent: Tuesday, 17 August 2010 11:43 a.m. > To: r-help@r-project.org > Subject: [R] Changing latitude data to decimal degrees > > Hi All, > > I have location data set up as degrees: minutes: seconds (for example, > 122:45:45) I need to get this data into decimal degree form (eg, > 122.7625). > > I know that I need to use the formula: > > Decimal degrees = Degrees + (Minutes/60) + (Seconds/3600) > > Does anyone know how I can get R to do this? > The original data is all in one column (called 'lat') and the degrees, > mins and > secs are divided by ':' > There are some values that are negative (eg -69:38:27), I think in > these > instances I need to do the calculation in the positive then multiply it > by -1 to > make it negative again, the only problem is the positive and negative > data are > all intermingled, is there a way around this too? > I have R version 2.10.1 on a windows vista computer. > > I could do it manually but I have like 20,000 entries and would really > like a > little code to automate the conversion. > > I have tried Microsoft Access and Excel, but because the data is not > stored in > 3 columns I cannot get it to work, I figured R was my best option but I > cant get > it to work. It should be really simple but I'm new to R so would > really appreciate help. > > Thank you for reading my plea, > Please contact me if you need any more details > Any and all help is greatly appreciated, > sadz > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.