尝试删除 NaN 时出错
Error when trying the remove NaN
我正在使用 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 值的东西?
修复了上面的@Dason 回答 rra <- rra[!is.nan(rra$yourcolumn), ]
在我指定了一列之后它也读取了其他列。谢谢你的帮助。
这是您的数据集的可重现版本。
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)
)
我正在使用 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 值的东西?
修复了上面的@Dason 回答 rra <- rra[!is.nan(rra$yourcolumn), ]
在我指定了一列之后它也读取了其他列。谢谢你的帮助。
这是您的数据集的可重现版本。
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)
)