【发布时间】:2017-10-25 12:29:20
【问题描述】:
我有一张田野地图,我在其中拍摄了地块的图像。照片是从左到右拍摄的,像这样蜿蜒曲折;所以,从 101, 118, 119, 136,137,138,135,120,117,102,103,116...等。图片也按此顺序排列;但是,它们的名称与绘图不对应,文件名看起来像这样 100_498、100_499、100_500、100_501。因此,为了获得更多详细信息,情节 101 等于文件 100_498,情节 118 等于文件 100_499 等...我需要能够根据他们在现场拍摄照片的方式将文件重命名为它们对应的情节。下面的地图。如果我用我的代码重命名它们,它会从上到下,因为它是蛇形的,所以图片在文件夹中是有序的。
现在我需要重新编写 R 代码...有什么建议吗??? 我需要重命名这些文件,使其与此图相对应。
这是我的代码,如果他们会从下到上获取数据并蜿蜒曲折... 101、102、103、104、105、106、107、108、109、110、111、112..等等。
Plot map
109 110 127 128 145
108 111 126 129 144
107 112 125 130 143
106 113 124 131 142
105 114 123 132 141
104 115 122 133 140
103 116 121 134 139
102 117 120 135 138
101 118 119 136 137
f <-list.files(pattern="*.JPG") #imports files names
head(f) #first 6 rows of data
new_names <- paste("Plot_", #create new file name
formatC(seq(length(file_names)), #writes the number in
#sequential order
width=2,flag="0"),
".JPG",sep="")
head(new_names) #first 6 rows of data
file.rename(from=f, to=new_names) #replaces old file name with new file name
list.files(pattern=".JPG") #check to make sure it was done
【问题讨论】: