Here is one way

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

-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Lorenzo Cattarino
Sent: Tuesday, 13 July 2010 5:20 PM
To: r-help@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. 

a

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

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

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

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

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

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

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

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

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

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

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

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

 

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. 

 

Thanks

 

Lorenzo

 

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.cattar...@uq.edu.au

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


 


        [[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.

Reply via email to