Author: Terry

Tech Enthusiast with a passion for teaching others new technology.

How To Select Multiple Columns Using Grep & R

Data Science Using R, Recent Posts
Why you need to be using Grep when programming with R. There's a reason that grep is included in most if not all programming language to this day 44 years later from creation. It's useful and simple to use. Below is an example of using grep to make selecting multiple columns in R simple and easy to read. The dataset below has the following column names. names(data) # Column Names [1] "fips" "state" "county" "metro_area" [5] "population" "med_hh_income" "poverty_rate" "population_lowaccess" [9] "lowincome_lowaccess" "no_vehicle_lowaccess" "s_grocery" "s_supermarket" [13] "s_convenience" "s_specialty" "s_farmers_market" "r_fastfood" [17] "r_full_servi...

Creating Excel Workbooks with multiple sheets in R

Data Science Using R, Data Science, Recent Posts
Create Excel Workbooks Generally, when doing anything in R I typically work with .csv files, their fast and straightforward to use. However, I find times, where I need to create a bunch of them to output and having to go and open each one individually, can be a pain for anyone. In this case, it's much better to create a workbook where each of the .csv files you would have created will now be a separate sheet. Below is a simple script I use frequently that gets the job done. Also included is the initial process of creating dummy data to outline the process. EXAMPLE CODE: Libraries used library(tidyverse) library(openxlsx) Creating example files to work with products <- c("Monitor", "Laptop", "Keyboards", "Mice") Stock <- c(20,10,25,50) Computer_Supplies <...

Sort

Recent Posts, Data Science, Linux
The command sort is used to sort files line by line.  Lines starting with a number go first. Lines that come next in order go alphabetical with uppercase letters appearing before lowercase ones. Use cat to create "testsort" for the example. ~/Test>cat testsort A line 1 a line 2 8 line 3 line 4 5 line 5 ~/Test>sort testsort 5 line 5 8 line 3 A line 1 a line 2 line 4 R sorts by using a random hash of keys ~/Test>sort -R testsorta line 25 line 5A line 18 line 3line 4 ~/Test>sort -R testsort5 line 5A line 1a line 2line 48 line 3

Egrep & Fgrep

Recent Posts, Data Science, Linux
EGREP:             The Command egrep is the same as running grep –E. egrep is used to search for a pattern using extended regular expressions. Terry@f:~/FinderDing>cat testsort A line 1 a line 2 8 line 3 line 4 5 line 5 Terry@f:~/FinderDing>egrep '^[a-zA-Z]' testsort A line 1 a line 2 line 4 *Show lines that start with a letter from alphabet Terry@f:~/FinderDing>cat html <!DOCTYPE html> <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> Terry@f:~/FinderDing>egrep "My|first" html <h1>My First Heading</h1> <p>My first paragraph.</p> `*Find lines with pattern My first from html file FGREP: The command fgrep is the same as running grep –F. The Command searches for fixed character strings in a

The War of Automation

Blog, Recent Posts
What happens when +90% of the jobs are not automated? No longer will we need doctors or surgeons, instead hospitals will just need a single person to decide on moral choices. More of a supervisor that really their time will be spent monitoring the machines. Kids will have no idea humans would drive trucks or even personal vehicles. They'll say "Why did you not care about safety and efficiency. Robots/Machines are better in every aspect." Side note: any movies like Terminator or iRobot will no longer be legal to watch Population Control: Concerns of overpopulation begin to be debated by the top 1%, with no longer having to work or work +40hrs a week births begin to increase. Wars are fought in the cyber world, no longer will militaries need boots on the ground as much rather than boots ...