Changing File Names In R
1
0
Entering edit mode
10.0 years ago
HNK ▴ 150

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 • 3.2k views
ADD COMMENT
4
Entering edit mode
10.0 years ago
xb ▴ 420
> 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?

ADD COMMENT
0
Entering edit mode

Thakuuu soo much :)

ADD REPLY

Login before adding your answer.

Traffic: 3824 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6