Пікірлер

  • @mufid.asshiddiq
    @mufid.asshiddiq3 ай бұрын

    Thanks, very helpful!

  • @danieldbonneau
    @danieldbonneau3 ай бұрын

    Thanks! I'm glad it was helpful

  • @j7andrew
    @j7andrew4 ай бұрын

    I highly recommend watching this at 1.25 speed. Other than that, it's a perfect video. Great balance between depth and getting straight to the point. Thank you 🤙🏽

  • @danieldbonneau
    @danieldbonneau4 ай бұрын

    Thanks! Really appreciate the feedback

  • @j7andrew
    @j7andrew4 ай бұрын

    Awesome video! Thank you!!

  • @danieldbonneau
    @danieldbonneau4 ай бұрын

    Thank you!

  • @Svykle
    @Svykle6 ай бұрын

    How do you retain the format of month-day-year?

  • @danieldbonneau
    @danieldbonneau6 ай бұрын

    For the column in your data frame? Date variables will always just show as Year-Month-Day. If you wanted to have a variable that displays it as Month-Day-Year, you could just paste it together in that way in a different column. However, you'd still use your actual date column if you wanted to run any calculations with that date variable.

  • @Svykle
    @Svykle6 ай бұрын

    @@danieldbonneau omg. Thanks . God I spent hours on this lol . So how would display my date like in a histogram using year -date? Thanks . R is fun but challenging at first .

  • @mattramsdell3173
    @mattramsdell31737 ай бұрын

    This is great!

  • @danieldbonneau
    @danieldbonneau7 ай бұрын

    Thanks, Matt!

  • @kcollins2316
    @kcollins23167 ай бұрын

    Thank you!

  • @danieldbonneau
    @danieldbonneau7 ай бұрын

    Glad I could help!

  • @vanakornsirijongprasert1726
    @vanakornsirijongprasert17269 ай бұрын

    Thank you, this tutorial is clear and so easy to follow. Big thumb up!

  • @danieldbonneau
    @danieldbonneau9 ай бұрын

    Thanks for the feedback, glad I could help!

  • @ZeuSonRed
    @ZeuSonRed Жыл бұрын

    Very Very Helpfull

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    Happy to hear it. Thanks!

  • @yawboateng9660
    @yawboateng9660 Жыл бұрын

    Thanks

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    You're welcome, Yaw!

  • @osoriomatucurane9511
    @osoriomatucurane9511 Жыл бұрын

    Very trick and at time daunting working with dates in R. But you made it so simple and straitforward with the mdy(), ymd() and dmy() functions. Well done!

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    Thanks for the kind words, Osorio!

  • @xoxojen15
    @xoxojen15 Жыл бұрын

    Hi, thanks for this video, it's very helpful. If you don't mind me asking, what would you do in cases where the date and time are given together in a dataset? for example "Dec 04, 2021, 11:30:00AM" all in one column. I'm unsure of the best way to split them out and format them as dates/times. Thanks!

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    Thanks for the question. To just convert that directly into a date format, you could use the mdy_hms() function within the lubridate package. Then, to get something like just the date without the time, you could use the date() function on that newly created variable. The same works for if you want to get the year, month, day, hour, minute, second. Then, if you wanted to also get a column that was just the time, you could load in the hms package and use the as_hms() function on the formatted datetime object. Here's some simple code showing a few of these things: dates <- c("Dec 04, 2021, 11:30:00AM", "Dec 04, 2021, 12:30:00AM", "Dec 05, 2021, 11:30:00AM") library(lubridate) library(hms) library(dplyr) data.frame(dates = dates) %>% mutate(date_format = mdy_hms(dates)) %>% mutate(just_date = date(date_format)) %>% mutate(month = month(date_format)) %>% mutate(hour = hour(date_format)) %>% mutate(just_time = as_hms(date_format))

  • @thisarajayasinghe9252
    @thisarajayasinghe9252 Жыл бұрын

    Thank you

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    You're welcome!

  • @koushikvadali7859
    @koushikvadali7859 Жыл бұрын

    how to convert a number such as this '41738.955555555556' into date ?

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    You can use the as.Date() function to convert that to a date. However, you'll need to also supply an origin argument. I've never seen it with decimals, but it's the same with decimals or the whole number. Running as.Date(41738, origin = "1899-12-30") gives 2014-04-09. Is that the date you're looking for? The way this works is the numeric value (41738 in this case) is the number of days from the origin supplied. In other words, 2014-04-09 is 41,738 days from 1899-12-30. Hope that helps.

  • @koushikvadali7859
    @koushikvadali7859 Жыл бұрын

    @@danieldbonneau thanks

  • @briandong5293
    @briandong5293 Жыл бұрын

    My dataset is different. The column names are the dates and not the cells below them. It doesn't seem to work.

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    If your column names are dates, you want to start by reorganizing your data set. Your data set should (almost always) be in a "long" format, where each column holds one particular piece of information - such as date or sales. So before applying the conversion from this video, you're going to want to use pivot_longer() from the tidyr package. Let's suppose your data set has dates as the column names, and sales as the values within the first row of your data set and that this data set is called "my_data". You would run this code first to reorganize your data into two columns: "date" and "sales" pivot_df <- my_data %>% pivot_longer(cols = everything(), names_to = "date", values_to = "sales") With that line, you should be left with a new data set that has two columns, date and sales. Then, you can transform the date column into an actual date data type using the steps in this video. To see the pivot_longer code in action with a different example, I have this video: kzread.info/dash/bejne/d3-hpJSMc9CZmpc.html

  • @lhamo388
    @lhamo388 Жыл бұрын

    is there a function for month/year or is it just for d/m/y?

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    There are a couple of ways I'm interpreting your question, so I'll try to answer both here. 1. If you're looking to get month and year as separate variables. You could use separate() in the tidyr package to split it into two columns. Something like: df %>% separate(date, into = c("month", "year"), sep = "/") 2. To convert month/year into a formal date object. Off the top of my head, that's not possible without adding the day in to the date. So you would need to do something like: date <- paste0("01/", month_year) formatted_date <- dmy(date) Alternatively, if you're just trying to create a month-year string, you can just paste together the month and year by using something like: paste(month(date), year(date), sep = "-") Let me know if I didn't address your question so I can help you out.

  • @Marlorouse109
    @Marlorouse109 Жыл бұрын

    Thank you for simplifying this function !

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    Happy I could help!

  • @omolewaoreweme147
    @omolewaoreweme147 Жыл бұрын

    Thank you so much, i was so frustrated

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    Thanks for the positive feedback! If you have any other R problems you're frustrated by let me know and I may be able to make a video to help you out.

  • @CoachPegasus
    @CoachPegasus Жыл бұрын

    2012-06-04 WM$Date = sub("\\-", "/", WM$Date) They turn into NAN NA NA NA "2012/06-04" NA NA thanks

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    You'll want to make sure you're using gsub(), and not sub(). sub() will only replace the first occurrence, while gsub() will replace it "globally". That change will make sure the "2012/06-04" is properly written as "2012/06/04". As for the NA's, it's hard to say without seeing your data further, there may be something else that's causing that to occur. *Edit: Make sure there's no conversion to numeric after you do the substituion. It would be strange for a character substitution to produce an NA in this case, so it may be something else if you're running additional code. Depending on what you need the dates for and why you're trying to make this change, you may want to look into the lubridate package and one of it's functions. Happy to help further if you want to share more about your specific use case so I can help you get this all squared away.

  • @CoachPegasus
    @CoachPegasus Жыл бұрын

    if we need to convert in date column from from 6-1-2022 to 6/1/2022... How can we do it? with gsub it shows as NAN..

  • @danieldbonneau
    @danieldbonneau Жыл бұрын

    I'm not sure why gsub() isn't working for that. Make sure you don't have any conversion to numeric occurring after the code. It would be weird for a character substitution to produce an NA in this scenario. A roundabout alternative to restructure this would just be to paste together the individual components. After making sure it's a date column and not a character column, you can do something like: library(lubridate) # Use this to read in month, day, year functions new_date <- paste(month(old_date), day(old_date), year(old_date), sep = "/') Where old_date would be, for example, 6-1-2022 and new_date should be the same date but separated by slashes. I know it's not as direct, but if you can't get gsub working this should work. Hope that helps.

  • @JPRGuti
    @JPRGuti2 жыл бұрын

    This is awesome!! Waiting for the next video showing how to build it!!

  • @danieldbonneau
    @danieldbonneau2 жыл бұрын

    Thanks for your excitement! I have uploaded the first 3 videos in a series to show how to build this exact app yourself in R Shiny. The first video is here: kzread.info/dash/bejne/Z36czrRmgZDgirw.html