gsub Function in R - Converting Revenue Data to Numeric

  Рет қаралды 1,687

Daniel Bonneau

Daniel Bonneau

Күн бұрын

Пікірлер: 6
@vanakornsirijongprasert1726
@vanakornsirijongprasert1726 Жыл бұрын
Thank you, this tutorial is clear and so easy to follow. Big thumb up!
@danieldbonneau
@danieldbonneau Жыл бұрын
Thanks for the feedback, glad I could help!
@CoachPegasus
@CoachPegasus 2 жыл бұрын
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 2 жыл бұрын
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
@CoachPegasus
@CoachPegasus 2 жыл бұрын
2012-06-04 WM$Date = sub("\\-", "/", WM$Date) They turn into NAN NA NA NA "2012/06-04" NA NA thanks
@danieldbonneau
@danieldbonneau 2 жыл бұрын
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.
Arrange in R - Sort a Dataframe by a Column in R
5:19
Daniel Bonneau
Рет қаралды 414
Convert to Date in R - Character Strings to Date Format
5:42
Daniel Bonneau
Рет қаралды 10 М.
Friends make memories together part 2  | Trà Đặng #short #bestfriend #bff #tiktok
00:18
小路飞还不知道他把路飞给擦没有了 #路飞#海贼王
00:32
路飞与唐舞桐
Рет қаралды 58 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 21 МЛН
Handling Missing Values in R
14:14
Unboxing Big Data
Рет қаралды 528
Lubridate - how to manipulate date and time data in R
18:05
R Programming 101
Рет қаралды 12 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
WHY Your EX Moved on So Quickly: The Shocking Truth!
7:04
Coach Blac - Blacademic
Рет қаралды 60 М.
How I'd Learn Data Analytics in 2024 (If I Had to Start Over)
14:08
CareerFoundry
Рет қаралды 814 М.
Recode Multiple Items Using Mutate At
9:56
benR
Рет қаралды 1,8 М.
How to Use lapply, sapply and mapply in R
7:45
DataDaft
Рет қаралды 40 М.
Future smartphone😀#youtubeshorts #smartphone #unboxing
0:24
E Zone
Рет қаралды 4,7 МЛН
Xiaomi 15 и HyperOS 2 - ну что, опять топ
27:09
Rozetked
Рет қаралды 523 М.
Low Battery 🪫🥹🥹🥹
0:10
dednahype
Рет қаралды 1,6 МЛН
Ai Samsung vs Ai Apple
1:00
Romancev768
Рет қаралды 195 М.
Making iPhone16 pink📱
0:34
Juno Craft 주노 크래프트
Рет қаралды 6 МЛН