Skip to content
Prev 65173 / 398506 Next

part of name to Date

Here is one way

x <- c( "VGT1_CONTR_B020020301.H0V0.MIR", 
	"VGT1_VGT2_CONTR_B020020611.H0V0.MIR", 
	"VGT1_VGT2_CONTR_B020030401.H0V0.MIR", 
	"VGT1_VGT2_CONTR_B020030711.H0V0.MIR", 
	"VGT1_VGT2_CONTR_B020031211.H0V0.MIR" )

( tmp1 <- sapply( strsplit(x, split="_"), tail, n=1 ) )
[1] "B020020301.H0V0.MIR" "B020020611.H0V0.MIR" "B020030401.H0V0.MIR"
[4] "B020030711.H0V0.MIR" "B020031211.H0V0.MIR"

( tmp2 <- sapply( strsplit( tmp1, split="\\." ), head, n=1 ) )
[1] "B020020301" "B020020611" "B020030401" "B020030711" "B020031211"

gsub( "B", "", tmp2 )
[1] "020020301" "020020611" "020030401" "020030711" "020031211"
 

Here is another approach using regular expressions. Please be careful
with my one-liner as I am no expert in this. Maybe someone on the list
can point if there are any errors 
	gsub(".*\_B?(.*)\\.H.*", "\\1", x)


If you want reliability, go with the first suggestion.

Regards, Adai
On Tue, 2005-03-01 at 13:36 +0100, Jonathan Charrier wrote: