R:在R中重新排序多个文件路径
我有100个文件,每个文件命名为“ ABC -Day -1(至100).csv”。
当我将它们读成R时,它是这样的:Day1,Day10,Day100等(请参见图1)。我知道R是这样做的,因为它是按字符对其进行排序,而不是按数字对其进行排序。有没有办法可以在数值正确的顺序(Day1,Day2,Day3,...)中重新排序路径,而无需我实际上必须手动更改我的原始文件名?
这是我到目前为止所拥有的:
filenames <- list.files(path="../STEP_ONE/Test_raw",
pattern="ADD_Day+.*sav",
full.names = TRUE) # Reads in path of the 100 files
I have 100 files, each named "ABC - Day - 1(to 100).csv".
When I read them into R, it is ordered like this: Day1, Day10, Day100, etc. (see figure 1). I know R does this because it is sorting it by character, not by number. Is there a way that I could reorder the path in numerically correct order (Day1, Day2, Day3, ...) without me actually having to manually change my raw file names?
Here is what I have so far:
filenames <- list.files(path="../STEP_ONE/Test_raw",
pattern="ADD_Day+.*sav",
full.names = TRUE) # Reads in path of the 100 files
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我们假设您有一个带有文件名的向量
v
(根据您所说的___ day __. sav
)。您可以减去一天的数量,并使用以下代码重新排序名称:Let’s suppose you have a vector
v
with the names of your file (according to what you said,___Day__.sav
). You can subtract the number of the day and reorder the names with the following code: