[R] Splitting coordinates into two

Pancho Mulongeni p.mulongeni at namibia.pharmaccess.org
Mon Jul 8 17:59:05 CEST 2013


Thank you,
So my mistake was my data was a factor and not character,for strsplit
Thanks so much 

-----Original Message-----
From: Rui Barradas [mailto:ruipbarradas at sapo.pt] 
Sent: 08 July 2013 15:55
To: Pancho Mulongeni
Cc: r-help at r-project.org
Subject: Re: [R] Splitting coordinates into two

Hello,

Try the following

x <- structure(...)


sp <- strsplit(as.character(x), ",")
G1 <- sapply(sp, `[`, 1)
G2 <- sapply(sp, `[`, 2)


Hope this helps,

Rui Barradas

Em 08-07-2013 14:49, Pancho Mulongeni escreveu:
> Hi users,
> I have a simple vector of five coordinates in form of ('lat1, 
> long1','lat2,long2',...,'latn,longn')
> And I would like to create two vectors, one just with the first 
> coordinate
> G1<-c('lat1,'lat2',..,'latn')
> G2<-c('long1,'long2',...,'longn')
>
> I am trying to apply strsplit(x=g,split=',') on my object g, but it is not working, any help?
> I struggle to understand how to use the regular expressions.
> structure(c(32L, 38L, 40L, 34L, 27L), .Label = 
> c("-17.394217,15.886574", "-17.406994,14.393463", 
> "-17.491495,14.992905", "-17.5005,24.274635", "-17.776151,15.765724", 
> "-17.779911,15.699806", "-17.905569,15.977211", 
> "-17.921576,19.758911", "-18.607204,17.166481", 
> "-18.804918,17.046661", "-18.805731,16.940403", 
> "-19.030476,16.467304", "-19.12441,13.616567", "-19.163006,15.916443", 
> "-19.243736,17.710304", "-19.562702,18.11697", "-19.6303,17.342606", 
> "-19.939787,13.013306", "-20.107201,16.154966", 
> "-20.363618,14.965954", "-20.460469,16.652012", 
> "-20.484914,17.233429", "-21.256102,17.869263", 
> "-21.418555,15.949402", "-21.491128,17.853234", 
> "-21.943046,17.363892", "-21.980459,16.91328", "-22.000992,15.582733", 
> "-22.084367,16.750031", "-22.182318,17.072754", 
> "-22.447841,18.962746", "-22.576608,17.07859", "-22.649502,14.532166", "-22.832516,17.183304", "-22.934365,14.521008", "-22.947328,14.508991", "-24.477775,15.801086", "-24.621739,17.959728", "-25.460983,19.438198", "-26.567955,18.134651", "-26.645292,15.153944", "-27.915553,17.490921", "-28.017742,18.745594"
> ), class = "factor")
>
> Pancho Mulongeni
> Research Assistant
> PharmAccess Foundation
> 1 Fouché Street
> Windhoek West
> Windhoek
> Namibia
>
> Tel:   +264 61 419 000
> Fax:  +264 61 419 001/2
> Mob: +264 81 4456 286
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list