简体   繁体   English

将字符串转换为日期在BlueSky Statistics中不起作用

[英]Converting String to Date not working in BlueSky Statistics

Not having a lot of luck with the Date conversion command. 使用Date转换命令没有太多运气。 Have tried several different prefixes. 尝试了几种不同的前缀。 The function appears to need it but when run it fails with a NULL . 该函数似乎需要它,但在运行时它失败并返回NULL This is the script that's produced: 这是生成的脚本:

## [Convert String Variables to Date]

BSkystrptime (varNames = c('date__3'),dateFormat = "%m/%d/%y %H:%M:%S",prefixOrSuffix = "suffix",prefixOrSuffixValue = "posix",data = "Dataset6")

BSkyLoadRefreshDataframe(dframe=Dataset6,load.dataframe=TRUE)

And here Is the output: 这是输出:

BSkystrptime (varNames = c('date__3'),dateFormat = "%m/%d/%y %H:%M:%S",prefixOrSuffix = "suffix",prefixOrSuffixValue = "posix",data = "Dataset6")

NULL

BSkyLoadRefreshDataframe(dframe=Dataset6,load.dataframe=TRUE)

The date__3 variable is present and populated with character representing dates. date__3变量存在并填充了表示日期的字符。

The NULL in the case of converting string to date type does not indicate an error, you should check the columns of the data grid, the new column with the prefix/suffix should be generated. 在将字符串转换为日期类型的情况下,NULL不表示错误,您应该检查数据网格的列,应该生成带有前缀/ suffix的新列。

In come cases, the new date field will contain "0001-01-01 00:00:00", this is because the format you have selected ie "%m/%d/%y %H:%M:%S" does not match the data in the character variable you are converting to date. 在新的情况下,新的日期字段将包含“0001-01-01 00:00:00”,这是因为您选择的格式,即“%m /%d /%y%H:%M:%S”与您要转换为日期的字符变量中的数据不匹配。

Here are a few tips 这里有一些提示

Tools->Configuration settings->Select the Output tab, now select the option to show syntax in the output window. 工具 - >配置设置 - >选择输出选项卡,现在选择在输出窗口中显示语法的选项。 This will show you the R syntax we trigger. 这将显示我们触发的R语法。 You can modify it. 你可以修改它。 Another person who I was assisting found this very helpful. 我帮助的另一个人发现这非常有帮助。 The reason is when you select an incorrect format, eg if you selected "%m/%d/%y %H:%M:%S" instead of "%m/%d/%Y %H:%M:%S" (Note the difference is the capitalization of y), you would see that the date field got converted in the grid to the date "0001-01-01 00:00:00". 原因是当您选择不正确的格式时,例如,如果您选择“%m /%d /%y%H:%M:%S”而不是“%m /%d /%Y%H:%M:% S“(注意差异是y的大小写),您会看到日期字段在网格中转换为日期”0001-01-01 00:00:00“。 This basically indicates that R was unable to convert the string to date due to invalid format. 这基本上表明由于格式无效,R无法将字符串转换为日期。

Another useful dialog when dealing with new variables created with a prefix or suffix is to sort the variables alphabetically. 处理使用前缀或后缀创建的新变量时,另一个有用的对话框是按字母顺序对变量进行排序。 Try Data->Reorder variables in dataset alphabetically 按字母顺序尝试数据 - >重新排序数据集中的变量

The option to convert string variables to date can be found under Data->Dates->Convert String to Date 将字符串变量转换为日期的选项可以在Data-> Dates-> Convert String to Date下找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM