在具有特定条件的r中对数据帧进行分组

时间:2018-05-08 19:20:20

标签: r

我有一个包含两列的数据框 - " Time"和"价值"在"时间"中有不连续的数据。如何选择"值"中的前10个最大值?至少在"时间" 3个单位?在将数据帧转换为向量之后,我尝试使用findPeaks函数,但它似乎没有帮助。这是我试过的代码:

Fulldata <- data.frame(x)

y <- subset(Fulldata, c(Time > 181.4 & Time < 181.69 | Time > 251 & Time < 251.84 | Time > 264.83 & Time < 265.28 ...... .... Time > 778.75 & Time < 779.45 | Time > 851.45 & Time < 852.22 ))

yvector <- as.vector(y$value)

peakmatrix <- findpeaks(yvector, minpeakdistance = 300, sortstr = TRUE)    
peakmatrix

dput(head(y, 50)) structure(list(Time = c(181.41, 181.42, 181.43, 181.44, 181.45, 181.46, 181.47, 181.48, 181.49, 181.5, 181.51, 181.52, 181.53, 181.54, 181.55, 181.56, 181.57, 181.58, 181.59, 181.6, 181.61, 181.62, 181.63, 181.64, 181.65, 181.66, 181.67, 181.68, 251.01, 251.02, 251.03, 251.04, 251.05, 251.06, 251.07, 251.08, 251.09, 251.1, 251.11, 251.12, 251.13, 251.14, 251.15, 251.16, 251.17, 251.18, 251.19, 251.2, 251.21, 251.22), value = c(0.0391672, 0.0426035, 0.0428215, 0.0420676, 0.0471682, 0.0503162, 0.045388, 0.0356645, 0.0302182, 0.0287721, 0.0254405, 0.0237114, 0.0221648, 0.0237992, 0.0250306, 0.0262008, 0.0260725, 0.0227329, 0.0228227, 0.0218701, 0.021884, 0.02352, 0.0256086, 0.0258213, 0.026324, 0.0271051, 0.0280477, 0.0269339, 0.017347, 0.0176336, 0.0187158, 0.0192151, 0.0194258, 0.0168017, 0.0152756, 0.0152147, 0.0157609, 0.0170017, 0.0170792, 0.0193993, 0.0259839, 0.0312447, 0.0356666, 0.0385061, 0.0423352, 0.0460978, 0.0476292, 0.0462294, 0.0439847, 0.0412032)), .Names = c("Time", "value"), row.names = c(18142L, 18143L, 18144L, 18145L, 18146L, 18147L, 18148L, 18149L, 18150L, 18151L, 18152L, 18153L, 18154L, 18155L, 18156L, 18157L, 18158L, 18159L, 18160L, 18161L, 18162L, 18163L, 18164L, 18165L, 18166L, 18167L, 18168L, 18169L, 25102L, 25103L, 25104L, 25105L, 25106L, 25107L, 25108L, 25109L, 25110L, 25111L, 25112L, 25113L, 25114L, 25115L, 25116L, 25117L, 25118L, 25119L, 25120L, 25121L, 25122L, 25123L), class = "data.frame")

0 个答案:

没有答案