asked    Frederica     2018-10-22       r       127 view        2 Answers

[SOLVED] changing date format with only months and year

I have a column with dates that are formatted like this:

yyyymm (e.g. 201809)

I want them to be formatted like this:

mm.yyyy (e.g. 09.2018)

I tried:

FF5factors$date <- strptime(FF5factors$date, format= "%Y%m")
format(FF5factors$date, format="%m.%Y")

But it only returns NA values.

  2 Answers  

        answered    Samuel     2018-10-22      

Here are some alternatives. The question did not provide date in reproducible form so we assume the first line below although the first 4 alternatives will also work with date <- "201809" and with date <- factor(201809) .

date <- 201809

# 1
sub("(....)(..)", "\\2.\\1", date)
## [1] "09.2018"

# 2
library(zoo)
format(as.yearmon(format(date), "%Y%m"), "%m.%Y")
## [1] "09.2018"

# 3
paste(substr(date, 5, 6), substr(date, 1, 4), sep = ".")
## [1] "09.2018"

# 4
format(as.Date(paste0(date, "01"), "%Y%m%d"), "%m.%Y")
## [1] "09.2018"

# 5
sprintf("%02d.%d", date %% 100, date %/%100)
## [1] "09.2018"


        answered    Mildred     2018-10-22      

What about:

d <- '201809'
format(as.Date(d,'%Y%M'),'%m.%Y')
[1] "09.2018"




Your Answer





 2018-10-22         Lambert

Text Split cognitive skill not visible in UI

I am adding Azure Search and trying to add skills for content enrichment.I can see the Key Phrase Extraction and the Language Detection predefined skills but not the Text Split skill on the screen. Is there a reason why Text Split skill is not visible? Or is it something that can only be added via API? The capabilities exposed throught the portal focus on core scenarios that customers want to perform so they do not include text splitting. If you want to split your text, you should do it by creating your own skillset programatically through the API, that will allow you t...
 azure                     1 answers                     110 view
 2018-10-22         Pearl

Questions about mysqldump and Microsoft Azure

I need to dump database which hosts on Microsoft Azure.I tried following: 1. Connect to db with MySQL Workbench. 2. Select Data Export and use it. The warning message says that 'unequal version of mysqldump(8.0.12) and MySQL Server to be dumped(5.7.21) may cause issues' were shown. 3. No upgrades avaliable at MySQL Community Installer. So where's the question:1. How to get mysqldump of required version?2. mysqldump version seems higher than needed but it still doent work. Why?All attemps had following log:18:59:01 Dumping schedule-system (all tables)Running: "C:\Program Fi...
 mysql                     1 answers                     123 view
 2018-10-22         Wendy

Error "TypeError: Cannot read property 'seconds' of null" when commit Firestore batch

I got the following error when trying to batch delete a collection: TypeError: Cannot read property 'seconds' of null at Function.fromProto (..\node_modules\@google-cloud\firestore\build\src\timestamp.js:91:47)The code is plain simple (written in TypeScript):var admin = require('firebase-admin');...var batch: FirebaseFirestore.WriteBatch = admin.firestore().batch();return generic.application.admin.firestore().collection(name) .get() .then((docs: FirebaseFirestore.QuerySnapshot) => { docs.docs.forEach((doc:any) => { batch.delete(doc.ref); ...
 node.js                     1 answers                     76 view