[R] modifying vector elements

Bill.Venables at csiro.au Bill.Venables at csiro.au
Tue Jul 13 09:35:18 CEST 2010

Here is one way

a_clip <-  sub("^([0-9]+\\.[0-9]+\\.[0-9]+).*$", "\\1", a) 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Lorenzo Cattarino
Sent: Tuesday, 13 July 2010 5:20 PM
To: r-help at r-project.org
Subject: [R] modifying vector elements

Hello R-users,


I have a very large vector (a) containing elements consisting of numbers
and letters, this is the  i.e. 


[1] "1.11.2a"     "1.11.2d"     "1.11.2e"     "1.11.2f"     "1.11.2x1"

[7] "1.11.2x2"    "1.11.2x2a"   "1.11.2x2b"   "1.11.2x3"    "1.11.2x4"

[13] "1.11.2x5"    "1.11.3a"     "1.11.3b"     "1.11.3x1"    "1.11.3x1b"

[19] "1.11.3x1d"   "1.12.1x1"    "1.12.1x1b"   "1.12.1x2"    "1.12.1x3"

[25] "1.12.1x4"    "1.3.1x1"     "1.3.4x1"     "1.3.6a"      "1.3.6c"

[31] "1.3.6x1a"    "1.3.6x1b"    "1.3.6x1c"    "1.3.6x1d"    "1.3.6x1e"

[37] "1.3.7a"      "1.3.7b"      "1.3.7c"      "1.3.7d"      "1.5.4a"

[43] "1.5.4x1a"    "1.5.4x1b"    "1.5.4x2"     "1.5.4x3"     "1.5.4x6"

[49] "1.5.6a"      "1.5.6b"      "1.5.6x1"     "1.5.6x2"     "1.5.7a"

[55] "1.5.7x1"     "1.5.7x2"     "1.7.1b"      "1.7.1c"      "1.7.1e"

[61] "1.7.1g"      "1.7.1i"      "1.7.1j"      "1.7.1k"      "1.7.1x1"

[67] "1.7.1x3"     "1.7.1x4"     "1.7.1x5"     "1.7.2b"      "1.7.2x1"


How can I remove from each record everything that is after the number
after the second dot? E.g.:

1.11.2a becomes 1.11.2, 1.12.1x4 becomes 1.12.1, 1.9.1a becomes
1.9.1...and so forth. 






Lorenzo Cattarino

PhD Candidate (Confirmed)


Landscape Ecology and Conservation Group

Centre for Spatial Environmental Research

School of Geography, Planning and Environmental Management

The University of Queensland

Brisbane, Queensland, 4072, Australia

Telephone 61-7-3365 4370, Mobile 0410884610

Email l.cattarino at uq.edu.au

Internet http://www.gpem.uq.edu.au/cser <http://www.gpem.uq.edu.au/cser>


	[[alternative HTML version deleted]]

R-help at r-project.org mailing list
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