我正在使用R的Rrd包并且我正在导入rrd文件,并且我希望删除所有具有NaN的记录。
head(rra)
timestamp curr_proc_units entitled_cycles capped_cycles
1480982460 2016-12-05 18:01:00 NaN NaN NaN
1480982520 2016-12-05 18:02:00 NaN NaN NaN
1480982580 2016-12-05 18:03:00 NaN NaN NaN
1480982640 2016-12-05 18:04:00 NaN NaN NaN
1480982700 2016-12-05 18:05:00 NaN NaN NaN
1480982760 2016-12-05 18:06:00 NaN NaN NaN
uncapped_cycles
1480982460 NaN
1480982520 NaN
1480982580 NaN
1480982640 NaN
1480982700 NaN
1480982760 NaN
头部全部都是NaN,但其余的都没有。
#!/usr/bin/env Rscript
# libraries
library(lubridate, quietly = TRUE)
library(plyr, quietly = TRUE)
library(dplyr, quietly = TRUE)
library(chron, quietly = TRUE)
library(ggplot2, quietly = TRUE)
library(Rrd, quietly = TRUE)
library(plyrmr, quietly = TRUE)
rra = importRRD("/kathryn/rdc1vsip8/rdc1vsiphmc3/rdc1vpc1lpr56.rrm", "AVERAGE", 1480982400, 1486598400, 2)
rra$timestamp <- as.POSIXct(as.numeric(rra$timestamp), origin = "1970-01-01")
rra = rra[!is.nan(rra)];
我的错误是:is.nan(rra)中的错误:类型'list'没有实现默认方法
那么如何将我的列表转换为可以取出NaN值的内容呢?
答案 0 :(得分:0)
修正@Dason回答rra <- rra[!is.nan(rra$yourcolumn), ]
之后我指定了一列,它也读了其他列。谢谢你的帮助。
答案 1 :(得分:0)
这是您的数据集的可重现版本。
timestamps <- seq(Sys.time() - 3600, Sys.time(), by = "1 min")
n <- length(timestamps)
rra <- data.frame(
timestamp = timestamps,
curr_proc_units = runif(n),
entitled_cycles = runif(n)
)
rra <- within(
rra,
{
curr_proc_units[sample(n, 10)] <- NaN
entitled_cycles[sample(n, 10)] <- NaN
}
)
以下是使用dplyr
filter()
功能的解决方案。
library(dplyr)
rra %>%
filter(
!is.nan(curr_proc_units),
!is.nan(entitled_cycles)
)