This is an R Markdown document that you can easily export to HTML, PDF, and MS Word formats. For more information on R Markdown, see <http://rmarkdown.rstudio.com>.
# Tags used per day
Read in the journal file *Readme.md* that is in the *journal* folder. Then extract the lines with date headings at the second level. We can then extract the tags and the dates:
```{r}
# Import data ------------------------------------------------------------------
# Extract lines with headings at the 2nd level ---------------------------------
MyDates <- MyData[grepl(pattern = "##", x = MyData)]
# Extract the tags -------------------------------------------------------------
MyTags <-
sub(pattern = "-->",
replacement = "",
x = sub(pattern = ".*<!--",
replacement = "",
x = MyDates))
# Extract the dates and replace string by dates --------------------------------
MyDates <-
substring(
MyDates,
regexpr(pattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}", text = MyDates),
regexpr(pattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}", text = MyDates) + 9)
# Format as date ---------------------------------------------------------------
MyDates <- as.Date(MyDates)
```
When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows:
We can now create a data frame with the date and tags:
Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible.
Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you.
Calculate the number of days per tag:
```{r}
table(MyTags$tags)
```
Now it's your turn! You can delete all this information and replace it by your computational document.