0

I have a dataset consisting of 2000 sequences of 3 numbers, ranging from 1 to 50 (for example, (2,11,35) or (8,20,49)). The data is in a .csv file, which R reads as a dataframe - 2000 obs. of 3 variables, all intergers.

I want to convert the data into a 3d array of 'frames', where every frame consists of the last 25 sequences. A keras model with 2d conv layers will then learn to predict the 26th sequence.

I tried loading the dataset using as.matrix(read.csv()), and then

x<-dataset[1:25,]
for (i in 2:(nrow(dataset)-24)) {
x<-rbind(x, dataset[i:(i+24),])
}
x<-array_reshape(x,c(1976,25,3,1))

The data seems to come out with the correct shape, but when I compare it with the original I see that the numbers are all out of order. Using dim() also did not help.

Could anyone please help?

macunaima
  • 13
  • 5
  • 1
    Can you please provide small reproducible example? Have a look at https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – MKR May 22 '18 at 05:59
  • 1
    Thanks for the link. It was very helpful as this was my first question on here. – macunaima Jun 23 '18 at 22:06

1 Answers1

0

I'm not sure I fully understand the question, but wouldn't using a list work? The order of the elements should stay the same.

results = list()
results[[1]]<-dataset[1:25,]

for(i in 2:(nrow(dataset)-24)){
   results[[i]] = dataset[i:(i+24),]
}
Fino
  • 1,774
  • 11
  • 21
  • For some reason keras could not recognize that as an array. I did find some typos in my code, however, and used dim() instead of array_reshape(). That seemed to do the trick. Thanks, either way! – macunaima Jun 23 '18 at 22:08