<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Michael T Vu on Medium]]></title>
        <description><![CDATA[Stories by Michael T Vu on Medium]]></description>
        <link>https://medium.com/@michaeltvu?source=rss-f258f10222f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OoodszYlJsNoiA4k4o7Uww.jpeg</url>
            <title>Stories by Michael T Vu on Medium</title>
            <link>https://medium.com/@michaeltvu?source=rss-f258f10222f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 16:58:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@michaeltvu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exploring the Exciting Future of Data Analysis and AI: Advancements, Challenges, and Impacts]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@michaeltvu/exploring-the-exciting-future-of-data-analysis-and-ai-advancements-challenges-and-impacts-3d6addc3d6d1?source=rss-f258f10222f6------2"><img src="https://cdn-images-1.medium.com/max/2600/0*p5WhCPG6hrKQb_1y" width="3648"></a></p><p class="medium-feed-snippet">The Future of Data Analysis and AI: A Look Ahead</p><p class="medium-feed-link"><a href="https://medium.com/@michaeltvu/exploring-the-exciting-future-of-data-analysis-and-ai-advancements-challenges-and-impacts-3d6addc3d6d1?source=rss-f258f10222f6------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@michaeltvu/exploring-the-exciting-future-of-data-analysis-and-ai-advancements-challenges-and-impacts-3d6addc3d6d1?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d6addc3d6d1</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[privacy]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Fri, 10 Feb 2023 04:46:27 GMT</pubDate>
            <atom:updated>2023-02-10T04:46:27.590Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Mastering Time Management: How to Effectively Prioritize and Meet Deadlines with Excel]]></title>
            <link>https://medium.com/@michaeltvu/mastering-time-management-how-to-effectively-prioritize-and-meet-deadlines-with-excel-cce4da8b492d?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cce4da8b492d</guid>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[time-management]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[project-management]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 01:44:37 GMT</pubDate>
            <atom:updated>2023-01-17T01:44:37.433Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6mLlCcmNrQ7iyiaT" /><figcaption>Photo by <a href="https://unsplash.com/@craftedbygc?utm_source=medium&amp;utm_medium=referral">Green Chameleon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We all have a to-do list that we need to complete, whether it’s for work, school, or personal projects. However, with so many tasks to juggle, it can be challenging to stay organized and ensure that everything is completed on time. That’s where time management comes in. By effectively managing your time, you can prioritize your tasks, set clear deadlines, and track your progress to make sure you stay on track and avoid feeling overwhelmed. In this article, I will show you how to use Excel to effectively manage your time when handling multiple projects, so you can stay organized and meet your deadlines, just like we do.</p><p>One effective way to manage your time when handling multiple projects is to prioritize them based on their level of urgency. For this purpose, you can use Excel to create a spreadsheet with at least 8 columns: <strong>Name, Folder, Level, Assigned Date, Deadline, Completed Date, Progress, and Status</strong>. You can also add or modify depending on your situation. You can also <a href="https://docs.google.com/spreadsheets/d/1h3cdUL9rNO6sNMRiuf_Z33pQ9gGdDImD/edit?usp=sharing&amp;ouid=103220444372673929436&amp;rtpof=true&amp;sd=true">download</a> the template here and adjust as you wish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AO0XSTopH-kcwBX9QJ_8RQ.png" /><figcaption>Effectively Prioritize and Meet Deadlines with Excel</figcaption></figure><p>The “<strong>Name</strong>” column is for the name of the project, “<strong>Folder</strong>” is for where you save your project, “<strong>Level</strong>” is a dropdown list that includes <strong>Low, Medium, High, Urgent</strong> which tells you how urgent a project is. By doing this way, you will easily recall the project you worked on, where to find the project and its requirement in your computer. When I receive a new project, I often save as an outlook file (<strong>.msg </strong>extension) in a specific folder. It saves me tons of time when I need to look back and navigate what I am going to do.</p><p>“<strong>Assigned Date</strong>” is the date that a project is assigned, “<strong>Deadline</strong>” is the date that the project needs to be done, “<strong>Completed Date</strong>” is the date that the project is completed, “<strong>Progress</strong>” is the progress bar that shows how many percent the project is being completed and “<strong>Status</strong>” is a dropdown list that includes <strong>In Progress, Completed</strong>. If the value is entered in the progress bar as <strong>100</strong>, then the status will automatically be updated as <strong>completed. </strong>Otherwise it will show <strong>in progress</strong>.</p><p>By prioritizing your projects based on their level of urgency, you can better plan and allocate your time to ensure that each project is completed on time.</p><p>Another important aspect of time management is setting clear deadlines for each project. The “<strong>Assigned Date</strong>” and “<strong>Deadline</strong>” columns in your Excel file can be used to track the start and end dates of each project. By setting specific deadlines, you can plan accordingly to finish the projects before the due date.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FG4pFuFdDewNyZlUYJV%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fdrawify-G4pFuFdDewNyZlUYJV&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2FG4pFuFdDewNyZlUYJV%2Fgiphy.gif%3Fcid%3D790b76115b4a6812651a3d98c3864fd62564c906faf1773e%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae56233ac02edc53789ce8bae4226b96/href">https://medium.com/media/ae56233ac02edc53789ce8bae4226b96/href</a></iframe><p>You can also use the “<strong>Progress</strong>” column in your Excel file to track the completion status of each project. By regularly updating the progress bar, you can ensure that you are on track to meet your deadline and make any necessary adjustments to your plan. The progress bar has value from <strong>0</strong> to <strong>100</strong>. If you enter <strong>10</strong>, it will update the progress bar as <strong>10%</strong>. When I start a new project, I always put <strong>10</strong> in this column because it creates a feeling that I am making progress, and a lot of positive energy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*lKszq--RUKSrZe2lmnMU9w.png" /><figcaption>Time management</figcaption></figure><p>Finally, you can use the “<strong>Status</strong>” column in your Excel file to keep track of which projects are currently in progress and which have been completed. This can help you focus your attention on the projects that still need to be finished, while still keeping an eye on the ones that are finished.</p><p>Overall, by utilizing the different columns in your Excel file, you can effectively prioritize and plan your projects, set clear deadlines, track progress, and monitor status, which all contribute to effective time management and meeting project deadlines.</p><p>In conclusion, time management is a crucial aspect of completing projects successfully, and by effectively managing your time and using Excel to create a spreadsheet with the above columns, you can stay organized, prioritize your tasks, and meet your deadlines, so you can work under minimal pressure.</p><p>You may like</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfbAYK4KQrso%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfbAYK4KQrso&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FfbAYK4KQrso%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4c80f65dc45bd446704e9f696b10719/href">https://medium.com/media/e4c80f65dc45bd446704e9f696b10719/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cce4da8b492d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What You Need To Know To Become A Data Analyst]]></title>
            <link>https://blog.devgenius.io/what-you-need-to-know-to-become-a-data-analyst-7e474f4e2325?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e474f4e2325</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[data-analyst]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[business-intelligence]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Sun, 08 Jan 2023 03:41:40 GMT</pubDate>
            <atom:updated>2023-01-10T18:24:43.885Z</atom:updated>
            <content:encoded><![CDATA[<h4>Becoming a data analyst and things you need to know.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JJ5T6-fP5Ak8W0IN" /><figcaption>Photo by <a href="https://unsplash.com/@kobuagency?utm_source=medium&amp;utm_medium=referral">KOBU Agency</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Data analysts are in high demand in today’s data-driven world. They play a crucial role in helping organizations make sense of large and complex datasets, extract valuable insights, and make data-driven decisions. But what does it take to become a successful data analyst? In this article, we will discuss the key skills and knowledge that are necessary for a career in data analysis, including a strong foundation in mathematics and statistics, programming skills, data visualization, data cleaning and wrangling, business acumen, and communication and collaboration abilities. We will also discuss the importance of staying up to date with new technologies and techniques, and how a degree in a related field and practical experience can help you succeed in this rewarding career.</p><p>Before becoming a data analyst, it is important to have a strong foundation in the following areas:</p><ol><li><strong>Mathematics and statistics:</strong> As a data analyst, you will be working with large datasets and using statistical techniques to extract insights from the data. It is crucial to have a strong understanding of concepts such as probability, hypothesis testing, regression analysis, and machine learning.</li><li><strong>Programming</strong>: Data analysts often use programming languages such as <strong>Python, R</strong>, and <strong>SQL</strong> to manipulate, analyze, and visualize data. Familiarity with at least one programming language is essential.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FauT90KZK3Y1Rshj" /><figcaption>Photo by <a href="https://unsplash.com/@hiteshchoudhary?utm_source=medium&amp;utm_medium=referral">Hitesh Choudhary</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>3. <strong>Data visualization</strong>: Being able to effectively communicate your findings through visualizations is a key skill for data analysts. Familiarity with tools such as Tableau, Power BI and matplotlib can help you create clear and impactful visualizations.</p><p>4. <strong>Data cleaning and wrangling</strong>: A significant portion of a data analyst’s job involves preparing data for analysis. This includes tasks such as handling missing values, merging datasets, and reformatting data.</p><p>5. <strong>Business acumen</strong>: As a data analyst, you will be working with various stakeholders within an organization to help make data-driven decisions. It is important to have a good understanding of business concepts and the industry you are working in to be able to effectively communicate your findings.</p><p>6. <strong>Communication and collaboration</strong>: Data analysts often work in teams and must be able to effectively communicate their findings to both technical and non-technical audiences. Strong communication skills and the ability to collaborate with others are essential.</p><p>In addition to the above skills, it is also helpful to have a strong curiosity and desire to learn. The field of data analysis is constantly evolving, and staying up to date with new techniques and technologies will help you excel in your career.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mFG4gtfNYV_qO4yg" /><figcaption>Photo by <a href="https://unsplash.com/it/@timmossholder?utm_source=medium&amp;utm_medium=referral">Tim Mossholder</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Obtaining a degree in a related field such as computer science, statistics, or economics can also be beneficial. Many data analyst positions also require experience, so internships or entry-level positions in data-related roles can be a great way to gain practical experience and make connections in the industry.</p><p>One important aspect of being a data analyst is the ability to work with large and complex datasets. This requires not only strong technical skills, but also the ability to effectively manage and organize data. Tools such as Hadoop and Spark can be useful for storing and processing large amounts of data, and experience with these technologies can be valuable for data analysts.</p><p>Another important consideration is the ability to choose the appropriate tools and technologies for a given task. Data analysts should be familiar with a range of software and programming languages, and be able to select the most appropriate one for a particular project. This may require learning new technologies on the job, as the field is constantly evolving.</p><p>In addition to technical skills, it is also important for data analysts to have strong problem-solving and critical thinking abilities. Data analysts are often faced with complex and open-ended problems, and must be able to think creatively and critically to arrive at solutions.</p><p>Finally, data analysts should be comfortable working with ambiguity and uncertainty. Data is often messy and incomplete, and it is the data analyst’s job to make sense of it and extract insights despite these challenges.</p><p>In summary, becoming a data analyst requires a strong foundation in mathematics and statistics, programming skills, and the ability to effectively visualize and communicate data. It also requires the ability to manage and work with large and complex datasets, choose the appropriate tools and technologies, and solve problems creatively. Strong problem-solving, critical thinking, and communication skills are also essential, as is the ability to work with ambiguity and uncertainty. With dedication and hard work, you can develop the skills necessary to succeed in this rewarding field.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FAYWLZ1lES6g%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DAYWLZ1lES6g&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FAYWLZ1lES6g%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b08d87d31294f8feadf9236cad25e652/href">https://medium.com/media/b08d87d31294f8feadf9236cad25e652/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e474f4e2325" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/what-you-need-to-know-to-become-a-data-analyst-7e474f4e2325">What You Need To Know To Become A Data Analyst</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Turning Calendar Year To Fiscal Year in R]]></title>
            <link>https://blog.devgenius.io/turning-calendar-year-to-fiscal-year-in-r-da9037a461dd?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/da9037a461dd</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[business-analysis]]></category>
            <category><![CDATA[r]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Tue, 20 Dec 2022 17:38:26 GMT</pubDate>
            <atom:updated>2022-12-21T21:11:42.249Z</atom:updated>
            <content:encoded><![CDATA[<p>An idea flashes into my mind, so I start noting it down right away in case I might forget after that. Today’s focus will be how to turn calendar year into fiscal year. What is a fiscal year?</p><blockquote>“The fiscal year end is the date on which a company finishes a 12-month business cycle. Most companies’ fiscal years are different than the calendar year, ending on dates other than Dec. 31. This is particularly important for seasonal businesses like retail stores that do increased business around the end of the year and need to concentrate capacity on sales and production instead of counting inventory.</blockquote><blockquote>Common fiscal year-end dates include March 31, June 30 and Sept. 30. All of Canada’s major domestic private banks end their fiscal year on Oct. 31.”</blockquote><p><em>Source: </em><a href="https://www.bdc.ca/en/articles-tools/entrepreneur-toolkit/templates-business-guides/glossary/fiscal-year-end"><em>What is a fiscal year end | BDC.ca</em></a></p><p>That being said, the data is stored in the database as calendar year in the most case. If your calculation is based on fiscal year, you need to convert from calendar year to fiscal year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*c94sKeEXRBi-dJoS146ubA.png" /><figcaption>Turning Calendar Year to Fiscal Year in R</figcaption></figure><h3>Scenario 1</h3><p>This dataset includes 8 projects assigned to 8 different people from 2019 to 2022 with certain amount of money. Your task is to turn calendar year to fiscal year as a first step.</p><pre>library(dplyr)<br>library(lubridate)<br>df &lt;- structure(list(FULL_NAME = c(&quot;Peter Smith&quot;, &quot;Tom Hilton&quot;, &quot;Jack Donoban&quot;, &quot;Anna Selena&quot;, &quot;Robyn Wheeler&quot;, &quot;Catherine Johnson&quot;, &quot;Brandon Aves&quot;, &quot;Marry Collin&quot;), <br>                     PROJECT = c(&quot;Healthy Sleep for Adults&quot;, &quot;Bike-Sharing Scheme in Ottawa&quot;, &quot;Benefits of doing Exercises&quot;, &quot;Data Analysis for beginners&quot;, &quot;Survive in Economic Downturn&quot;, &quot;Unemployment rate in the past 5 years in Canada&quot;, &quot;Home-based learning and its Benefits&quot;, &quot;Social Network and its Impact on Teenagers&quot;), <br>                     AMOUNT = c(7500, 8500, 8000, 7700, 8450, 9000, 8800, 7900), <br>                     CAL_DATE = as.Date(c(&quot;2022-01-25&quot;, &quot;2021-07-15&quot;, &quot;2021-02-22&quot;, &quot;2022-10-21&quot;, &quot;2020-08-30&quot;, &quot;2019-03-30&quot;, &quot;2022-05-17&quot;, &quot;2021-10-10&quot;))), class = &quot;data.frame&quot;, row.names = c(NA, -8L))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*yA-V10m8qgucNUAGRB0xkg.png" /></figure><p>Let’s assume your company’s fiscal year starts from <strong>April 1</strong> to <strong>March 31</strong>. Look at the following dates and answer what are the fiscal years?</p><ul><li>2022–01–25</li><li>2020–08–30</li><li>2019–03–30</li></ul><p><strong>The answer is:</strong></p><p>1. Fiscal Year <strong>2022</strong>, or Fiscal Year <strong>2021–2022</strong></p><p>2. Fiscal Year <strong>2021</strong>, or Fiscal Year <strong>2020–2021</strong></p><p>3. Fiscal Year <strong>2019</strong>, or Fiscal Year <strong>2018–2019</strong></p><p>At a glance, we could tell it immediately the fiscal year of the given date. The question is how we tell the system to create a new column with the fiscal year based on calendar year. The logic is simple as the following:</p><p><strong>2022–01–25</strong>: Whenever the month of the calendar year <strong>is greater than 3</strong> (the month of March), the fiscal year will be added <strong>1 year</strong>. If the month is <strong>less than 3</strong>, the fiscal year will be kept <strong>the same as the calendar year</strong>. In this example, we can see <strong>01 (January) is less than 03 (March)</strong>, so the fiscal year is the same as the calendar year-<strong>2022</strong>.</p><p>With that in mind, we can use <strong>ifelse</strong> statement to achieve our goal.</p><pre>df2 &lt;- df %&gt;% <br>  mutate(FISCAL_YEAR = ifelse(month(CAL_DATE)&gt;3, year(CAL_DATE)+1, year(CAL_DATE)))<br># if the month &gt; 3, FICAL_YEAR will be added 1, if not FISCAL_YEAR will be <br># the same year as CAL_DATE</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*RyuVG8tObpIudOLgOj-niA.png" /><figcaption>Convert Calendar Year to Fiscal Year</figcaption></figure><p>The <strong>ifelse</strong> statement means: <strong>ifelse</strong>(<strong>condition</strong>, <strong>result when it is true</strong>, <strong>result when it is false</strong>)</p><p><strong>month()</strong> and <strong>year()</strong> function from <strong>lubridate</strong> package will return the month and the year (numeric number) of the given date respectively.</p><h3>Scenario 2</h3><p>Now you have already known how to get the fiscal year from calendar year. What about <strong>fiscal months</strong>?</p><p>If the fiscal year begins from April, then this is a summary table of the equivalence months between calendar year and fiscal year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKpM0CzMiGtwlcUTmj2ESw.png" /></figure><p>The idea here is that you tell the system to convert from calendar month to fiscal month as the image above (the right order). How does the system know what the right order is? At this step, you may think of giving a vector with the exact order. Below is one of the possible solutions.</p><pre>fis_month &lt;- c(10,11,12,1,2,3,4,5,6,7,8,9)<br>df2 &lt;- df %&gt;% <br>  mutate(FISCAL_YEAR = ifelse(month(CAL_DATE)&gt;3, year(CAL_DATE)+1, year(CAL_DATE)),<br>         FISCAL_MONTH = fis_month[month(CAL_DATE)])</pre><p>First, we need to create a vector imitating the order of the fiscal month like the image. Just a question for you. How do we get the value of the vector based on its index? To be more specific, we want to get the value of the first element in <strong>fis_month</strong> vector, which is <strong>10</strong>. How can we do?</p><pre>fis_month[1] # it will return 10.<br>#[1] 10<br>fis_month[4] # it will return 1.<br>#[1] 1</pre><p>Now you know how to get value from a vector based on its index. Let’s look at the image one more time. If we could get the month of the calendar year and pass it to the <strong>fis_month</strong> vector as an index, it will return the equivalent month of the fiscal year. <strong>month(CAL_DATE)</strong>will return the month of <strong>CAL_DATE</strong> column (numeric). This number is now served as an index in <strong>fis_month[].</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U6GXO6W9DgTpLW3EJ_FZJg.png" /><figcaption>From Calendar Month to Fiscal Month</figcaption></figure><h3>Scenario 3</h3><p>You have got to know how to get the fiscal year and fiscal month. Now it comes to our mind that what the fiscal quarter is? To get the fiscal quarter, it is very similar to scenario 2. We need to create a quarter vector with an order which is equivalent to each month of the calendar year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kN4zkRFFKyCANIYzr8dFgQ.png" /></figure><pre>fis_qua &lt;- c(4,4,4,1,1,1,2,2,2,3,3,3)<br>df2 &lt;- df %&gt;% <br>  mutate(FISCAL_YEAR = ifelse(month(CAL_DATE)&gt;3, year(CAL_DATE)+1, year(CAL_DATE)),<br>         FISCAL_MONTH = fis_month[month(CAL_DATE)],<br>         FISCAL_QUARTER = fis_qua[month(CAL_DATE)])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Th5_vFNxciluq3EX4cbSFg.png" /><figcaption>From Calendar Quarter to Fiscal Quarter</figcaption></figure><p>It works the same way as the fiscal month in Scenario 2, so I will not go into detail as it repeats the content itself. At this step, to calculate the total funding per fiscal month, quarter or year, you only need to group them and add up those number together. Some people prefer to export an Excel file and work with pivot table, while others like to code in R.</p><h3>Bonus</h3><p>Looking at the fiscal year column, we can see that they are all numeric numbers. If you want to change the name convention format (ie. From <strong>2022</strong> to <strong>FY2122</strong>), we can modify easily.</p><pre># Custom function to extract the character from the right of the text string<br>my_right &lt;- function(data, num){<br>  str_sub(data, start = str_length(data)-num+1)<br>}<br><br>df2 &lt;- df %&gt;% <br>  mutate(FISCAL_YEAR = ifelse(month(CAL_DATE)&gt;3, year(CAL_DATE)+1, year(CAL_DATE)),<br>         FISCAL_YEAR2 = paste0(&quot;FY&quot;, my_right(FISCAL_YEAR-1,2), my_right(FISCAL_YEAR,2)),<br>         FISCAL_MONTH = fis_month[month(CAL_DATE)],<br>         FISCAL_QUARTER = fis_qua[month(CAL_DATE)])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDY7g6IRLD2l0j6NaTzfdA.png" /><figcaption>From Calendar Quarter to Fiscal Quarter</figcaption></figure><p>For simplicity, let’s make another column named <strong>FISCAL_YEAR2</strong>. This column will contain a string of <strong>FY</strong> and <strong>2</strong> last digits of fiscal years. (ie <strong>2022</strong> or <strong>2021–2022</strong> or <strong>FY2122</strong>). <strong>my_right()</strong> is a custom function , basically it works the same as the <strong>RIGHT()</strong> function in Excel. This function will extract the number the number of characters from the right of a text string. In our case, we only need to extract 2 last digits, so we input as <strong>2.</strong> If you want to learn more about <strong>LEFT()</strong>, <strong>MID()</strong>, and <strong>RIGHT()</strong> custom function in R, see <a href="https://medium.com/@michaeltvu/how-to-convert-left-mid-and-right-into-r-cd6f20e902ef">this article</a>.</p><h3>References</h3><p>Fiscal Year: <a href="https://www.bdc.ca/en/articles-tools/entrepreneur-toolkit/templates-business-guides/glossary/fiscal-year-end">What is a fiscal year end | BDC.ca</a></p><p>Fiscal Year Calculation: <a href="https://www.contextures.com/fiscalyearcalculations.html#:~:text=To%20get%20the%20fiscal%20year,%3DC4%2C1%2C0)">Excel Fiscal Year Calculations (contextures.com)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da9037a461dd" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/turning-calendar-year-to-fiscal-year-in-r-da9037a461dd">Turning Calendar Year To Fiscal Year in R</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Convert Date Format in R]]></title>
            <link>https://blog.devgenius.io/r-for-haters-how-to-convert-date-format-50583214e1c8?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/50583214e1c8</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-analyst]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Thu, 15 Dec 2022 21:59:57 GMT</pubDate>
            <atom:updated>2022-12-18T19:21:35.142Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I have worked on multiple projects including date time fields in the datasets. Most of the time I need to convert the date time into <strong>ISO 8601 Date Format</strong> (ex: <strong>YYYY-MM-DD</strong>). The date fields I have been working with coming from all kinds of types. Especially, when joining multiple datasets together, <strong>NA </strong>value may be introduced when these formats are not consistent. Also, I am not able to calculate time duration or create graphs with date fields stored as a text. It will never be a problem to tidy up manually when my workload is slowing down. But you need to think it in a long run, every time you clean up those fields manually can add up a huge ton of time. We as data analysts have other priorities to complete as well. For that reason, I like to share some ideas and insights when dealing with <strong>Date Time format</strong> so that we could boost productivity at work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*MrKuIUzr2XMk62OAb-WQ5A.png" /><figcaption>How to convert date format in R</figcaption></figure><p>When working on big projects, we often gather data from different sources. That explains why there are many cases even the same fields having different formats. This deters data analyst from speeding up the data cleaning process because of this inconsistency. I notice many times the date fields which are stored as text or numeric or a bunch of different formats.</p><p>Some popular Date format types:</p><ul><li><strong>MM/DD/YYYY</strong> (12/24/1990)</li><li><strong>DD/MM/YYYY</strong> (24/12/1990)</li><li><strong>YYYY/MM/DD</strong> (1990/12/24)</li></ul><p>Learn more about different date time formats <a href="https://www.ibm.com/docs/en/cmofz/10.1.0?topic=SSQHWE_10.1.0/com.ibm.ondemand.mp.doc/arsa0257.htm"><strong>here</strong></a>.</p><p>After you have scanned through these formats, now you have a better idea what the date field might look like in your datasets. To convert from one format to another, we need to tell the computer the right way. If we do not specify correctly, the result may turn out to be completely different from our expectation. How do we tell the computer what we want exactly?</p><p>Date Format Summary Table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*vXZh2NyUHFBuTpaFZOh2Ow.png" /></figure><p>There are many more, but I just get some of them here. If we have the date as <strong>2022–12–24</strong>, computer understands that it is <strong>%Y-%m-%d</strong> format. Similarly, <strong>24 Dec 2022</strong>, the computer digests as <strong>%d %b %Y </strong>(having the space between). The important thing here is the <strong>Symbol</strong>, the separators can be <strong>the dashes </strong>(-), <strong>the spaces </strong>( ), <strong>forward slashes</strong> (/) and so on.</p><h3>Scenario 1</h3><p>Let’s take a closer look on a specific example. I have a dataset with the format as below, and I want to convert the <strong>BIRTHDAY </strong>column into my computer system format (<strong>YYYY-MM-DD</strong>), how can we do?</p><pre>library(dplyr)<br>df &lt;- data.frame(BIRTHDAY = c(&quot;24/12/1990&quot;, &quot;01/07/1980&quot;))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*INw7Hq9E7W-lA4SRkQZydg.png" /></figure><p>You can use <strong>as.Date() </strong>function, which you can input the data and the format as following.</p><pre>df &lt;- df %&gt;% <br>  mutate(NEW_FORMAT = as.Date(as.character(BIRTHDAY), format = &quot;%d/%m/%Y&quot;))</pre><p>The result works as expected. Basically, you tell the computer, hey treat the BIRTHDAY column as character having the format <strong>“%d/%m/%Y” (day/month/year)</strong> and convert it to your computer system date format with the help of <strong>as.Date()</strong> function. My computer system has the <strong>YYYY-MM-DD</strong> (2022–12–15) format, yours might be different from mine, so you can expect different result in your new column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*0PerFqBJAYZVT5b1LowIaA.png" /></figure><h3>Scenario 2</h3><p>Now imagine your data has multiple formats in the same column, how can you convert all these formats into one format?</p><pre>df &lt;- data.frame(date_time = c(&quot;24/12/1990&quot;, &quot;01/07/1980&quot;, &quot;2000-12-24&quot;, <br>                               &quot;24 Nov 2005&quot;, &quot;September 24, 2010&quot;, <br>                                &quot;Jul 24, 2016&quot;, &quot;12/24/21&quot;))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*otxdLDLpl6oWKzrKUUAemQ.png" /></figure><p>Because there are many more other formats as well, in this example I just get some of them for this illustration, you might expect other different formats in your datasets. But don’t worry, once you understand the basic you can adjust easily.</p><p>In this case, we can apply the same method as scenario 1 which specify only one format. Now we need to specify all these formats and put it into a vector. Let’s specify these formats together with me.</p><pre>Specification:<br>24/12/1990: =&gt; %d/%m/%Y<br>01/07/1980: =&gt; %m/%d/%Y<br>2000-12-24: =&gt; %Y-%m-%d<br>24 Nov 2005: =&gt; %d %b %Y<br>September 24, 2010: =&gt; %B %d, %Y<br>Jul 24, 2016: =&gt; %b %d, %Y<br>12/24/21: =&gt; %m/%d/%y</pre><pre>df &lt;- df %&gt;% <br>  mutate(NEW_FORMAT = as.Date(as.character(BIRTHDAY), <br>format = c(&quot;%d/%m/%Y&quot;, &quot;%m/%d/%Y&quot;, &quot;%Y-%m-%d&quot;, <br>&quot;%d %b %Y&quot;, &quot;%B %d, %Y&quot;, &quot;%b %d, %Y&quot;, &quot;%m/%d/%y&quot;)))</pre><p>You are telling the computer, hey treating the BIRTHDAY as character with of one the above date formats, if the formats are matched, then convert it into the date format of your computer system. If not, it will return NA value. Here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*z6TdpK2FpSvTmZvYqC0DBA.png" /></figure><p>Now you know how to convert multiple date formats into a single one. Every time you see a new format is in your data, you can add to the <strong>format vector c()</strong>. At this step, if you want to create a function for reusing in the future, you are encouraged to do so.</p><pre>convert_date &lt;- function(date_data){<br>  as.Date(as.character(date_data), <br>format = c(&quot;%d/%m/%Y&quot;, &quot;%m/%d/%Y&quot;, &quot;%Y-%m-%d&quot;, &quot;%d %b %Y&quot;, <br>&quot;%B %d, %Y&quot;, &quot;%b %d, %Y&quot;, &quot;%m/%d/%y&quot;)) <br>}<br>df &lt;- df %&gt;% <br>  mutate(NEW_FORMAT = convert_date(BIRTHDAY))</pre><p>It returns the same result, and now every time you need to convert the date data, you can only need one line of code. If you discover new data formats, simply add the format to the function.</p><h3>Scenario 3</h3><p>In this scenario, it is very straightforward to convert various data formats into one format. You can use <strong>lubridate</strong> package with only one line of code. Using the same example above</p><pre>library(dplyr)<br>library(lubridate)<br>df &lt;- data.frame(BIRTHDAY = c(&quot;24/12/1990&quot;, &quot;01/07/1980&quot;, &quot;2000-12-24&quot;, <br>                              &quot;24 Nov 2005&quot;, &quot;September 24, 2010&quot;, <br>                              &quot;Jul 24, 2016&quot;, &quot;12/24/21&quot;)) <br>df &lt;- df %&gt;% <br>  mutate(converted_date = parse_date_time(BIRTHDAY, <br>orders = c(&quot;mdy&quot;, &quot;dmy&quot;, &quot;ymd&quot;)))</pre><p>It returns the same output as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*YV4oZpaOQX4hLZouAMOSlw.png" /></figure><p>Once again, there are multiple ways to convert date format from one to another. I draw different scenarios and analyze the different ways to solve the problem. By doing so we learn how to find out solutions step by step. This is considered as a foundation for further problems. When we break down the issue into small species, it will be much easier to handle one by one. Visit <a href="https://lubridate.tidyverse.org/reference/parse_date_time.html"><strong>here</strong></a><strong> </strong>to learn more about <strong>parse_date_time</strong> and <strong>lubridate</strong> package.</p><h3>Scenario 4</h3><p>Wow wow wow, four different scenarios for today’s article. Sometimes you want to convert into a specific format, not your computer system format. Let’s say you want to convert <strong>2016/07/24</strong> to <strong>Jul 2016, </strong>how can we do?</p><p>Sometimes manager wants to have a report with a graph that he/she only want to filter based on <strong>Month </strong>and <strong>Year</strong>. It is very handy to convert date with month and year only. You can use <strong>format()</strong> function, with this function you can input the date column and the input the desired format to be converted. Let’s look at this example.</p><p>Using the same example with <strong>scenario 3</strong>, now we add one more column with <strong>Month </strong>and <strong>Year </strong>format only.</p><pre>df &lt;- data.frame(BIRTHDAY = c(&quot;24/12/1990&quot;, &quot;01/07/1980&quot;, &quot;2000-12-24&quot;, <br>                              &quot;24 Nov 2005&quot;, &quot;September 24, 2010&quot;, <br>                              &quot;Jul 24, 2016&quot;, &quot;12/24/21&quot;)) <br>df &lt;- df %&gt;% <br>  mutate(NEW_FORMAT = parse_date_time(BIRTHDAY, <br>  orders = c(&quot;mdy&quot;, &quot;dmy&quot;, &quot;ymd&quot;))) %&gt;% <br>  mutate(DESIRED_FORMAT = format(NEW_FORMAT, &quot;%b %Y&quot;))</pre><p>This is how it looks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*LJR5h3uUvC82ip4AMSpx4Q.png" /></figure><p>With some handy method to handle with date types, now you can boost your productivity a little bit. By improving little by little every day, it will be compounded with huge effects down the road.</p><h3>References:</h3><p>Lubridate package: <a href="https://lubridate.tidyverse.org/reference/parse_date_time.html">User friendly date-time parsing functions — parse_date_time • lubridate (tidyverse.org)</a></p><p>Date format: <a href="https://www.r-bloggers.com/2013/08/date-formats-in-r/">Date Formats in R | R-bloggers</a></p><p>ISO Date and Time Format: <a href="https://www.techtarget.com/whatis/definition/ISO-date-format#:~:text=The%20ISO%20standard%20takes%20a,or%202022%2D07%2D15.">What is the ISO date and time format? (techtarget.com)</a></p><p>IBM Date and Time Format: <a href="https://www.ibm.com/docs/en/cmofz/10.1.0?topic=SSQHWE_10.1.0/com.ibm.ondemand.mp.doc/arsa0257.htm">Date and Time Formats — IBM Documentation</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50583214e1c8" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/r-for-haters-how-to-convert-date-format-50583214e1c8">How To Convert Date Format in R</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[R for Haters: How To Extract Word/Number Inside Parentheses]]></title>
            <link>https://blog.devgenius.io/r-for-haters-how-to-extract-word-number-inside-parentheses-c0fc775de9bc?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0fc775de9bc</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-analyst]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Mon, 05 Dec 2022 20:27:59 GMT</pubDate>
            <atom:updated>2022-12-07T11:10:04.498Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with people data, I have many chances to deal with name and an extra parenthesis with information inside such as year of birth, states, or country and so on. This information sometimes needs to be extracted into a separated column so that we could use for further data analysis. Although there are many different cases, today we learn the basic way to extract everything inside a single pair of parentheses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*yRhUdTcX14dM569CdqJJGA.png" /><figcaption>How To Extract Word/Number Inside Parentheses</figcaption></figure><h3>Scenario 1</h3><p>Here is an example data frame. This <strong>FULL_NAME </strong>column contains names with an extra year of birth inside the parentheses.</p><pre>library(dplyr)<br>library(stringr)<br>df &lt;- data.frame(<br>FULL_NAME = c(&quot;Aleksander, Fraser (1990)&quot;,&quot;Eden, Connor (1980)&quot;,<br>&quot;Joao, Snider (2000)&quot;), <br>STATES = c(&quot;Ohio&quot;, &quot;California&quot;, &quot;Ontario&quot;))</pre><p>When it comes to extract number from a pair of parentheses, we may think about a pattern using <em>regular expression</em> (<em>regex</em>). Take a second to think of a possible way to extract the number inside parentheses. You can see what we want to extract is the number after <strong>the open parenthesis</strong> and <strong>before the close parenthesis</strong>. You might hear about the <strong>Lookahead/Lookbehind</strong> regex.</p><ul><li><strong>Lookahead</strong>: <strong>(?=) </strong>(requires PERL = TRUE), e.g. (?=yx): position followed by ‘xy’</li><li><strong>Lookbehind</strong>: <strong>(?&lt;=)</strong> (PERL = TRUE), e.g. (?&lt;=yx): position following ‘xy’</li></ul><p>Now we get the basic ingredients to extract the number inside the parentheses. The logic is to extract the number behind <strong>(</strong></p><p>And ahead <strong>). </strong>I enter a new line here, so you are not confused. We are looking for what to go after the ( with this syntax <strong>(?&lt;=\\().</strong> We need to escape <strong>( </strong>with \\. Next step, we need to look for what to go before the <strong>)</strong> with this syntax <strong>(?=\\))</strong>, we also need to escape the <strong>) </strong>with \\.</p><p>Here is the final regex of what we just discuss above: <strong>“(?&lt;=\\()\\d+(?=\\))”.</strong> You might wonder what does <strong>\\d+</strong> mean? It will match digit at least <strong>1</strong> time inside the parentheses.</p><pre>Summary:<br>(?&lt;=\\(): Look behind the open parenthesis<br>(?=\\): Look ahead the close parenthesis<br>\\d+: Match digits at least 1 time</pre><p>It is time to write a function so that we can reuse for future projects. This function will extract digits inside the parentheses, note that this pattern is valid for our specific case as a sample data above. If your case is different, you can adjust the regex to capture what you want.</p><pre>#Function to extract number inside parentheses<br>ex_num &lt;- function(data){<br>  str_extract(data, &quot;(?&lt;=\\()\\d+(?=\\))&quot;)<br>}<br><br>df2 &lt;- df %&gt;%<br>  mutate(YOB = ex_num(FULL_NAME))</pre><p>Result looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*lA0403kUKITH9JA3hFoQMQ.png" /></figure><h3>Scenario 2</h3><p>In this case, <strong>FULL_NAME </strong>column includes both states and year of birth inside the parentheses. Your task is to extract the state into a separated column, how would you adjust the regex to capture that?</p><pre>df &lt;- data.frame(<br>FULL_NAME = c(&quot;Aleksander, Fraser (Ohio, 1990)&quot;,<br>&quot;Eden, Connor (California, 1980)&quot;,&quot;Joao, Snider (Ontario, 2000)&quot;))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*Jz8b5ksN0tTa0305wQ6YQQ.png" /></figure><p>This case is quite different from scenario 1, which captures digits inside the parentheses. However, in this case, we only want to capture the state name. We need to modify the regex a little bit to catch it. For <strong>Lookahead</strong> part, we change from <strong>\\(</strong> to <strong>,</strong></p><pre>ex_word &lt;- function(data){<br>  str_extract(data, &quot;(?&lt;=\\()\\w+(?=,)&quot;)<br>}</pre><pre>Summary:<br>(?&lt;=\\(): Look behind the open parenthesis<br>(?=,): Look ahead the comma<br>\\w+: Match word characters at least 1 time</pre><p>The regex means we are looking for word characters after the <strong>open parenthesis</strong> until the <strong>comma</strong>. Below is the result when we run the code.</p><pre>df2 &lt;- df %&gt;% <br>  mutate(STATE = ex_word(FULL_NAME))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*0Ng2sheTYDgTAKNQ43brzA.png" /></figure><p>At this step, you may ask how you could extract both state and year of birth into 2 separated columns. That is a good point. We apply the same principle as two examples above. Here is how to extract year of birth to another column. This pattern will capture the year within parentheses</p><p><strong>(?&lt;=\\(\\w{1,20},\\s)\\d+(?=\\))</strong></p><p><strong>(?&lt;=\\(\\w{1,20},\\s): </strong><em>Look behind the open parenthesis, word characters with a length from 1 to 20, a comma, and a space.</em></p><ul><li><em>For example: Aleksander, Fraser </em><strong><em>(Ohio,</em></strong><em> 1990)</em></li></ul><p>You may wonder why we use <strong>{1,20}</strong> instead <strong>+. </strong>It is because in lookbehind if we use <strong>\\w+</strong> it will throw out below error. Therefore, we need to specify the fixed length. (<em>it’s up to you, in this case I just leave it from 1 to 20</em>)</p><p>Look-Behind pattern matches must have a bounded maximum length</p><pre>df2 &lt;- df %&gt;% <br>  mutate(STATE = ex_paren(FULL_NAME),<br>         YOB = str_extract(FULL_NAME, &quot;(?&lt;=\\(\\w{1,20},\\s)\\d+(?=\\))&quot;))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*YURJ8wHKa3mUIogIeeD5iw.png" /></figure><p>If you need to repeat the same task again and again you may consider writing a function, but if it is not frequently used, you just write the direct code without function.</p><h3>Other Solution</h3><p>As the saying goes “All roads lead to Rome”. That said we have so many ways to achieve our purpose. Another easy way is that we will extract everything inside the parentheses to another column. At this step, we could extract only word or number to 2 separated columns.</p><pre>df &lt;- data.frame(<br>FULL_NAME = c(&quot;Aleksander, Fraser (Ohio, 1990)&quot;,<br>&quot;Eden, Connor (California, 1980)&quot;,&quot;Joao, Snider (Ontario, 2000)&quot;))<br><br>df2 &lt;- df %&gt;% <br>  mutate(PAREN = str_extract(FULL_NAME, &quot;(?&lt;=\\().*(?=\\))&quot;),<br>         STATE = str_extract(PAREN, &quot;\\w+&quot;),<br>         YOB = str_extract(PAREN, &quot;\\d+&quot;))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*4yJetOpRqeOqqxboW1A2rQ.png" /></figure><h3><strong>Summary</strong>:</h3><p>We have so many ways to perform the same tasks. However, in this article I want to go into details as much as possible so that you have more than an idea to solve the same problem. When we do this way, we learn how to analyze a problem and find out the best way for each particular case. If you have any idea or feedback, feel free to let me know.</p><h3>References:</h3><p>R Regex Cheat Sheet: <a href="https://paulvanderlaken.files.wordpress.com/2017/08/r-regular-expression-cheetsheat.pdf">Four Column layout Cheat Sheet (wordpress.com)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0fc775de9bc" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/r-for-haters-how-to-extract-word-number-inside-parentheses-c0fc775de9bc">R for Haters: How To Extract Word/Number Inside Parentheses</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Import Data from Clipboard into R]]></title>
            <link>https://medium.com/@michaeltvu/import-data-from-clipboard-into-r-f977bbb2e4e6?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f977bbb2e4e6</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-cleaning]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Thu, 24 Nov 2022 19:27:53 GMT</pubDate>
            <atom:updated>2022-11-24T19:27:53.941Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes you might wonder how to import the copied data from clipboard into <strong>R</strong>. Especially when you are working on big projects, you need to do some tests with small datasets. For that reason, knowing a quick and simple way to import copied data from the clipboard for testing is very hand in many cases.</p><p>If you don’t know what clipboard is, click <a href="https://en.wikipedia.org/wiki/Clipboard_(computing)">here</a> to learn more. Just imagine when you copy something (<strong>Ctrl+C</strong>) and you have not paste yet. The copied data is saved in “somewhere” you can’t see. But it still exists somewhere in your computer system. The place storing your copied data is called clipboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*T0yFd4AfC525v9WIWyFblg.png" /><figcaption>How to Import Data from Clipboard into R</figcaption></figure><p>When you copy data from somewhere and paste into a <strong>txt</strong> file or an E<strong>xcel</strong> file, you don’t need to save the file, but you are still able to import data into <strong>R</strong>. Below are the steps I did.</p><p>· Copy the data from the internet</p><p>· Paste in the <strong>txt</strong> or <strong>Excel</strong> file without saving the file. Then <strong>Crlt+A</strong> and <strong>Ctrl+C</strong> to copy the whole data one more time</p><p>· Run this line: df &lt;- read.table(“clipboard”, sep = “\t”, header = TRUE)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*n8CWxrlvXLdkjWM9ljncJg.png" /><figcaption>Copy Data from a txt File</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*xLIb4Ms3_kaY-ZhcwDj8nQ.png" /><figcaption>Copy data from an Excel file</figcaption></figure><p>Copy the data from the <strong>txt </strong>or <strong>Excel </strong>file and run this line</p><pre>df &lt;- read.table(&quot;clipboard&quot;, sep = &quot;\t&quot;, header = TRUE)</pre><p>Here is the result. It works as expectation. Within a moment you can import copied data from clipboard into <strong>R</strong>. You don’t need to save the file and get the directory and import data into <strong>R</strong> as usual. This technique saves you lots of time down the road.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*SMmFljHcTBWtoxA7Bj02zA.png" /></figure><p>For some reason, if you forget to copy the date into clipboard and you run the code, it will throw out this error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*PqFHXtYvZpRuMAdiCCiHpA.png" /></figure><h3>Another Short-cut</h3><p>If you don’t want to paste your copied data into a <strong>txt </strong>or an <strong>Excel </strong>file, you could put directly into the code as following:</p><pre>df2 &lt;- read.table(text = &quot;FULL_NAME AGE<br>Peter Smith 22<br>Tom Cuise 33<br>Jack London 77&quot;, sep=&quot;\t&quot;, header = TRUE)</pre><p>It returns the same result. Now you can work on a smaller dataset for testing purposes.</p><h3>SEPARATOR</h3><p>The <strong>sep </strong>above can be varied from one to another. If your data is separated by comma for example, you can adjust the <strong>sep=”,”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*MaIm9_w919l0Hr1q2UIzZQ.png" /></figure><p>Then you adjust as following:</p><pre>df &lt;- read.table(&quot;clipboard&quot;, sep = &quot;,&quot;, header = TRUE)</pre><p>The same result is returned. The separator can be a comma, a tab (\t), a white space, and so on. Depending on your data, then you can select the right separator. Another function you can take into consideration is <strong>read.delim()</strong>, it works similarly to <strong>read.table()</strong> as well.</p><p>From now then on, you know a quick and handy method to import data from clipboard into R. Besides, there other packages provide a similar function to read data from clipboard. From my perspective, I like to use this one because I don’t need to remember functions from different packages. However, it is free to apply what you like best. As the saying goes, all roads lead to Rome. If you have any feedback, feel free to drop your comment and I will see you in the next article.</p><h3>REFERENCE:</h3><p><a href="https://en.wikipedia.org/wiki/Clipboard_(computing)">Clipboard (computing) — Wikipedia</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f977bbb2e4e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Imported Data Headers in R]]></title>
            <link>https://medium.com/@michaeltvu/clean-imported-data-headers-in-r-fdcdad6ad078?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdcdad6ad078</guid>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-analyst]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analytics]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 17:40:27 GMT</pubDate>
            <atom:updated>2022-11-20T22:54:43.813Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever been tired of renaming headers when you import new data files into <strong>R</strong>. The headers from those files are not in good shapes. They can include empty space(s), the dot(s) or mix of lower and upper case. You may take some time to rename them before you start wrangling your data. By the end of our discussion today, you will find an easy technique to clean headers without making any efforts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*beOiHDNKRUwGCfeShqq8sg.png" /><figcaption>How to clean headers in R</figcaption></figure><p>When importing data files such as <strong>excel, csv, txt, r</strong> files into <strong>R</strong>, there are chances that the headers are messy. What do I mean? That means the headers may contain empty space(s), the dot(s) and so on. It might be time-consuming when you need to do extra steps instead of selecting directly those columns. Additionally, having empty spaces or dot(s) in the headers may be a potential risk for future errors, which is very difficult to detect when you write a big chunk of code.</p><p>We will learn how to clean the header right from the beginning when we import new data file into <strong>R</strong>. In my case, I usually work with headers containing empty space(s) and the dot(s), so I make a handy function for myself, then it makes my life easier 😊</p><p>Below is an example of data files with messy header.</p><pre>library(dplyr)<br>library(stringr)<br>df &lt;- tibble(SEQ = 1:3, <br>First.....lAST = c(&quot;Aleksander, Fraser&quot;,&quot;Eden, Connor&quot;,&quot;Joao, Snider&quot;), <br>`last    first` =c(&quot;Fraser, Aleksander&quot;, &quot;Connor, Eden&quot;, &quot;Snider, Joao&quot;))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*egcOiR8E3coHtj4WC_rGBQ.png" /></figure><p>Imagine this is the data file you have just imported and it looks like that. We see the <strong>“First…..lAST”</strong> column contains the dot(s), mix of upper and lower case; the second column <strong>“last first”</strong> contains white space, lower case. This is more complicated when we select those columns.</p><p>Our goal is to replace those white space(s), the dot(s) with an underscore and make them upper case. That being said we will use <strong>regex</strong> (regular expression) to achieve that.</p><pre>clean_header &lt;- function(header){<br>  str_to_upper(str_replace_all(header, &quot;\\s+|\\.+&quot;, &quot;_&quot;))}</pre><p>The pattern <strong>\\s+|\\.+</strong> means: it looks for white space(s) at least one time or the dot(s) at least one time. When the condition is met, those patterns will be replaced by an underscore “<strong>_</strong>”. Then we put them into the <strong>str_to_upper()</strong> to make it upper case.</p><p>To get all the column names of the object, we can use <strong>names()</strong>, in this case <strong>names(df) </strong>and it returns</p><pre>names(df)<br>[1] &quot;SEQ&quot;            &quot;First.....lAST&quot; &quot;last    first&quot;</pre><p>So how we clean all columns with a function we have just created. Wrap the <strong>names(df)</strong> inside the <strong>clean_header()</strong> function and then assign to <strong>names(df)</strong></p><pre>names(df)&lt;- clean_header(names(df))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*SvwTU6nyW9dDaQ5PMMsSTw.png" /></figure><p>It works as expected. From now then on, you can tidy the headers of data when imported into R. It makes your life much easier. Based on this basic idea, you can come up with other pattern to fit your interest and demands. If you have any new ideas, don’t forget to share with us.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdcdad6ad078" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Find Out Duplicates in R]]></title>
            <link>https://blog.devgenius.io/how-to-find-out-duplicates-in-r-715d007c721a?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/715d007c721a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-cleaning]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 18:19:10 GMT</pubDate>
            <atom:updated>2022-11-20T18:40:06.873Z</atom:updated>
            <content:encoded><![CDATA[<p>Cleaning data is an arduous task, and it often requires a lot of time to extract only necessary information for the project. Sometimes you realize that there are the same records which repeat several times in your datasets. This might lead to inaccurate reporting along the way. In today’s topic, I’d like to discuss how we could <em>find out the duplicates in R </em>when doing data analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*tcHqor4pP1rsnqw-qID9tw.png" /><figcaption>How to find duplicates in R</figcaption></figure><p>Let’s look at the sample dataset below:</p><pre>library(dplyr)<br>df &lt;- data.frame(SEQ = 1:10, <br>FIRST_LAST = c(&quot;Aleksander, Fraser&quot;,&quot;Eden, Connor&quot;,&quot;Joao, Snider&quot;,<br>&quot;Micah, Hess&quot;,&quot;Hashim, Burns&quot;,&quot;Joe, Deacon&quot;, &quot;Aleksander, Fraser&quot;, <br>&quot;Micah, Hess&quot;,&quot;Aleksander, Fraser&quot;,&quot;Aleksander, Fraser&quot;))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*A1qyVQ62p7oqMTEqmxTdYw.png" /></figure><p>We can see <strong>Aleksander, Fraser</strong> and <strong>Micah, Hess</strong> are the duplicates. We need to find a solution to filter these duplicates or without duplicates. We can use <strong>duplicated()</strong> function to find out duplicates. Make it a function so that we can reuse it in the future.</p><pre>find_up &lt;- function(data){<br>  data[duplicated(data)]}</pre><p>If you pass a vector of character string, it will return a vector a character string with the duplicates only. For example, <strong>find_up(df$FIRST_LAST)</strong> will return</p><pre>find_up(df$FIRST_LAST)<br>[1]&quot;Aleksander, Fraser&quot; &quot;Micah, Hess&quot; &quot;Aleksander, Fraser&quot; &quot;Aleksander, Fraser&quot;</pre><p>It returns the records correlating to <strong>SEQ</strong> <strong>7, 8, 9</strong> and <strong>10</strong>. Do you remember when we want to filter using <strong>%in%</strong> operator, we need a vector, right? The result of <strong>find_up(df$FIRST_LAST)</strong> is a vector. By understanding that we can apply it in the <strong>filter</strong>() function.</p><pre>df2 &lt;- df %&gt;% <br>  filter(FIRST_LAST %in% find_up(FIRST_LAST))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*MbWQDmMt7wPBYEOAlEhc0w.png" /></figure><p>You can see here, it returns all the duplicates with one line of code. Now you have a closer look on your duplicates, and then decide to keep those or to remove them. In the meantime, if you wish to filter names which are not duplicated at all, you can use <strong>not </strong><strong>%in%</strong> operator with <strong>an</strong> <strong>exclamation mark</strong> (<strong>!</strong>) as following:</p><pre>df2 &lt;- df %&gt;% <br>  filter(!FIRST_LAST %in% find_up(FIRST_LAST))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*OGkQNB-pUOuWwgAH8PjeJA.png" /><figcaption>Non-duplicated names</figcaption></figure><p>At this step, you are able to find out the duplicates as well as non-duplicates. You might wonder how you can get the distinct/unique values only. You can use <strong>distinct()</strong> to do so.</p><pre>df2 &lt;- df %&gt;% <br>  distinct(FIRST_LAST, .keep_all = TRUE)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*jEHkgyBv6_KWzuIQlmDjmg.png" /><figcaption>Removing duplicates in R</figcaption></figure><p>Remember the option with <strong>.keep_all = TRUE</strong>, if you don’t specify <strong>.kepp_all = TRUE</strong>, it will return only the column <strong>FIRST_LAST</strong>. If you specify <strong>.keep_all = TRUE</strong>, it will keep other columns as well.</p><p>Filtering out duplicates is really important part in data analysis. It gives you a closer look on your data. At this step you may can examine and make a decision whether to keep or remove them depending on your context.</p><p>With small tip today when working with duplicates, I hope you find it useful and don’t forget to give me any feedback you have.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=715d007c721a" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/how-to-find-out-duplicates-in-r-715d007c721a">How to Find Out Duplicates in R</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swap First and Last Name in R]]></title>
            <link>https://medium.com/@michaeltvu/swap-first-and-last-name-in-r-87e29f960b89?source=rss-f258f10222f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/87e29f960b89</guid>
            <category><![CDATA[regular-expressions]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[r]]></category>
            <dc:creator><![CDATA[Michael T Vu]]></dc:creator>
            <pubDate>Wed, 09 Nov 2022 03:12:09 GMT</pubDate>
            <atom:updated>2022-12-16T15:58:27.594Z</atom:updated>
            <content:encoded><![CDATA[<p>In the last article, we discussed how we converted LEFT(), MID() and RIGHT() function from <strong>Excel</strong> to <strong>R</strong>. Today we will find out how to swap first and last name / last and first name conversely. By creating a handy function, it will make your life much easier when you work with multiple datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*wMImN3GzlNckKEIRZL1JLg.png" /><figcaption>How to Swap Name in R</figcaption></figure><p>There are chances we need to work with different datasets and in many cases the name column is never the same. That being said it might be <strong>LAST_FIRST</strong> name in this dataset, but it might be <strong>FIRST_LAST</strong> name in another one. We cannot join two tables together because the name column from both tables is not matched. We need to convert the name column in the same format, whether the first and last name or last and first name so that we can join them together.</p><p>In other cases, you want to make some changes to fit with the company’s format. There are many ways you can do depending on the tools you used. Let’s build this function together.</p><p>Below is the sample dataset including the <strong>FIRST_LAST</strong> name format. If we want to change it to <strong>LAST_FIRST</strong> name format? How could we do?</p><pre>df &lt;- data.frame(FIRST_LAST = c(&quot;Aleksander, Fraser&quot;,&quot;Eden, Connor&quot;,<br>&quot;Joao, Snider&quot;,&quot;Micah, Hess&quot;,&quot;Hashim, Burns&quot;,&quot;Joe, Deacon&quot;))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*cHoE0Fuw8l2EjLnI0iRWkg.png" /><figcaption>How to Swap First and Last Name</figcaption></figure><p>Supposing that FIRST and LAST name is separated by a comma as above. Our expected result is <strong>LAST, FIRST </strong>name (for example: <strong>Fraser, Aleksander </strong>and so on). In Excel, you can easily get it by using <strong>Flash Fill</strong>. However, we are likely to use regular expression in <strong>R</strong>.</p><pre>swap_name &lt;- function(data){<br>  str_squish(sub(&quot;^(.*), (.*)$&quot;, &quot;\\2, \\1&quot;, data))}</pre><p>To understand this function, we will break it down into small pieces.</p><ul><li><strong>sub(pattern, replacement, string)</strong>. Click <a href="https://www.digitalocean.com/community/tutorials/sub-and-gsub-function-r">here</a> to learn more about sub()</li></ul><h4>In the Pattern part:</h4><p>The Pattern “^(.*), (.*)$” means:</p><p><strong>^</strong>: start of the string</p><p><strong>(.*)</strong>: the first group; this group matches any character at least 0 times. This group will match any thing before the comma, which is the first name.</p><p><strong>, </strong>(a comma and a space)</p><p><strong>(.*)</strong> the second group, this group matches any character at least 0 times. This group will match anything after the comma, which is the last name</p><p><strong>$</strong>: end of the string</p><h4>In the Replacement part:</h4><p><strong>\\2, \\1</strong> : now the replacement is constructed by the second group in the pattern (last name), a comma, a space and the first group in the patter (first name). This is called “<strong>backreference</strong>”.</p><p>str_squish() function is in case of trimming any excess trailing and leading white space</p><p>It is time to test our newly function we have just created.</p><pre>df2 &lt;- df %&gt;% <br>  mutate(LAST_FISRT = swap_name(FIRST_LAST))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*_uXXTOmbPOnUZKSWx4MLvw.png" /><figcaption>Swap Name with Regular Expression</figcaption></figure><p>Amazing eh? It works beautifully. From now then on, you can use this function to swap first name and last name easily. This is just one of examples we can swap the name, but it may vary from one to another format. By applying the same principles, you can custom your own pattern to solve your problems.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FEYV3omA24nJWzbwyp1%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fparamountplus-paramount-plus-icarly-EYV3omA24nJWzbwyp1&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2FEYV3omA24nJWzbwyp1%2Fgiphy.gif%3Fcid%3D790b76114e7ad54ed01549f3d446533f244fffc743afb208%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5dd89ebe06f3bc64a2488326e0f8084/href">https://medium.com/media/f5dd89ebe06f3bc64a2488326e0f8084/href</a></iframe><h4>Another Scenario</h4><p>What happens if we have more than one comma? There are many cases the name followed by <strong>Mr/Mrs/Ms</strong> and so on and if we are sure that the part before the first comma is the first name, anything else after the first comma will be last name. Let’s see how it works</p><pre>df &lt;- data.frame(FIRST_LAST = c(&quot;Aleksander, Fraser, Mr&quot;,&quot;Eden, Connor&quot;,<br>&quot;Joao, Snider&quot;,&quot;Micah, Hess&quot;,&quot;Hashim, Burns&quot;,&quot;Joe, Deacon&quot;))<br>swap_name &lt;- function(data){<br>str_squish(sub(&quot;^(.*), (.*)$&quot;, &quot;\\2, \\1&quot;, data))}<br>df2 &lt;- df %&gt;%<br>mutate(LAST_FISRT = swap_name(FIRST_LAST))</pre><p>Here is how it looks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*QxEAkqJC9mjTbCBN1DPtFA.png" /></figure><p>Our expectation is to swap the part before and after <strong>the first comma</strong>, something like <strong>Fraser, Mr, Aleksander</strong>. Not the result shown above. What we want the pattern stops at the first comma but instead it is looking for until the last comma. How to resolve the issue?</p><p>Now we can turn it into <strong>lazy mode</strong> by adding the question mark (<strong>?</strong>), so it only match until the first comma as following</p><pre>swap_name &lt;- function(data){<br>str_squish(sub(&quot;^(.*?), (.*)$&quot;, &quot;\\2, \\1&quot;, data))}</pre><p>Here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*hDnMM9Mpu2HVabnEcEpjVw.png" /></figure><p>It works as our expectation. With this handy function, you can quickly swap first and last name without retyping the same pattern again and again. You can do more than just swap first name and last name. It could be anything based on the basic principle. I hope you find it useful and if you have any feedback, drop a line to let me know.</p><p>Learn how to convert <strong>LEFT()</strong>, <strong>MID()</strong> and <strong>RIGHT()</strong> function from Excel to R <a href="https://medium.com/@michaeltvu/how-to-convert-left-mid-and-right-into-r-cd6f20e902ef">here</a>.</p><h4>REFERENCES</h4><p><a href="https://www.digitalocean.com/community/tutorials/sub-and-gsub-function-r">https://www.digitalocean.com/community/tutorials/sub-and-gsub-function-r</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87e29f960b89" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>