Programming Articles - Page 927 of 3363

How to find the quartile for each value in an R vector?

Nizamuddin Siddiqui
Updated on 01-Nov-2021 06:05:00

629 Views

Any numerical data can be divided into four parts (four quarters) by using three quartiles, first quartile at 25%, second quartile at 50% and third quartile at 75% hence there will be four quarters to represent first 25%, second 25%, third 25% and the last 25% in a set of data.If we want to find the quartile (1 to 4) for each value in an R data frame column then we can use the quantile function and cut function as shown in the Examples given below.Example 1Following snippet creates a sample data frame −x

How to match and replace column names stored in R data frames in R-Programming?

Nizamuddin Siddiqui
Updated on 01-Nov-2021 05:57:48

959 Views

If we have a data frame that contains a column of column names which matches with the column names of a data frame and another column that has different values then we can set these different values as the new column names of the data frame having matched column names.This can be done with the help of match function. Check out the below Examples to understand how it works.Example 1Following snippet creates a sample data frame −x1

Convert a data frame with grouping column into a list based on groups in R.

Nizamuddin Siddiqui
Updated on 01-Nov-2021 05:47:37

2K+ Views

To convert a data frame with grouping column into a list based on groups, we can use split function.For Example, if we have a data frame called df that contains a categorical column say Group and a numerical column say DV then we can convert df into a list based on groups in Group column by using the command as mentioned below −split(df$DV,df1$Group).Example 1Following snippet creates a sample data frame −Group

Define column and row names of a square matrix in a single line code if they are same in R.

Nizamuddin Siddiqui
Updated on 01-Nov-2021 05:38:12

394 Views

If we have a square matrix or we want to create a square matrix and the row names and column names for this matrix are same then we can define these names in a single line of code.For Example, if we have a matrix called M that has 10 rows and 10 columns that has first ten alphabets as row and column names then we can define the column names as colnames(M)

Create multiple regression lines in a single plot using ggplot2 in R.

Nizamuddin Siddiqui
Updated on 12-Nov-2021 03:52:33

10K+ Views

To create multiple regression lines in a single plot using ggplot2, we can use geom_jitter function along with geom_smooth function. The geom_smooth function will help us to different regression line with different colors and geom_jitter will differentiate the points.Check out the below Example to understand how it can be done.ExampleFollowing snippet creates a sample data frame −x1

How to subset non-duplicate values from an R data frame column?

Nizamuddin Siddiqui
Updated on 01-Nov-2021 05:02:17

1K+ Views

Generally, the duplicate values are considered after first occurrence but the first occurrence of a value is also a duplicate of the remaining. Therefore, we might want to exclude that as well.The subsetting of non-duplicate values from an R data frame column can be easily done with the help of duplicated function with negation operator as shown in the below Examples.Example 1Following snippet creates a sample data frame −x

Node.js – Immediate Timer Class

Mayank Agarwal
Updated on 29-Oct-2021 08:59:59

240 Views

The Immediate Timer class is used for scheduling the functions that we need to call at a certain period of time in future. These tasks can be scheduled by using the Immediate timer class and using the setImmediate() method. The Immediate class has an object for setImmediate() method and it passes the same object to clearImmediate() in case it wants to cancel the scheduled timer function.Given below are the Immediate class ref objects −1. immediate.ref()This method is called if the immediate object is active for too long and did not exit.Syntaximmediate.ref()2. immediate.unref()This object keeps the event loop ‘active’ until False ... Read More

Node.js – diffieHellman.getPublicKey() Method

Mayank Agarwal
Updated on 29-Oct-2021 08:57:58

296 Views

The diffieHellman.getPublicKey() returns the Diffie-Hellman generated public key that is specified by the encoding passed. It will return a string in case the encoding is passed, else it will return a buffer.SyntaxdiffieHellman.getPublicKey([encoding])Parametersencoding – This parameter specifies the encoding of the return value.Example 1Create a file with the name "publicKey.js" and copy the following code snippet. After creating the file, use the command "node publicKey.js" to run this code.// diffieHellman.getPublicKey() Demo Example // Importing the crypto module const crypto = require('crypto') // Initializing the diffieHellman const dh = crypto.createDiffieHellman(512); // Taking default publicKey as null let publicKey = ... Read More

Node.js – Timeout-hasRef() & Timeout-refresh() methods

Mayank Agarwal
Updated on 29-Oct-2021 08:54:41

2K+ Views

The Timeout object is internally created and is returned from the setTimeout() and setInterval() method. You can use this object and pass it to either clearTimeout() or clearInterval() methods in order to cancel the scheduled actionsFollowing are the timeout class ref objects that can be used to control the default behaviour1. timeout.hasRef()This method keeps the node event loop active as long as its value is True.Syntaxtimeout.hasRef()2. timeout.refresh()This method refreshes the timer’s start time to the current time and reschedules the timer to its callback where the previously specified duration will be adjusted to the current time. This method helps in ... Read More

Node.js – process.channel Property

Mayank Agarwal
Updated on 29-Oct-2021 08:51:11

244 Views

When a node process is spawned with an IPC channel, the process.channel property provides the reference to that IPC channel. If no IPC channel exists, this property is then undefined.Syntaxprocess.channelExample 1Create two files "channel.js" and "util.js" and copy the following code snippets. After creating the files, use the commands "node channels.js" and "node util.js" to run the codes.channel.js// process.channel Property Demo Example // Importing the process modules const cp = require('child_process'); // Getting reference to the child const process = cp.fork(`${__dirname}/util.js`); // Sending the below message to child process.send({ msg: 'Welcome to Tutorials Point' }); console.log(process.channel)util.js// ... Read More

Advertisements