Question

I have locality information in a vector that contains [lat.];[long.];[town name];[governorate name];[country name].

I want to create a new vector that includes just the town name for each observation.

Below you can see the contents of the vector for the first four observations.

[1] 36.7416894818782;10.227453200912464;Ben Arous;Gouvernorat de Ben Arous;TN; [2] 37.17652020713887;9.784534661865223;Tinjah;Gouvernorat de Bizerte;TN;
[3] 34.7313;10.763400000000047;Sfax;Sfax;TN;
[4] 34.829474860751915;9.791573033378995;Regueb;Gouvernorat de Sidi Bouzid;TN;

I want to output a vector that looks like:

[1] Ben Arous
[2] Tinjah
[3] Sfax
[4] Regueb

Was it helpful?

Solution

You could use read.table with sep=";":

d <- read.table(textConnection("
36.7416894818782;10.227453200912464;Ben Arous;Gouvernorat de Ben Arous;TN;
37.17652020713887;9.784534661865223;Tinjah;Gouvernorat de Bizerte;TN;
34.7313;10.763400000000047;Sfax;Sfax;TN;
34.829474860751915;9.791573033378995;Regueb;Gouvernorat de Sidi Bouzid;TN;"), 
sep=";", stringsAsFactors=FALSE)

d[, 3]
# [1] "Ben Arous" "Tinjah"    "Sfax"      "Regueb"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top