1

I have a list of 12 rasters:

IN_folder_S2 <- "T:\\New_SM\\Indices_UXC"
IN.files_S2 <- dir(IN_folder_S2, pattern= "_11.tif$",full.names = T)
IN.files_S2

IN.files_S2
 [1] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_137_30UXC_ARVI_11.tif"  
 [2] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_137_30UXC_GNDVI_11.tif" 
 [3] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_137_30UXC_IRECI_11.tif" 
 [4] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_137_30UXC_MSAVI2_11.tif"
 [5] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_137_30UXC_MTCI_11.tif"  
 [6] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_137_30UXC_NDI45_11.tif" 
 [7] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_137_30UXC_NDVI_11.tif"  
 [8] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_137_30UXC_NDWI_11.tif"  
 [9] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_137_30UXC_NDWI2_11.tif" 
[10] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_bbb_30UXC_SAVI0_11.tif" 
[11] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_bbb_30UXC_SAVI1_11.tif" 
[12] "T:\\New_SM\\Indices_UXC/S2A2A_20191118_bbb_30UXC_SAVI2_11.tif" 

After I stacked them:

INDEX_Nov19 <- stack(IN.files_S2)

the number of layers increased

   > names(INDEX_Nov19)
 [1] "S2A2A_20191118_137_30UXC_ARVI_11"    "S2A2A_20191118_137_30UXC_GNDVI_11.1"
 [3] "S2A2A_20191118_137_30UXC_GNDVI_11.2" "S2A2A_20191118_137_30UXC_IRECI_11.1"
 [5] "S2A2A_20191118_137_30UXC_IRECI_11.2" "S2A2A_20191118_137_30UXC_MSAVI2_11" 
 [7] "S2A2A_20191118_137_30UXC_MTCI_11.1"  "S2A2A_20191118_137_30UXC_MTCI_11.2" 
 [9] "S2A2A_20191118_137_30UXC_NDI45_11.1" "S2A2A_20191118_137_30UXC_NDI45_11.2"
[11] "S2A2A_20191118_137_30UXC_NDVI_11"    "S2A2A_20191118_137_30UXC_NDWI_11"   
[13] "S2A2A_20191118_137_30UXC_NDWI2_11"   "S2A2A_20191118_bbb_30UXC_SAVI0_11"  
[15] "S2A2A_20191118_bbb_30UXC_SAVI1_11"   "S2A2A_20191118_bbb_30UXC_SAVI2_11"  

I have applied the same method for other files and it worked well.

1

Some of your files have more than one layer themselves, so they contribute more than one layer to the final stack. R gives them names with .1 and .2 and so on. eg GNDVI and IRECI but not ARVI:

 [1] "S2A2A_20191118_137_30UXC_ARVI_11"    "S2A2A_20191118_137_30UXC_GNDVI_11.1"
 [3] "S2A2A_20191118_137_30UXC_GNDVI_11.2" "S2A2A_20191118_137_30UXC_IRECI_11.1"
 [5] "S2A2A_20191118_137_30UXC_IRECI_11.2" "S2A2A_20191118_137_30UXC_MSAVI2_11" 
1
  • I see, thank you so much! – user166416 Jul 1 '20 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.