i need vector repeats numbers in sequence @ varying intervals. need this
c(rep(1:42, each=6), rep(43:64, each = 7), rep(65:106, each=6), rep(107:128, each = 7), .... need keep going, until 2 million. want vector looks
[1] 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 5 ... ..... [252] 43 43 43 43 43 43 43 44 44 44 44 44 44 44 .... [400] 64 64 64 64 64 64 65 65 65 65 65 65... and on. not alternating between 6 , 7 repetitions, rather 6s , fewer 7s until whole vector 1.7 million rows. so, there loop can do? or apply, replicate? need 400th entry in vector 64, 800th entry 128, , on, in evenly spaced integers.
update
thank quick clever tricks there. worked, @ least enough deadline dealing with. realize repeating 6 xs , 7 xs dumb way try solve this, quick @ least. have time, everyone's opinions /ideas on real underlying issue here.
i have 2 datasets merge. both sensor datasets, both stopwatch time primary keys. 1 records every 1/400 of second, , other records every 1/256 of second. have trimmed top of each starting exact same moment. but.. what? have 400 records each second in 1 set, , 256 records 1 second in other. there way merge these without losing data? interpolating or repeating obs a-ok, necessary, think, i'd rather not throw data out. read this post here, had using xts , zoo similar problem mine. have nice epoch date/times each. have these awful fractions of seconds!
sample data (a): time dist a_lat 1 139.4300 22 0 2 139.4325 22 0 3 139.4350 22 0 4 139.4375 22 0 5 139.4400 22 0 6 139.4425 22 0 7 139.4450 22 0 8 139.4475 22 0 9 139.4500 22 0 10 139.4525 22 0 sample data (b): timestamp hex_acc_x hex_acc_y hex_acc_z 1 367065215501 -0.5546875 -0.7539062 0.1406250 2 367065215505 -0.5468750 -0.7070312 0.2109375 3 367065215509 -0.4218750 -0.6835938 0.1796875 4 367065215513 -0.5937500 -0.7421875 0.1562500 5 367065215517 -0.6757812 -0.7773438 0.2031250 6 367065215521 -0.5937500 -0.8554688 0.2460938 7 367065215525 -0.6132812 -0.8476562 0.2109375 8 367065215529 -0.3945312 -0.8906250 0.2031250 9 367065215533 -0.3203125 -0.8906250 0.2226562 10 367065215537 -0.3867188 -0.9531250 0.2578125 (oh yeah, , btw, b dataset timestamps epoch format * 256, because life hard. haven't converted because dataset has nothing that, 0.0025 intervals. b data sensor left on hours later data sensor turned off, doesn't help)
now put way ... have absolutely no idea how planning on using of 6s , 7s. :-)
regardless, recommend standardizing time, adding "sample" column, , merging on them. having "sample" column may facilitate processing later on, perhaps.
your data:
df400 <- structure(list(time = c(139.43, 139.4325, 139.435, 139.4375, 139.44, 139.4425, 139.445, 139.4475, 139.45, 139.4525), dist = c(22l, 22l, 22l, 22l, 22l, 22l, 22l, 22l, 22l, 22l), a_lat = c(0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l)), .names = c("time", "dist", "a_lat"), class = "data.frame", row.names = c(na, -10l)) df256 <- structure(list(timestamp = c(367065215501, 367065215505, 367065215509, 367065215513, 367065215517, 367065215521, 367065215525, 367065215529, 367065215533, 367065215537), hex_acc_x = c(-0.5546875, -0.546875, -0.421875, -0.59375, -0.6757812, -0.59375, -0.6132812, -0.3945312, -0.3203125, -0.3867188), hex_acc_y = c(-0.7539062, -0.7070312, -0.6835938, -0.7421875, -0.7773438, -0.8554688, -0.8476562, -0.890625, -0.890625, -0.953125), hex_acc_z = c(0.140625, 0.2109375, 0.1796875, 0.15625, 0.203125, 0.2460938, 0.2109375, 0.203125, 0.2226562, 0.2578125)), .names = c("timestamp", "hex_acc_x", "hex_acc_y", "hex_acc_z"), class = "data.frame", row.names = c(na, -10l)) standardize time frames:
colnames(df256)[1] <- 'time' df400$time <- df400$time - df400$time[1] df256$time <- (df256$time - df256$time[1]) / 256 assign label easy reference (not nas won't clear enough):
df400 <- cbind(sample='a', df400, stringsasfactors=false) df256 <- cbind(sample='b', df256, stringsasfactors=false) and merge , sorting:
dat <- merge(df400, df256, by=c('sample', 'time'), all.x=true, all.y=true) dat <- dat[order(dat$time),] dat ## sample time dist a_lat hex_acc_x hex_acc_y hex_acc_z ## 1 0.000000 22 0 na na na ## 11 b 0.000000 na na -0.5546875 -0.7539062 0.1406250 ## 2 0.002500 22 0 na na na ## 3 0.005000 22 0 na na na ## 4 0.007500 22 0 na na na ## 5 0.010000 22 0 na na na ## 6 0.012500 22 0 na na na ## 7 0.015000 22 0 na na na ## 12 b 0.015625 na na -0.5468750 -0.7070312 0.2109375 ## 8 0.017500 22 0 na na na ## 9 0.020000 22 0 na na na ## 10 0.022500 22 0 na na na ## 13 b 0.031250 na na -0.4218750 -0.6835938 0.1796875 ## 14 b 0.046875 na na -0.5937500 -0.7421875 0.1562500 ## 15 b 0.062500 na na -0.6757812 -0.7773438 0.2031250 ## 16 b 0.078125 na na -0.5937500 -0.8554688 0.2460938 ## 17 b 0.093750 na na -0.6132812 -0.8476562 0.2109375 ## 18 b 0.109375 na na -0.3945312 -0.8906250 0.2031250 ## 19 b 0.125000 na na -0.3203125 -0.8906250 0.2226562 ## 20 b 0.140625 na na -0.3867188 -0.9531250 0.2578125 i'm guessing data small representation. if i've guessed poorly (that a's integers seconds , b's integers 1/400ths of second) scale differently. either way, resetting first value 0 , merging/sorting, easy merge , sort.
Comments
Post a Comment