问题标签 [as.date]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
6810 浏览

r - sapply as.Date 函数将时间变量从整数更改为日期不起作用

我的问题是我有代表日期的三列整数。如果我使用

对于每个单独的列,它都有效。但是,如果我sapply使用

这没用。关于如何有效解决问题的任何想法?可重现的代码如下

结果根本没有改变。但使用

它可以工作。

0 投票
0 回答
831 浏览

r - 在R中将序列号转换为日期时的NA

将excel表格导入R后,发现所有日期格式都改成序号了。我尝试使用如下非常简单的代码,但是我得到的是 NA 而不是日期。

可重现的例子是(df):

我使用的代码是

as.Date在指定后用单独的序列号进行了测试origin,它工作正常。但是,当我尝试一次转换 (df) 的整个第一列时,它会给出那些 NA

我在 Mac OS 10.10 和 R 3.1.1

0 投票
2 回答
1021 浏览

r - 如何按按会计季度分组的日期计算平均值

我有下表:

在“日期”列中,年份除以接下来的月份 - 3 月、6 月、9 月和 12 月。我需要将 6 月至 3 月的月份分组为一个财政年度,并按每个财政年度按“国家”和“类别”计算“值”列的平均值。有人可以帮我这样做吗?

我正在尝试使用 data.table 执行此操作,但出现错误:

cut.default 中的错误(期间,列表(2010 年 6 月 1 日、2011 年 3 月 1 日、2011 年 6 月 1 日、2012 年 3 月 1 日):“x”必须是数字

谢谢!

0 投票
3 回答
2599 浏览

r - 在R中按间隔拆分日期

我有一个日期列:

我怎样才能按财政年度分割这些日期 - 从六月到三月。2010 年 6 月至 2011 年 3 月 - FY1011;从 2011 年 6 月至 2012 年 3 月 - FY1112。并为每一行输入会计年度的名称。

我可以用功能切割来做吗?像这样的东西:

0 投票
1 回答
2937 浏览

r - 用 R 转换为日期

我想将日期转换为日期格式,以便制作可扩展的时间序列数据。

0 投票
2 回答
6022 浏览

r - 将字符串 data.frame 转换为 Date

我想知道为什么会出现这个错误。我想使用方括号进行转换,因为我正在循环中进行顺序转换。因为我只是想能够做到并了解正在发生的事情。

0 投票
1 回答
511 浏览

r - 转换为.Date:一次多个数据帧

我有 66 个数据框需要转换“日期”列“as.Date”。我不知道该怎么做。我会这样:

等等...

有一种方法可以同时处理所有数据帧吗?我找到了同一数据框中多列的解决方案,但不是这样。

Tks

0 投票
1 回答
347 浏览

r - 以不规则的方式将日期粘贴到时间

我正在尝试将时间与其相应的日期结合起来,但遇到了麻烦。日期和时间在一个列表中,其中日期后跟该日期的时间。这种模式以不规则的方式继续。

这是我到目前为止所尝试的:

我得到:

我在找:

理想情况下,我想要一个将日期和时间组合成单个日期时间对象的解决方案。

请帮助...谢谢

0 投票
2 回答
461 浏览

r - Trouble converting and separating dates in R

I have a dataset containing some dates listed in the CSV as dd/mm/yy and my final aim is to separate out the year column into a separate column, however it seems to be giving me some very odd results.

When the CSV is input into R, the dataset (dframe1) shows the dates as factors automatically e.g. 8/3/05 but they aren't all in this format, some are 8/3/2005 and some are 08/03/2005 (as they should be) which means that when I convert them, some of the dates are coming up like they should (i.e., 2004-11-5) and some are coming out really strange (i.e., 0004-11-5).. I checked on the excel spreadsheet and they are all formatted exactly the same, written in the same etc., and the code is exactly the same for converting, but it just doesn't seem to work.

Here is an example of what it looks like what I import into R, even though in excel they are all the same:

The code I am wanting to use to convert is as below:

data = dframe1

Set.date, Haul.date, Date.depart and Date.return are all columns within dframe1

First I make sure R knows that the date columns are actually dates (rather than factors, the automatic assumption)

Next I want to separate and add a column for year (can also do with day and month but won't bother this time)

0 投票
0 回答
673 浏览

r - 闪亮的反应式日期格式

我正在尝试构建一个简单的闪亮应用程序,但我被日期转换困住了。我想要的主要目的是选择文件并选择日期格式。

现在,我正在使用 csv、数据文件示例中的一种日期格式,该示例看起来像“%d-%m-%Y”字符串。我尝试了几种方法来转换为正确的日期,并且 as.date 函数似乎可以解决问题。

但是当我在新的 data.frame 中显示转换后的日期时,结果似乎是数字。我也有以下错误:

server.R 代码是:

用户界面代码是:

而 global.R 是:

下面是我处理的数据示例:

我的语言环境是:

有什么建议吗?提前感谢奥斯卡