Select First and Last Row Based on Group Column in R Data Frame

Nizamuddin Siddiqui
Updated on 04-Sep-2020 07:30:13

1K+ Views

Extraction of data is necessary in data analysis because extraction helps us to keep the important information about a data set. This important information could be the first row and the last row of groups as well, also we might want to use these rows for other type of analysis such as comparing the initial and last data values among groups. We can extract or select the first and last row based on group column by using slice function of dplyr package.Example Live DemoConsider the below data frame: > x1 x2 df1 head(df1, 12)Output  x1 x2 1  1  3 2  1 ... Read More

Get List of Data Sets in Base R or Package in R

Nizamuddin Siddiqui
Updated on 04-Sep-2020 07:27:32

8K+ Views

There are many data sets available in base R and in different packages of R. The characteristics of these data sets are very different, for example, some data sets are time series data, some have only numerical columns, some have numerical as well as factor columns, some includes character columns with other type of columns. Therefore, it becomes helpful to everyone who want to learn the use of R programming. To get the list of available data sets in base R we can use data() but to get the list of data sets available in a package we first need ... Read More

Plot Multiple Time Series Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 04-Sep-2020 06:58:38

1K+ Views

For a one point of time, we might have multiple time series data, this could be weather for multiple cities, price variation in multiple products, demand expectancy at different locations, or anything that changes with time and measured for multiple things or locations. If we have such type of time series data then we would be needing to plot that data in a single plot and it can be done with the help of geom_line function of ggplot2 package.ExampleConsider the below data frames − Live Demo> x1 y1 df1 df1Output   x1 y1 1 1 -0.1165387 2 2 -0.9084062 3 3 0.4696637 ... Read More

Change Color of Bars in Bar Plot using ggplot2 in R

Nizamuddin Siddiqui
Updated on 04-Sep-2020 06:54:36

736 Views

The default color of the bars created by using ggplot2 package is grey but we can change that color to any depending on our interest. This change is highly required in professions such as academic writing and analytics because everyone wants to look at attractive images. They are not meant to be useful if you just want to learn the concept but when it comes to practical, you need to do it as attractive images gets more attention, thus, they become memorable. To change the color of the bars in ggplot2, we can use fill argument of geom_bar function.ExampleConsider the ... Read More

How Bats Use Sound to Locate Their Prey

Ridhi Arora
Updated on 03-Sep-2020 16:20:08

594 Views

Bats are mammals which use sound ways to locate their prey. They do so by a scientific technique called 'Echolocation'. This is because they are nocturnal mammals that have weak eyesight. They use their ears more than any other mammal.EcholocationIt is defined as the use of sound waves and echoes to determine the location of objects in space. Bats use this mechanism for finding their food. Just as SONAR (Sound Navigation and Ranging) is used in case of big ships, and tanks, similarly, the emission of sound waves helps bat catch its prey.Bats use ultrasonic waves (20 to 200 kilohertz) ... Read More

Simple Chat Room Using Python

Samual Sam
Updated on 03-Sep-2020 16:10:11

3K+ Views

In this article we will see how to make a server and client chat room system using Socket Programming with Python.The sockets are the endpoints of any communication channel. These are used to connect the server and client. Sockets are Bi-Directional. In this area, we will setup sockets for each end and setup the chatroom system among different clients through the server. The server side has some ports to connect with client sockets. When a client tries to connect with the same port, then the connection will be established for the chat room.There are basically two parts. The server side ... Read More

Find and Replace Word in Text File Using PowerShell

Chirag Nagrekar
Updated on 03-Sep-2020 11:05:00

2K+ Views

To search for the word in PowerShell and replace it in the file we will use the string operation. In fact, the Get-Content command in PowerShell is used to read almost any type of file content. In this article, we are considering one text file as shown below.Get-Content C:\Temp\TestFile.txtOutputPS C:\> Get-Content C:\Temp\TestFile.txt # In case of linux, networkInterface names are of the form eth* # In Windows, please use the network full name from Device Manager networkInterfaces: ["Microsoft Hyper-V Network Adapter" ] overrideMetricsUsingScriptFile: false scriptTimeoutInSec: 60 scriptFiles: - osType: windows filePath: monitors/NetworkMonitor/scripts/windows-metrics.bat - osType: unixBase filePath: monitors/NetworkMonitor/scripts/unix-base-metrics.shThe ... Read More

Difference Between ErrorActionPreference and ErrorAction Cmdlet in PowerShell

Chirag Nagrekar
Updated on 03-Sep-2020 10:58:31

953 Views

As we know $ErrorActionPreference and $ErrorAction both have the same functionality and both are used to handle terminating errors by converting Non-Terminating errors to Terminating errors. But when both the variables are used, we need to know which takes precedence.$ErrorActionPreference variable is used at the start of the script while the $erroraction variable is a common parameter and used with the cmdlet. In some cases, we might need the script to be terminated as soon as an error occurs but inside the script, we have some cmdlets which need to be ignored or continued if the error occurs. In that ... Read More

How ScriptBlock Works in PowerShell

Chirag Nagrekar
Updated on 03-Sep-2020 10:56:07

3K+ Views

Scriptblock is a set of commands which can be executed together when they are invoked. In PowerShell, generally, we write individual commands. Scriptblock can be written with two curly brackets.Example$sb = {Get-Process powershell; Get-Service W32Time}Here we have written two commands under scriptblock. If you directly run this command, scriptblock treats them as a string.PS C:\> $sb Get-Process powershell; Get-Service W32TimeTo run the commands inside the scritblock, use Invoke-Command with the -Scriptblock parameter.Invoke-Command -ScriptBlock $sbOutputHandles NPM(K)    PM(K)    WS(K)    CPU(s)    Id    SI    ProcessName ------- ------    -----    -----    ------    --    --   ... Read More

Copy Files or Folders Without Overwriting Existing Files

Chirag Nagrekar
Updated on 03-Sep-2020 10:48:21

7K+ Views

To copy files/folders on the remote path without overwriting the existing files/folders, you can use multiple cmdlets like Copy-Item, Robocoy, and Xcopy, etc. As Copy-Item is a standard cmdlet, we will check if it's supported parameters can prevent overwriting.If Copy-Item doesn’t work then we will check its alternate command. Copy-Item simply overwrites the files and folders on the destination path and the copies newer files.For example, To copy files from the source folder C:\Test1 to the destination folder C:\Test2 below command is used and it simply overwrites the file without asking.ExampleCopy-Item C:\Test1\* C:\Test2 -Recurse -VerboseOutputPS C:\Temp> Copy-Item C:\Test1\* C:\Test2 -Recurse ... Read More

Advertisements