Convert Data Table Object into a Matrix in R

Nizamuddin Siddiqui
Updated on 16-Oct-2020 13:54:16

355 Views

A data.table object is very similar to a data frame in R, therefore, converting a data.table object to a matrix is not a difficult job. We just need to use as.matrix function and store the data.table object into a new object that will belong to the matrix, otherwise R will not be able to convert the data.object to a matrix. For example, if we have a data.table object DT then to convert it into a matrix, we should use the below example code −DT_matrix

Deal with Warning Message: Removed X Rows Containing Missing Values in R

Nizamuddin Siddiqui
Updated on 16-Oct-2020 13:47:16

981 Views

If we have missing values/NA in our data frame and create a plot using ggplot2 without excluding those missing values then we get the warning “Removed X rows containing missing values”, here X will be the number of rows for the column that contain NA values. But the plot will be correct because it will be calculated by excluding the NA’s. To avoid this error, we just need to pass the subset of the data frame column that do not contains NA values as shown in the below example.Consider the below data frame with y column having few NA values ... Read More

Visualize Two Categorical Variables Together in R

Nizamuddin Siddiqui
Updated on 16-Oct-2020 13:44:32

5K+ Views

The categorical variables can be easily visualized with the help of mosaic plot. In a mosaic plot, we can have one or more categorical variables and the plot is created based on the frequency of each category in the variables. To create a mosaic plot in base R, we can use mosaicplot function. The categories that have higher frequencies are displayed by a bigger size box and the categories that have less frequency are displayed by smaller size box.Consider the below data frame −Example Live Demox1

How PowerShell Pipeline Works - Part 2

Chirag Nagrekar
Updated on 16-Oct-2020 09:49:39

175 Views

In part-1 we have seen the PowerShell pipeline functionality using the ValueFromPipeline property. There is another cmdlet property known as ValueFromPipelineByPropertyName, which is also useful to know the PowerShell pipeline functionality.Like part-1 command, we can get this property name using the same Get-Command but the filter parameter we will use for the property is ValueFromPipelineByPropertyName.The below example is for the Stop-Service cmdlet.(Get-Command Stop-Service).ParameterSets.parameters | where{$_.ValueFromPipelineByPropertyName -eq 'True'} | Select Name, ParameterTypeOutputName ParameterType ---- ------------- Name System.String[]This means you can use Name property to stop the service. So here we will use Get-Service and its Name property to retrieve services and ... Read More

How PowerShell Pipeline Works - Part 1

Chirag Nagrekar
Updated on 16-Oct-2020 09:44:27

199 Views

PowerShell is made easier with the Pipeline structure. With the Pipeline structure, we can pass the input of the left side command output or string to the right side of the command as the input. For example, Get-Service | Out-File c:\services.txtIn the above example, we are passing Get-Service output as an object to the Out-File command which is the right side of the Pipeline as the Input. Before going into detail about how the Pipeline works, we need to understand that every command we write produces output and that output is already formatted by the PowerShell using Pipeline.For example, Get-Process ... Read More

Block Ports on Windows Using PowerShell

Chirag Nagrekar
Updated on 16-Oct-2020 09:39:26

3K+ Views

To block the port using PowerShell on the Windows OS, we need to change the firewall settings using the New-NetFirewallRule command.ExampleWe need to block the port 5985 on the computer. The below code will block all TCP Incoming requests on the 5985 port on the local computer.New-NetFirewallRule -DisplayName "Block WINRM HTTP Port" `                     -Direction Inbound `                     -LocalPort 5985 `                     -Protocol TCP `                     -Action Block To ... Read More

Open a Port in Windows using PowerShell

Chirag Nagrekar
Updated on 16-Oct-2020 09:35:20

2K+ Views

To open a port in the Windows Operating system, we need to know a few things. LikeFor which Profile we need to open port (Public, private, or Domain)? - OptionalWhich port do we need to open (port Number)?The direction of the port – Inbound (i.e Incoming requests) or Outbound (i.e. Outgoing requests).Protocol by name (TCP, UDP, ICMPv4, or ICMPv6) or Number (0-255).Once we have all the details we can open the port. In the below example, we need to open a port 5985 (WINRM HTTP) port on the computer which is currently blocked. So we will use the below command.New-NetFirewallRule -DisplayName "Allow WINRM HTTP Port" ` ... Read More

Change Files and Folders Attributes Using PowerShell

Chirag Nagrekar
Updated on 16-Oct-2020 09:28:49

10K+ Views

There are multiple files and folders attribute supported by the Windows Operating System. To check which attributes that files and folders support use DOS command attrib /?You can see the attributes listed like Read-Only, Archive, etc. You can set the attribute using PowerShell.For example, we have a file called TestFile.txt and its attribute is ReadOnly and we need to change it to the Archive.PS C:\> (Get-ChildItem C:\Temp\TestFile.txt).Attributes ReadOnlyChange Attribute code −$file = Get-ChildItem C:\Temp\TestFile.txt $file.Attributes = 'Archive'So we have set the attribute to the ‘Archive’ from ‘ReadOnly’ and when you check it, the attribute should be changed.PS C:\> (Get-ChildItem C:\Temp\TestFile.txt).Attributes ... Read More

Retrieve Files and Folders Attributes Using PowerShell

Chirag Nagrekar
Updated on 16-Oct-2020 09:20:11

3K+ Views

To retrieve files and folders attributes using PowerShell, you can use Get-Item or Get-ChildItem command. For example, We have a file called testfile.txt to get its attributes, PS C:\> Get-ChildItem C:\Temp\TestFile.txt |Select Name, Attributes Name Attributes ---- ---------- TestFile.txt ArchiveSo this file has the Archive attribute. To retrieve multiple files and folders' attributes, just refer to the folder name instead of the file name.Get-ChildItem C:\Temp -Recurse -Force | Select Name, FullName, Attributes Name ... Read More

Maximum Sum Bitonic Subarray in C++

Ayush Gupta
Updated on 15-Oct-2020 14:00:02

617 Views

In this problem, we are given an array arr[]. Our task is to create a program to find the maximum sum bitonic subarray in C++.Bitonic Subarray is a special subarray in which the element strictly increase first and then strictly decreases after reaching a certain point.Let’s take an example to understand the problem, Inputarr[] = {4, 2, 3, 7 ,9, 6, 3, 5, 1}Output30ExplanationThe bitonic subarray is [2, 3, 7, 9, 6, 3]. Sum = 2 + 3 + 7 + 9 + 6 + 3 = 30Solution ApproachThe solution is similar to that in the bitonic subsequence problem. We ... Read More

Advertisements