Dear R users, I have huge dataset like the bellow (prepared in notepad in txt format: 31;39;00N+65;40;00E T 36;31;42N+69;04;21E T 34;10;00N+69;41;00E T 34;34;00N+69;06;00E T 31;40;00N+65;44;00E T 35;00;00N+69;07;00E T 34;00;00N+69;53;00E T These are geographical coordinates, degree minute, seconds. latitude longitude 31;39;00N+65;40;00E T I would like to plot them on the map. I would like to know to how separate longitude and longitude from each other and put them into two different columns and then transform the degree minute second into decimal format. Your help very appreciated. Mehdi [[alternative HTML version deleted]]
try this:> input <- read.table(textConnection("31;39;00N+65;40;00E T+ 36;31;42N+69;04;21E T + 34;10;00N+69;41;00E T + 34;34;00N+69;06;00E T + 31;40;00N+65;44;00E T + 35;00;00N+69;07;00E T + 34;00;00N+69;53;00E T"), sep = "+", as.is = TRUE)> closeAllConnections() > result <- NULL > for (i in 1:2){+ # remove trailing letters + x.s <- sub("^([^[:alpha:]]*).*", '\\1', input[[i]]) + x.split <- strsplit(x.s, ";") + x.s1 <- sapply(x.split, function(.coord){ + .coord <- as.numeric(.coord) + .coord[1L] + .coord[2L] / 60 + .coord[3L] / 3600 + }) + result <- cbind(result, x.s1) + }> resultx.s1 x.s1 [1,] 31.65000 65.66667 [2,] 36.52833 69.07250 [3,] 34.16667 69.68333 [4,] 34.56667 69.10000 [5,] 31.66667 65.73333 [6,] 35.00000 69.11667 [7,] 34.00000 69.88333>On Wed, Oct 6, 2010 at 1:51 PM, Mehdi Zarrei <gagzarrei at yahoo.com> wrote:> Dear R users, > > I have huge dataset like the bellow (prepared in notepad in txt format: > > 31;39;00N+65;40;00E T > 36;31;42N+69;04;21E T > 34;10;00N+69;41;00E T > 34;34;00N+69;06;00E T > 31;40;00N+65;44;00E T > 35;00;00N+69;07;00E T > 34;00;00N+69;53;00E T > > These are geographical coordinates, degree minute, seconds. > ? latitude????? longitude > 31;39;00N+65;40;00E T > > I would like to plot them on the map. I would like to know to how separate longitude and longitude from each other and put them into two different columns and then transform the degree minute second into decimal format. > > Your help very appreciated. > > Mehdi > > > > > > > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Another way: library(gsubfn) sapply(lapply(lapply(input, strapply, pattern = "\\d{2}", ~as.numeric(x), simplify = rbind), sweep, MARGIN = 2, STATS = c(1, 60, 3600), '/'), rowSums) On Wed, Oct 6, 2010 at 2:51 PM, Mehdi Zarrei <gagzarrei@yahoo.com> wrote:> Dear R users, > > I have huge dataset like the bellow (prepared in notepad in txt format: > > 31;39;00N+65;40;00E T > 36;31;42N+69;04;21E T > 34;10;00N+69;41;00E T > 34;34;00N+69;06;00E T > 31;40;00N+65;44;00E T > 35;00;00N+69;07;00E T > 34;00;00N+69;53;00E T > > These are geographical coordinates, degree minute, seconds. > latitude longitude > 31;39;00N+65;40;00E T > > I would like to plot them on the map. I would like to know to how separate > longitude and longitude from each other and put them into two different > columns and then transform the degree minute second into decimal format. > > Your help very appreciated. > > Mehdi > > > > > > > > [[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. > >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]