【问题标题】:import .csv avoiding conversion to double data in R导入 .csv 避免在 R 中转换为双精度数据
【发布时间】:2020-04-06 12:07:27
【问题描述】:

在我的数据框上使用 fitdistrplus 包的 descdist() 函数时遇到问题。我认为问题来自数据类型:double。我想避免在导入我的 csv 时转换为双精度,但将数据保留为数字(我显然无法使用 as.numeric 将它们转换回来,之后它仍然是双精度)。

这是我导入数据集的代码:

setwd("[directory]")
data=read.csv('data_BehCoor.csv', header=T, sep=";", dec=".", fill=T)

require("fitdistrplus")
descdist(data$stateTSp)

返回以下错误

Error in plot.window(...) : 'xlim' needs finite values

数据的想法:

dput(head(data))
structure(list(day = c(2L, 2L, 2L, 2L, 2L, 2L), 
trial = c(1L, 1L, 1L, 1L, 1L, 1L), ID = structure(c(2L, 2L, 3L, 3L, 4L, 4L), 
.Label = c("", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"),
 class = "factor"), 
condition = structure(c(3L, 3L, 3L, 3L, 2L, 2L), .Label = c("", 
"C", "T"), class = "factor"), gender = structure(c(3L, 2L, 
3L, 2L, 3L, 2L), .Label = c("", "F", "M"), class = "factor"), 
TSp = c(5, 3, 1, 5, 0, 6), AGR = c(3, 0, 0, 0, 0, 0), beAGR = c(0, 
3, 0, 0, 0, 0), FOR = c(27.729, 24.51, 51.459, 37.645, 34.489, 
34.281), FOR_noTSp = c(22.729, 21.51, 50.459, 32.645, 34.489, 
28.281), NI = c(39.857, 82.421, 76.922, 9.277, 265.484, 249.692
), stateTSp = c(55.858, 21.607, 0, 79.961, 0, 2.001), TSpFOR = c(20.345, 
8.408, 0, 0, 0, 0), tot_duration = c(136.967, 136.967, 128.395, 
128.395, 300, 300), OL_FOR = c(3.746, 3.746, 5.002, 5.002, 
10.081, 10.081), OL_FOR_stateTSp = c(4.563, 10.907, 41.703, 
0, 0, 0), OL_FOR_TSpFOR = c(3.372, 1.113, 0, 0, 0, 0), OL_FOR_NI = c(11.041, 
8.496, 2.748, 27.639, 19.655, 18.191), OL_stateTSp_FOR = c(10.907, 
4.563, 0, 41.703, 0, 0), OL_stateTSp = c(3.249, 3.249, 0, 
0, 0, 0), OL_stateTSp_TSpFOR = c(4.034, 0, 0, 0, 0, 0),
OL_stateTSp_NI = c(36.66, 
11.79, 0, 37.249, 0, 2.001), OL_TSpFOR_FOR = c(1.113, 3.372, 
0, 0, 0, 0), OL_TSpFOR_stateTSp = c(0, 4.034, 0, 0, 0, 0), 
OL_TSpFOR = c(0, 0, 0, 0, 0, 0), OL_TSpFOR_NI = c(18.23, 
2.499, 0, 0, 0, 0), overlap_NI_FOR = c(8.496, 11.041, 27.639, 
2.748, 18.191, 19.655), OL_NI_stateTSp = c(11.79, 36.66, 
37.249, 0, 2.001, 0), OL_NI_TSpFOR = c(2.499, 18.23, 0, 0, 
0, 0), OL_NI = c(16.065, 16.065, 6.528, 6.528, 230.021, 230.021
), AGR_in_FOR = c(0, 0, 0, 0, 0, 0), AGR_in_stateTSp = c(0, 
0, 0, 0, 0, 0), AGR_in_TSpFOR = c(0, 0, 0, 0, 0, 0), AGR_in_NI = c(3, 
0, 0, 0, 0, 0), beAGR_in_FOR = c(0, 0, 0, 0, 0, 0), beAGR_in_stateTSp = c(0, 
0, 0, 0, 0, 0), beAGR_in_TSpFOR = c(0, 0, 0, 0, 0, 0), beAGR_in_NI = c(0, 
3, 0, 0, 0, 0), comment = structure(c(1L, 1L, 1L, 1L, 1L, 
1L), 
.Label = c("", "moved the plate too fast"), class = "factor")),
 row.names = c(NA, 6L), class = "data.frame")

提前致谢

【问题讨论】:

  • 恐怕您提供的信息会让社区难以为您提供帮助。您能否提供有关您的数据、您如何使用该功能以及抛出的错误的更多信息?我建议你关注this post
  • 是的,我尝试添加部分数据集作为示例,但找不到如何加入它。^^'
  • 查看第一条评论中的链接。有时复制问题中dput(head(data)) 的结果可能就足够了。
  • 来自您的示例plot(df$stateTSp) 工作正常。我很确定问题不在于双重类型。您可能在df$stateTsp 中有一些NAInf 值。
  • 它导入了最后一行充满 NAs .. 现在很好,谢谢!

标签: r


【解决方案1】:

fitdistrplus::descdist 可以很好地与类型 double 配合使用,见下文:

foo <- runif(50, min = 1, max = 100)
typeof(foo)
fitdistrplus::descdist(foo)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-01
    • 2017-09-29
    • 1970-01-01
    • 2021-06-11
    • 2019-09-22
    • 2015-09-13
    • 2011-07-07
    相关资源
    最近更新 更多