[R] Fwd: help to slip a file name using "strsplit" function

Ivan Calandra ivan.calandra at u-bourgogne.fr
Wed Jan 25 16:40:15 CET 2012


Hi Gianni,

Your first example works fine, though you have unnecessary stuff in it:
strsplit("Myfile_MyArea1_sample1.txt", "_")
[[1]]
[1] "Myfile"      "MyArea1"     "sample1.txt"

The second example doesn't work because of two things: the period is a 
special character, and the fixed argument should be false:
strsplit("Myfile_MyArea1_sample1.txt", "\\.")
[[1]]
[1] "Myfile_MyArea1_sample1" "txt"

HTH,
Ivan


-------- Message original --------
Sujet: 	[R] help to slip a file name using "strsplit" function
Date : 	Wed, 25 Jan 2012 16:26:11 +0100
De : 	gianni lavaredo <gianni.lavaredo at gmail.com>
Pour : 	r-help at r-project.org



Dear Researchers,

I have several files as this example: Myfile_MyArea1_sample1.txt

i wish to split in "Myfile", "MyArea1", "sample1", and "txt", becasue i
need to use "sample1" label. I try to use "strsplit" but I am able just to
split as "Myfile_MyArea1_sample1" and "txt" OR "Myfile", "MyArea1",
"sample1.txt" using


strsplit(as.character("Myfile_MyArea1_sample1.txt"), ".", fixed = TRUE)
strsplit(as.character("Myfile_MyArea1_sample1.txt"), "_", fixed = TRUE)

Thanks in advance

Gianni

	[[alternative HTML version deleted]]

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




-- 
Ivan CALANDRA
Université de Bourgogne
UMR CNRS/uB 6282 Biogéosciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calandra at u-bourgogne.fr



More information about the R-help mailing list