Change Plot Border Color of a ggplot2 Graph in R

Nizamuddin Siddiqui
Updated on 02-Nov-2021 11:25:46

5K+ Views

To change the plot border color of a ggplot2 graph in R, we can use theme function with panel.background argument where we can set the border of the plot panel using element_rect to desired color.To understand how it can be done, check out the below Example.ExampleFollowing snippet creates a sample data frame −x

Construct SLR Parsing Table and Parse Input String

Ginni
Updated on 02-Nov-2021 11:25:43

50K+ Views

Description − Consider the GrammarE → E + T|TT → TF|FF → F*|a|b.SolutionStep1 − Construct the augmented grammar and number the productions.(0) E′ → E(1) E → E + T(2) E → T(3) T → TF(4) T → F(5) F → F ∗(6) F → a(7) F → b.Step2 − Find closure & goto Functions to construct LR (0) items.Box represents the New states, and the circle represents the Repeating State.Computation of FOLLOWWe can find outFOLLOW(E) = {+, $}FOLLOW(T) = {+, a, b, $}FOLLOW(F) = {+, *, a, b, $}Parsing for Input String a * b + a −Stack    ... Read More

Sum of Column Values Based on Another Numerical Column in R

Nizamuddin Siddiqui
Updated on 02-Nov-2021 11:16:35

605 Views

To find the sum of a column values based on another numerical column in R, we can use with function and define the sum by subsetting the column with the help of single square brackets.For Example, if we have a data frame called df that contains two columns say X and Y then we can find the sum of values in X when Y is greater than 10 by using the command with the following −(df,sum(X[Y10]))Example 1Following snippet creates a sample data frame −x1

Construct SLR(1) Parsing Table for Given Grammar

Ginni
Updated on 02-Nov-2021 11:14:16

4K+ Views

SolutionStep1 − Construct Augmented Grammar(0) S′ → S(1) S → x A y(2) S → x B y(3) A → q S(4) A → q(5) B → qStep2 − Find Closure & goto functions to construct LR (0) items. Here Boxes represent New States and Circles represent the repeating state.Step3 − Computation of FOLLOWS → x A yFOLLOW(S) = {$}                                                       (1)Applying Rules (2a) of FOLLOW.Comparing S → x a y with A → ... Read More

Show That Every SLR(1) Grammar is Unambiguous

Ginni
Updated on 02-Nov-2021 11:04:51

4K+ Views

SolutionStep1 − First of all, convert it into augmented grammar G′ and number the productions(0) S′ → S(1) S → L = R(2) S → R(3) L →∗ R(4) L → id(5) R → LStep2 − Find closure and goto function to construct LR (0) items.In the following set of LR (0) items, Boxes represents the new states and circle represents Repeating statesStep3− Computation of FOLLOW− Applying Rule (1) of FOLLOW, we getFOLLOW(S) = $                                                 (1)S ... Read More

Create Horizontal Line in XYplot in R

Nizamuddin Siddiqui
Updated on 02-Nov-2021 11:03:24

798 Views

To create horizontal line in xyplot, we can use abline function.For Example, if we have a data frame called df that contains two columns say X and Y and we want to create a scatterplot between X and Y using xyplot with a horizontal line at Y = 2 then we can use the command given below −xyplot(Y~X,df,abline=c(h=2))ExampleFollowing snippet creates a sample data frame −x

Difference Between SLR, CLR, and LALR Parser in Compiler Design

Ginni
Updated on 02-Nov-2021 11:00:27

64K+ Views

SLR ParserSLR represents "Simple LR Parser". It is very easy and cost-effective to execute. The SLR parsing action and goto function from the deterministic finite automata that recognizes viable prefixes. It will not make specificially defined parsing action tables for all grammars but does succeed on several grammars for programming languages. Given a grammar G. It augment G to make G’, and from G’ it can construct C, the canonical collection of a set of items for G’. It can construct ACTION the parsing action function, and GOTO, the goto function, from C using the following simple LR Parsing table ... Read More

Fill Entries in Parsing Table

Ginni
Updated on 02-Nov-2021 10:51:02

495 Views

A parser is the second phase of compilation. The parser takes as its input tokens generated from the previous phase, i.e., the Lexical Analyzer phase, and groups them in such a way that their syntax can be recognized.For example, Consider I0I0 − E′ → ∙ E      E → ∙ E + T     E → ∙ T     T → ∙ T ∗ F     T → ∙ F     F → ∙ (E)     F → ∙ idFilling of Shifting EntriesApplying Rule (2a) of the algorithm of construction of SLR Parsing Table on a set of a ... Read More

Find Column Name for Row Maximum in Data Table Object in R

Nizamuddin Siddiqui
Updated on 02-Nov-2021 10:49:43

467 Views

If we have a data.table object and we want to find the column name for row maximum then we can use max.col function.For Example, if we have a data.table object called DT then we can find the column name for row maximum by using the below command −DT[,names(.SD)[max.col(.SD,ties.method="first")]]Example 1Following snippet creates a sample data frame −x1

Construct SLR(1) Parsing Table for the Grammar

Ginni
Updated on 02-Nov-2021 10:49:31

1K+ Views

SolutionSteps to produce SLR Parsing TableGenerate Canonical set of LR (0) itemsCompute FOLLOW as required by Rule (2b) of Parsing Table Algorithm.Computation of FOLLOWBy Rule (1) of FOLLOWFOLLOW(E) = {$}                                                   (1)E → E + TApplying Rule (2) FOLLOWi.e., comparing E → E + T with A → α B βE →ΕE+ TA →ΑBΒ∴ A = E, α = ε, B = E, β = +T∵ Since FIRST(β) = FIRST(+T) = {+}which does not contain ε.∴ ... Read More

Advertisements