This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Changing File Names In R

Hey i am trying to change the file names. I have like 86 files and used list.files(path="...") to get a charachter vector of file names.

exon_counts__htseq__20130607-H23761_2_L7.D702.counts exon_counts__htseq__20130607-H23761_7B1_L7.D702.counts exon_counts__htseq__20130607-H23761_105_L7.D702.counts exon_counts__htseq__20130607-H23761_23_L7.D702.counts

the file names are like these.. i know in R file.rename(from=from.files, to=to.files) this function is used to rename the files. But i want to have the file names just as 2.counts, 7B1.counts, 105.counts, 23.counts

Wil be thankyou if you can help

r

1 answer

> gsub("^.+_([^_]+)_[^_]+.counts","\\1.counts",c("exon_counts__htseq__20130607-H23761_2_L7.D702.counts","exon_counts__htseq__20130607-H23761_7B1_L7.D702.counts","exon_counts__htseq__20130607-H23761_105_L7.D702.counts","exon_counts__htseq__20130607-H23761_23_L7.D702.counts"))
[1] "2.counts"   "7B1.counts" "105.counts" "23.counts"

However, do you know stackoverflow is more appropriate for such questions?

Thakuuu soo much :)

Log in to answer this question.