Programming Articles - Page 927 of 3366

How to decode JSON into objects in Golang?

Kiran Kumar Panigrahi
Updated on 01-Nov-2021 06:30:03

1K+ Views

Suppose we have a JSON that looks like this.{ "name":"Mukul Latiyan", "age":10, "sports":[ "football", "tennis", "cricket" ] }Now, we want to convert this JSON into struct fields which we can access later and maybe iterate over too.In order to do that, we need to first make a struct that will satisfy the fields of the above JSON.The struct shown below will work just fine for the above JSON.type Person struct ... Read More

How to create transparent boxplot in R?

Nizamuddin Siddiqui
Updated on 01-Nov-2021 06:31:21

1K+ Views

Be default, the boxplot created in base R or by using ggplot2 are not transparent in nature. If we want to create a transparent boxplot then we can use bwplot function from lattice package.For Example, if we have a vector called X then we can create transparent boxplot of X by using the below command −bwplot(x)Example 1To create transparent boxplot use the snippet given below −library(lattice) bwplot(rnorm(1000))OutputIf you execute the above given snippet, it generates the following Output −Example 2To create transparent boxplot add the following code to the above snippet −library(lattice) bwplot(rpois(1000, 5))OutputIf you execute all the above given ... Read More

Find the column name with the largest value for each row in an R data frame.

Nizamuddin Siddiqui
Updated on 01-Nov-2021 06:22:24

4K+ Views

To find the column name that has the largest value for each row in an R data frame, we can use colnames function along with apply function.For Example, if we have a data frame called df then we can find column name that has the largest value for each row by using the command as follows −df$Largest_Column

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

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

612 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

931 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

378 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

226 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

Advertisements