I want to create a new column called page
If URL="//Community/document/pen" then Page=Pen
If UR:="//Community/document/Pencil" then Page =Pencil
else Page=Sharpner
End;
This i wanted to do in R programming Please help me to write code
This looks like two separate questions. Please ask only one question per thread.
To calculate the week of a date, there are three functions in the lubridate package. They use different definitions for the start of the first week in the year. Please see the help section in lubridate for an explanation.
I used the mdy() function from lubridate to change the text strings into Dates.
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:lubridate':
#>
#> intersect, setdiff, union
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
DF <- data.frame(Date = mdy(c("9/1/2019",
"9/5/2019",
"9/11/2019",
"9/16/2019",
"9/20/2019",
"9/26/2019",
"9/30/2019")))
DF <- DF %>% mutate(Week = week(Date), ISOweek = isoweek(Date), EPIweek = epiweek(Date))
#> Warning: The `printer` argument is deprecated as of rlang 0.3.0.
#> This warning is displayed once per session.
DF
#> Date Week ISOweek EPIweek
#> 1 2019-09-01 35 35 36
#> 2 2019-09-05 36 36 36
#> 3 2019-09-11 37 37 37
#> 4 2019-09-16 37 38 38
#> 5 2019-09-20 38 38 38
#> 6 2019-09-26 39 39 39
#> 7 2019-09-30 39 40 40
Created on 2019-10-09 by the reprex package (v0.3.0.9000)
Thanks for the reply. However am not able to recall the library after installing it trowing below error.
"Error in library(lubridate) : there is no package called ‘lubridate’"
If you cannot install lubridate you can still extract it using base R. Of course, the same thing as with lubridate, what do you consider a week?. Base R easily extract the EPIweek and ISOweek too:
Try this: If you are having problems installing lubridate on Windows, then try to close all RStudio/R session down and open RStudio again, so you start from scratch. Closing down R sometimes help as Windows locks folders in use.