To find the frequency of exclusive group combinations in an R data frame, we can use count function of dplyr package along with ungroup function.For Example, if we have a data frame called df that contains four grouping columns say Grp1, Grp2, Grp3, and Grp4 then we can count the unique group combinations in df by using the below command −count(df,Grp1,Grp2,Grp3,Grp4)%%ungroup()Example 1Following snippet creates a sample data frame −Class1
To display superscript for X-axis title in base R plot, we can use ^ sign inside mtext function before defining the plain text.For example, if we want to display X2 at position 5 on X-axis then it can be done by using the below command −mtext(expression(paste(plain("X")^plain("2"))), side=1, line=2, at=5, cex=1.2)ExampleConsider the following snippet −plot(1:10) OutputIf you execute the above given snippet, it generates the following Output −To display superscript for X-axis title in base R plot, add the following code to the above snippet −Exampleplot(1:10, xlab="")OutputIf you execute all the above given snippets as a single program, it generates the ... Read More
We are given an integer array containing odd and even integer values. The task is to rearrange an array in such a manner that arr[i] should be greater than or equals to arr[j] based on the condition that value at index arr[i] should be even and if value at arr[i] is odd then arr[i] should be less than equals to arr[j].Let us see various input output scenarios for this −Input − int arr[] = {5, 9, 10, 12, 32, 35, 67, 89}Output − Array after rearranging elements are: 12 32 10 35 9 67 5 89Explanation − we are given an array with ... Read More
To change the order of independent variables in regression Output, we can pass the variables in the sequence we want while creating the regression model.For example, if we want to have three independent variables and we want to display first at the last position then it can be done as follows −lm(DP1~ ind_var_3+ ind_var_2+ind_var_1,data=”data_frame_name”)ExampleFollowing snippet creates a sample dataframe −iv1
The LR (0) item for Grammar G consists of a production in which symbol dot (.) is inserted at some position in R.H.S of production.For Example − For the production S → ABC, the generated LR (0) items will be −S →∙ ABCS → A ∙ BCS → AB ∙ CS → ABC ∙Production S → ε generates only one item, i.e., S →∙Canonical LR (0) collection helps to construct LR parser called Simple LR (SLR) parser.To create Canonical LR (0) collection for Grammar, 3 things are required −Augmented GrammarClosure Functiongoto FunctionAugmented Grammar − If grammar G has start symbol ... Read More
LR Parser is a class of Bottom-Up Parser that is used to parse Context-Free Grammars. LR Parsing is known as LR (K) parsing whereL represents Left to Right Scanning of InputR represents Rightmost DerivationK is the number of input symbols of Look ahead that are used in developing parsing decisions.LR parser is a shift-reduce parser that creates the use of deterministic finite automata, identifying the collection of all applicable prefixes by reading the stack from bottom to top.It decides what handle, if any, is feasible. An achievable prefix of a right sentential form is that prefix that includes a handle, ... Read More
Top-Down Parsing with BacktrackingIn Top-Down Parsing with Backtracking, Parser will attempt multiple rules or production to discover the match for input string by backtracking at every step of derivation. So, if the used production does not give the input string as needed, or it does not match with the needed string, then it can undo that shift.Top-Down Parsing without BacktrackingAs backtracking looks more powerful by which we can select different alternatives. But backtracking cannot be applied or implemented so easily in parsing. There are two types of Top-Down Parsing without Backtracking, which are as follows −Recursive Descent ParserPredictive ParserRecursive Descent ... Read More
SolutionComputation of FIRSTE →TE′Applying Rule (4b) of FIRSTSince FIRST (T) does not contain ε, or T does not derive ε.∴ FIRST (E) = FIRST(TE′) = FIRST(T)∴ FIRST (E) = {FIRST(T)} (1)E → +TE′|εApplying Rule (3) of FIRSTComparing E′ → +TE′with X → aα∴ FIRST(E′) = {+}Apply Rule (2) on E′ → εFIRST (E′) = {ε}∴ FIRST(E′) = {+, ε} (2)T→FT′Apply rule (4b) of FIRSTSince, FIRST(F) does not derive ε∴ FIRST(T) = FIRST(FT′) = FIRST(F)∴ FIRST(T) = {FIRST(F)} (3)T′→*FT′|εComparing with rule (2) & (3) of FIRST, we get∴ FIRST(T′) = {ε, ∗} (4)F→(E)|idComparing with rule (3) of FIRST∴ FIRST(F) = {(, ... Read More
SolutionComputation of FIRSTA → b B∴ FIRST(A) = {b}B → ε∴ FIRST(B) = {ε}S → A a AApplying Rule (4) of FIRSTi.e., Comparing S → A a A with X → Y1Y2Y3∴ FIRST (S) = FIRST (A a A) = FIRST (A) = {b}∴ FIRST(S) = {b}S → B b B∵ FIRST (B)contains ε or B derives ε ∴ Applying Rule (4c)∴ FIRST (S) = FIRST (B to B)∴ FIRST (S) = FIRST (B) − {ε} ∪ FIRST(bB)∴ FIRST (S) = FIRST (B) − {ε} ∪ {b} = {ε} − {ε} ∪ {b} = {b}∴ FIRST (A) = {b}FIRST (B) ... Read More
FIRST and FOLLOW are two functions associated with grammar that help us fill in the entries of an M-table.FIRST ()− It is a function that gives the set of terminals that begin the strings derived from the production rule.A symbol c is in FIRST (α) if and only if α ⇒ cβ for some sequence β of grammar symbols.A terminal symbol a is in FOLLOW (N) if and only if there is a derivation from the start symbol S of the grammar such that S ⇒ αNαβ, where α and β are a (possible empty) sequence of grammar symbols. In ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP