简体   繁体   中英

Converting String to Date not working in BlueSky Statistics

Not having a lot of luck with the Date conversion command. Have tried several different prefixes. The function appears to need it but when run it fails with a 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.

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.

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.

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. 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". This basically indicates that R was unable to convert the string to date due to invalid format.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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