Break and Continue in Foreach Loop in Kotlin

Soumak De
Updated on 23-Nov-2021 06:48:01

5K+ Views

In Kotlin, we have three types of structural jump expressions: "break", "return", and "continue". In this article, we will see how break and continue work in Kotliln.Break - This is a keyword that helps in terminating an iteration, once a given condition is met, while traversing through a collection.Continue - This keyword helps to continue the iteration once a condition is fulfilled.In Kotlin, we cannot explicitly use break and continue statements explicitly inside a forEach loop, but we can simulate the same action. In this example, we will see how to do it.Example: Return at labels :: directly to the ... Read More

Find Row-wise Sum for N Columns in R

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:36:30

3K+ Views

To find the row wise sum of n number of columns can be found by using the rowSums function along with subsetting of the columns with single square brackets.For example, if we have a data frame called df that contains five columns and we want to find the row sums for last three columns then we can use the following command −df$Sum_3

Extract Maximum Value from Named Vector in R

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:31:08

1K+ Views

To extract the maximum value from named vector in R, we can use which.max function.For example, if we have a vector called X which is a named vector then we can use the following command to find the maximum value in X.X[which.max(X)]Check out the below examples to understand how it works.Example 1Following snippet creates a vector −x1

Swift If-Let Statement Equivalent in Kotlin

Soumak De
Updated on 23-Nov-2021 06:28:11

2K+ Views

Swift "if let" is a conditional check operator to check whether a reference variable is NULL or not. This is a very useful technique to evaluate the unwrap optional value using swift language.In Kotlin, we can't use this operator directly. Instead, we will be using "let" and "run" to evaluate the same. In the following example, we will see how to use "let" and "run" using Kotlin library class.Example: Null Check using 'let' and 'run'In this example, we will check whether the value of a reference variable is NULL or not. If the value of the reference variable is NULL, ... Read More

Reduce Space Between Y-Axis Values and Ticks Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:21:07

5K+ Views

To reduce the space between axis value and ticks using ggplot2, we can use theme function of ggplot2 package with margin set to 0.For example, if we have a data frame called df that contains two columns say x and y then the scatterplot between x and y with reduced space between Y-axis value and ticks can be created by using the following command −ggplot(df,aes(x,y))+geom_point()+theme(axis.text.y=element_text(margin=margin(r=0)))ExampleFollowing snippet creates a sample data frame −x

Implement Builder Pattern in Kotlin

Soumak De
Updated on 23-Nov-2021 06:17:19

875 Views

In object-oriented programming, the creation of objects is very easy via constructors when the object definitions are simple, but sometimes, it may so happen that the constructors need more variables or functions in order to initialize an object. In such cases, the "builder pattern" comes into picture which helps programmers to create small units of different objects and create a final object.A builder pattern provides an API to construct an object step- by-step.Builder patterns are particularly useful when objects need to be created dynamically.Note that it is not recommended to use builder patterns in Kotlin because we can get the ... Read More

Display Fraction in Base R Plot

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:15:23

1K+ Views

To display fraction in base R plot, we can use frac function in text function.For example, if we create a plot of vectors called X and Y with display of over form fraction as X over Y at X=2 and Y= 2 then we can use the following code −text(2, 2, expression(Output==frac(X, Y)))Check out the below examples to understand how it works.Example 1To display fraction in base R plot, use the code given below −plot(1:5, type="n") text(2, 4, expression(Output==frac(x, y)))OutputIf you execute the above given code, it generates the following output −Example 2To display fraction in base R plot, use ... Read More

Convert Kotlin Source File to Java Source File

Soumak De
Updated on 23-Nov-2021 06:13:27

822 Views

Kotlin is a statistically typed language that runs on JVM. Once a Kotlin file is compiled, it creates a .class file that can be executed on the JVM. In this article, we will see how we can convert a Kotlin source file to a Java source file. In this process, we will be taking help from different online Decompilers available on the Internet.Open VS Code.Go to the "extension" section and install "Kotlin language support for VS Code" and "Code Runner". We need these two extensions to run Kotlin in VS code environment.Install Kotlin compiler in your system as per the ... Read More

Display Fraction in Plot Title Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:11:56

1K+ Views

To display fraction in a plot title using ggplot2 in R, we can use frac function inside ggtitle function of ggplot2 package. Generally, fraction is displayed as X/Y but frac function helps to create the fraction in over form.Check out the below example to understand how over form of fraction can be displayed in a plot title using ggplot2.ExampleFollowing snippet creates a sample data frame −x

Find Sequence of Correlation Between Variables in R Data Frame or Matrix

Nizamuddin Siddiqui
Updated on 23-Nov-2021 05:51:00

313 Views

To find the sequence of correlation between variables in an R data frame or matrix, we can use correlate and stretch function from corrr package.For example, if we have a data frame called df then we can find the sequence of correlation between variables in df by using the below given command −df%>% correlate() %>% stretch() %>% arrange(r)Example 1Following snippet creates a sample data frame −x1% + arrange(r) Correlation method: 'pearson' Missing treated using: 'pairwise.complete.obs' # A tibble: 25 x 3OutputIf you execute all the above given snippets as a single program, it generates the following output −  ... Read More

Advertisements