arrays - filling the gaps in a table -


i have 2 tables. 1 has info 2012 till 2014 period of 3 hours. looks this:

1   01.06.2012 00:00    10  0    2   01.06.2012 03:00    10  0    3   01.06.2012 06:00    10  6    4   01.06.2012 09:00    7,5 0    5   01.06.2012 12:00    6   2,5  6   01.06.2012 15:00    6   0    7   01.06.2012 18:00    4   0    8   01.06.2012 21:00    4   0    9   02.06.2012 00:00    0   0    10  02.06.2012 03:00    0   0    

the other table same time period of 1 minute , has no data.

1   01.06.2012 00:00    3   1    2   01.06.2012 00:01    3   1    3   01.06.2012 00:01    3   1    4   01.06.2012 00:03    3   1    5   01.06.2012 00:03    3   1    6   01.06.2012 00:05    3   1    7   01.06.2012 00:05    3   1    8   01.06.2012 00:07    3   1    9   01.06.2012 00:08    3   1    10  01.06.2012 00:09    3   1    11  01.06.2012 00:10    3   1 

now, need values of 2nd , 3rd rows of second table correlate first, if timestamp second table between timestamp(i) , timestamp(i+1) of first table take b(i) , c(i) , copy them. have code, can see above doesn't put right values in. 3 & 1 instead of 10 & 0.

clouds <- read.csv('~/2012-2014 clouds info.csv', sep=";", header = false) cloudfull <- read.csv('~/2012-2014 clouds.csv', sep=";", header = false)  (i in 1:nrow(cloudfull)){   dateone <- strptime(cloudfull[i,1], '%d.%m.%y %h:%m')    (j in 1:nrow(clouds)){     bottomdate = strptime(clouds[j,1], '%d.%m.%y %h:%m')     upperdate = strptime(clouds[j+1,1], '%d.%m.%y %h:%m')     if  ((dateone >= bottomdate) && (dateone < upperdate)) {       cloudfull[i,2] <- clouds[j,2]       cloudfull[i,3] <- clouds[j,3]       break      }     } }  write.csv(cloudfull, file = 'cc.csv') 

what do?

following may helpful:

ddf = rbind(df1, df2) ddf$v2 = as.date(as.character(ddf$v2), format="%d.%m.%y") ddf = cbind(ddf, do.call(rbind, strsplit(as.character(ddf$v3),':'))) ddf = ddf[order(ddf$"1",ddf$"2"),] ddf = ddf[!duplicated(ddf$v3),] ddf    v1         v2    v3 v4 v5  1  2 1   1 2012-06-01 00:00 10  0 00 00 12  2 2012-06-01 00:01  3  1 00 01 14  4 2012-06-01 00:03  3  1 00 03 16  6 2012-06-01 00:05  3  1 00 05 18  8 2012-06-01 00:07  3  1 00 07 19  9 2012-06-01 00:08  3  1 00 08 20 10 2012-06-01 00:09  3  1 00 09 21 11 2012-06-01 00:10  3  1 00 10 2   2 2012-06-01 03:00 10  0 03 00 3   3 2012-06-01 06:00 10  6 06 00 4   4 2012-06-01 09:00  7  5 09 00 5   5 2012-06-01 12:00  6  2 12 00 6   6 2012-06-01 15:00  6  0 15 00 7   7 2012-06-01 18:00  4  0 18 00 8   8 2012-06-01 21:00  4  0 21 00 

columns '1' , '2' v3 , can removed command:

ddf = ddf[,-c(6,7)] 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -