in Education by
Let's say that I have a date in R and it's formatted as follows. date 2012-02-01 2012-02-01 2012-02-02 Is there any way in R to add another column with the day of the week associated with the date? The dataset is really large, so it would not make sense to go through manually and make the changes. df = data.frame(date=c("2012-02-01", "2012-02-01", "2012-02-02")) So after adding the days, it would end up looking like: date day 2012-02-01 Wednesday 2012-02-01 Wednesday 2012-02-02 Thursday Is this possible? Can anyone point me to a package that will allow me to do this? Just trying to automatically generate the day by the date. Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
To extract the weekday, month or quarter, or the Julian time (days since some origin), use the weekdays function that extracts parts of a POSIXt or Date Object. In your case: dt = data.frame(date=c("2012-02-01", "2012-02-01", "2012-02-02")) dt$day <- weekdays(as.Date(dt$date)) dt Output: date day 1 2012-02-01 Wednesday 2 2012-02-01 Wednesday 3 2012-02-02 Thursday

Related questions

0 votes
    I have code that at one place ends up with a list of data frames which I really want to convert ... starting with (this is grossly simplified for illustration): listOfDataFrames...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a data frame with a column of p-values and I want to make a selection on these p-values. > pvalues_anova ... 7.125751e-01 5.193604e-01 4.835312e-04 Selection way: anovatest...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a data frame called "newprice" (see below) and I want to change the column names in my program in R. > newprice ... 164 In fact, this is what am doing: names(newprice)[1]...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I have a huge vector which has a couple of NA values, and I'm trying to find the max value in that vector ( ... I can compute the max? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Many times I have seen the set.seed function in R, before starting the program. I know it's basically used for ... need to set this? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    How do you import a plain text file as a single character string in R? I think that this will probably ... is probably unstable too. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    The install.packages() function in R is the automatic unzipping utility that gets and install packages in R. ... accesses packages? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    A very newbish question, but say I have data like this: test_data...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Suppose I have a ggplot with more than one legend. mov...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Hi this simple code (and all my scripts from this morning) has started giving me an off-center title in ggplot2 Ubuntu ... the above this morning to try and fix this.... dat...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I'm trying to keep the legend of one layer (smooth) and remove the legend of the other (point). I have tried ... = gear)) + theme_bw() Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    A categorical variable V1 in a data frame D1 can have values represented by the letters from A to Z. I want to create a ... B','N',T')) Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have used the following ggplot command: ggplot(survey, aes(x = age)) + stat_bin(aes(n = nrow(h3), y = ... but cannot figure out how. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    According to the R language definition, the difference between & and && (correspondingly | and ||) is that the former ... OrElse in R? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a list and I want to remove a single element from it. How can I do this? I've tried looking ... 't found anything appropriate. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...