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.lavar...@gmail.com>
Pour :  r-help@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@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.calan...@u-bourgogne.fr

______________________________________________
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