Articles on Trending Technologies

Technical articles with clear explanations and examples

Consider the ambiguous grammar.nE → E + EnE → E * EnE → (E)nE → idn(a) Construct LR (0) items for above grammar.n(b) Construct SLR parsing table for grammar.n(c) Parse the input string id + id * id.

Ginni
Ginni
Updated on 03-Nov-2021 7K+ Views

Problem Statement Consider the ambiguous grammar.E → E + EE → E * EE → (E)E → id(a) Construct LR (0) items for above grammar.(b) Construct SLR parsing table for grammar.(c) Parse the input string id + id * id. SolutionStep1− Construct Augmented Grammar(0) E′ → S(1) E → E + E(2) E → E ∗ E(3) E → (E)(4) E → idStep2− Find closure & goto functions to construct LR (0) items.Closure (E′ → ∙ E) =Applying goto on I9∵ goto cannot be applied on I9, ...

Read More

How to create normal probability plot in R with confidence interval bands?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 2K+ Views

To create normal probability plot in R with confidence interval bands, we can use qqPlot function of QTLRel package. We simply need to pass the vector name that contains normal distribution values inside qqPlot function or directly introduce the vector inside the function as shown in the below given examples.Example 1Use the following code to create normal probability plot −library("QTLRel") qqPlot(rnorm(10))OutputIf you execute the above given snippet, it generates the following Output −Example 2Add the following code to the above snippet to create normal probability plot −qqPlot(rnorm(500)) OutputIf you execute the above given snippet, it generates the following Output −Example ...

Read More

Create a matrix for odd number of elements by filling the last element with NA in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 451 Views

We can find the total number of elements for a matrix with the help of prod and dim function as shown in the below Examples. To create a matrix for odd number of elements by filling the last element with NA, we can use byrow argument.For Example, if we have a vector called V that contains 19 elements then we can create a matrix called M having 20 elements NA as the last element by using the below command −M

Read More

How to create an ID column in R based on categories?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 2K+ Views

If we have a categorical column in an R data frame then it can be used to create an ID column where each category will have its own ID defined on the basis of categories in the categorical column.For this purpose, we would need to read the categorical column with as.factor and as.numeric function as shown in the below examples.Example 1Following snippet creates a sample data frame −Group

Read More

Rotate a matrix by 90 degree without using any extra space in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 03-Nov-2021 658 Views

We are given a 2-D array that will be used to form a matrix pattern. The task is to rotate a matrix by 90 degrees in an anti-clockwise direction such that the first row becomes the first column, second row becomes second column and third becomes third column and the challenge is that we don’t have to use any extra space.Let us see various input output scenarios for this −Input −int arr[row_col_size][row_col_size] = { { 5, 1, 4},    { 9, 16, 12 },    { 2, 8, 9}}Output   −Rotation of a matrix by 90 degree without using any extra space ...

Read More

How to create a scatterplot with larger distance between facets in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 195 Views

By default, the distance/space between facets created by using ggplot2 is very less and it becomes a little uneasy for viewers to separately read the facets. Therefore, to deal with this problem we can increase the space between facets and it can be done with the help of theme function as shown in the example below.ExampleFollowing snippet creates a sample data frame &miuns;x

Read More

How to find the column means for each matrix stored in an R list?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 575 Views

To find the column mean of all matrices stored in an R list, we can use sapply function along with colMeans function.For example, if we have a list called LIST that contains some matrices then the col means for each matrix can be found by using the commandsapply(LIST,colMeans)Check out the below example to understand how it works.ExampleFollowing snippet creates list of matrices −M1

Read More

How to randomly assign participants to groups in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 5K+ Views

To randomly assign participants to groups, we can use sample function.For example, if we have a data frame called df that contains a column say Employee_ID and we want to create five groups that are stored in a vector say Grp then random assignment of participants to values in Grp can be done by using the command given below −df$Grp

Read More

Create an integer column in an R data frame with leading zeros

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 675 Views

To create an integer column in an R data frame with leading zeros, we can use sprintf function.For Example, if we want to create a data frame column having values starting from 1 to 10 and we want to have 1 as 01 and so on then we can use the command given below −data.frame(x=sprintf('%0.2d',1:10))Check out the Examples given below to understand how it works.Example 1To create an integer column in an R data frame with leading zeros, use the command given below −df1

Read More

How to change the Y-axis title in base R plot?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 10K+ Views

The easiest way to change the Y-axis title in base R plot is by using the ylab argument where we can simply type in the title. But the use of ylab does not help us to make changes in the axis title hence it is better to use mtext function, using which we can change the font size, position etc. of the title.Check out the below example to understand how it can be done.ExampleUse the code given below to change the Y-axis title in base R plot −plot(1:10)OutputIf you execute the above given code, it generates the following Output −Add ...

Read More
Showing 47641–47650 of 61,297 articles
Advertisements