List modis files per day

0

I need to make a fusion of raster images with terra and aqua satellites of modis in R. To carry out the cycle I must have the same length of the satellite vectors, however for terra I have 6031 images and for aqua 5277. I do not know how to create a data.frame only with the images in common that share the day, and leave out those that are unique (without a partner).

library(raster)
library(MODIS)

setwd("C:/Composite")

#Directorio Terra
mypath1<-"C:/Reclass_MOD"
myras1<-list.files(path=mypath1,pattern = glob2rx("*.tif$"), ## nc es la extension de HDF
                    full.names = TRUE, recursive = TRUE)
name<-substr(myras8,16,31)

files1 <- stack(myras1)
date1<-extractDate(files1,asDate=TRUE,pos1=10,pos2=16,format= "%Y%j")

#Directorio Aqua
mypath2<-"C:/Reclass_MYD"
myras2<-list.files(path=mypath2,pattern = glob2rx("*.tif$"), ## nc es la extension de HDF
                    full.names = TRUE, recursive = TRUE)
name1<-substr(myras2,16,31)

files2 <- stack(myras2)
date2<-extractDate(files2,asDate=TRUE,pos1=10,pos2=16,format= "%Y%j")

> data.frame(date1$inputLayerDates,date2$inputLayerDates)
Error in data.frame(date1$inputLayerDates, date2$inputLayerDates) : 
  arguments imply differing number of rows: 6031, 5277
    
asked by tmsppc 05.03.2017 в 06:05
source

1 answer

0

You can use the function %in% to find the dates in common between date1 and date2.

comun <- date1$inputLayerDates %in% date2$inputLayerDates

Then you can use common to create a new data frame.

data.frame(date1[comun, "inputLayerDates"], date2[comun, "inputLayerDates"])

In general, it is easier to use the merge function to combine data frames.

merge(date1, date2, by = "columna(s) en común")

But the code you provide does not allow knowing the structure of your data.

    
answered by 06.03.2017 / 18:10
source