我有一个文件路径的字符向量:
> tail(paths)
[1] "/home/username/data/dir/GCZ98/GCZ98_1998_12_16.asc.gz"
[2] "/home/username/data/dir/GCZ98/GCZ98_1998_12_20.asc.gz"
[3] "/home/username/data/dir/GCZ99/GCZ99_1999_12_21.asc.gz"
[4] "/home/username/data/dir/GCZ99/GCZ99_1999_12_23.asc.gz"
[5] "/home/username/data/dir/GCZ99/GCZ99_1999_12_27.asc.gz"
[6] "/home/username/data/dir/GCZ99/GCZ99_1999_12_28.asc.gz"
我想按父文件夹名称将其拆分为向量列表,即:
> tail(desired)
$ "/home/username/data/dir/GCZ98"
[1] "/home/username/data/dir/GCZ98/GCZ98_1998_12_16.asc.gz"
[2] "/home/username/data/dir/GCZ98/GCZ98_1998_12_20.asc.gz"
$ "/home/username/data/dir/GCZ98"
[1] "/home/username/data/dir/GCZ99/GCZ99_1999_12_21.asc.gz"
[2] "/home/username/data/dir/GCZ99/GCZ99_1999_12_23.asc.gz"
[3] "/home/username/data/dir/GCZ99/GCZ99_1999_12_27.asc.gz"
[4] "/home/username/data/dir/GCZ99/GCZ99_1999_12_28.asc.gz"
我已经尝试过使用split
并且strsplit
几乎没有成功,但我正在努力尝试找到一个满足我需求的正则表达式。
谢谢你的帮助