读取有关 r 中不同行数的数据集时出错? [英] Error reading dataset regarding differing number of rows in r?

查看:48
本文介绍了读取有关 r 中不同行数的数据集时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 d857 的数据集,其中包含大约 90000 行的 2 个变量.以下是 d857 的示例:

I have a dataset called d857 with about 90000 rows of 2 variables. Here is an example of d857:

             datetime  light
1 2013-05-21 23:10:27 10.220
2 2013-05-21 23:15:27  7.949
3 2013-05-21 23:20:27  5.678
4 2013-05-21 23:25:27  3.407
5 2013-05-21 23:30:27  3.407 

我正在尝试从 Geolight 包中执行 twilightCalc 函数.当我执行该功能时,我收到错误:

I am attempting to perform the twilightCalc function from the Geolight package. When I perform the function I receive the error:

Error in data.frame(id = 1:nrow(smooth), smooth) : 
  arguments imply differing number of rows: 2, 0

我在 d857 的不同部分执行了该功能,但得到了不同的结果.该函数适用于 d857[1:27873,],但在超过该数字的任何部分都会收到错误,但也适用于 d857[80000:90000,].我检查了其文件中的数据集,没有看到任何异常值.什么可能导致此错误,我该如何解决?

I performed the function on different portions of d857 and have had differing results. The function works on d857[1:27873,], but receives error on any portion past that number, but also works on d857[80000:90000,]. I checked the dataset in its file and do not see any values that are out of the ordinary. What could be causing this error and how could I fix it?

这里是 d857[27870:27880,] 和 sapply 函数.

Here is d857[27870:27880,] and the sapply function.

> d857[27870:27880,]
                 datetime    light
27870 2013-08-26 17:35:27 1163.944
27871 2013-08-26 17:40:27 1163.944
27872 2013-08-26 17:45:27 1163.944
27873 2013-08-26 17:50:27 1163.944
27874 2013-08-26 17:55:27 1163.944
27875 2013-08-26 18:00:27 1163.944
27876 2013-08-26 18:05:27 1163.944
27877 2013-08-26 18:10:27 1163.944
27878 2013-08-26 18:15:27 1163.944
27879 2013-08-26 18:20:27 1163.944
27880 2013-08-26 18:25:27 1163.944

> sapply(d857$datetime, twilightCalc)
Error in data.frame(datetime = as.POSIXct(as.character(datetime), "UTC"),  : 
  argument "light" is missing, with no default

推荐答案

该解决方案包括在 R 中添加两行代码,以在地理定位器处于活动状态之前删除任何日期并记录转换数据.在使用 twilightCalc 函数之前,在以下代码行中对 geolocator 数据类型使用函数 luxTrans 之后:

The solution involves adding two lines of code into R to cut out any dates before the geolocator was active and to log transform the data. After using the function luxTrans on the geolocator data type in the following lines of code before using the twilightCalc function:

ds <- luxTrans("D857.lux") #luxTrans the data
ds <- ds[ds[,1]>as.POSIXct("2013-06-24"),] # cut off the days when not active
ds$light <- log(ds$light) # log transform the data

这篇关于读取有关 r 中不同行数的数据集时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆