To create a number vector in R with initial values as zero by defining the maximum digits for each value, we can use sprintf function.For Example, if we want to create a number vector having values starting from 1 to 100 and we want to have 1 as 001 and so on then, we can use the below command −sprintf('%0.3d',1:100)ExampleFollowing snippet creates a sample data frame −x1
The default boxplot in R has straight lines that display end point(s) excluding outliers. To remove these end lines from a boxplot, we can use staplelty argument and set it to 0.For Example, if we have a vector called X then we can create the boxplot of X by using the command given below −boxplot(X,staplelty=0)ExampleFollowing snippet creates a sample data frame −x
To check if a data frame has any missing value in R, we can use any function along with is.na function. For Example, if we have a data frame called df then we can use the below command to check whether df contains any missing value or notany(is.na(df))Example 1Following snippet creates a sample data frame −x1
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 a vector in R can be easily done with the help of duplicated function with negation operator as shown in the Examples given below.Example 1Following snippet creates a sample data frame −x1
A pie chart is a circular representation of data which is created for either nominal data or ordinal data. The slices in the pie chart depend on the magnitude of the data values. If we want to create a pie chart in base R then pie function can be used.For Example, if we have a vector called X then the pie chart for values in X can be created by using the below command −pie(X)ExampleFollowing snippet creates a sample data frame −x
In this article, we will see how we can convert a List to a Map using various options provided by the Kotlin Library.Example: Using associate()The most standard way of converting a list into a map is by using the associate() function. This function takes a list of items as an argument and it returns a map containing key-value pairs. In the following example, we will see how it works.Exampledata class mySubjectList(var name: String, var priority: String) fun main() { val mySubjectList: List = listOf( mySubjectList("Java", "1"), mySubjectList("Kotlin", "2"), mySubjectList("C", ... Read More
To find the row products for each row in an R data frame, we can use rowProds function of matrixStats package but we need to read the data frame as a matrix.For Example, if we have a data frame called df then we can find the row products for each row in df by using the command given below −rowProds(as.matrix(df))Example 1Following snippet creates a sample data frame −x1
Kotlin is based on Java, hence we can use Java-based library functions to delay a function call. In this article, we will be using a Java library function to delay the function call using Timer() and schedule().Exampleimport java.util.Timer import kotlin.concurrent.schedule fun main(args: Array) { // Execution starting point println("Hello world!!") // Delay of 5 sec Timer().schedule(5000){ //calling a function newMethod() } } fun newMethod(){ println("Delayed method call!") }OutputOnce executed, the above piece of code will yield the following output −Hello world!! Delayed method call!
String is a collection which is implemented using String class. As per the Kotlin documentation, a string can be defined as follows −Class String : Comparable, CharSequenceIn Kotlin, a string is a collection of characters. Strings are immutable in nature which means they are read-only. The length and elements of a string can be modified once declared.In Java, we have an option to create an empty String array by defining it like String[]. In this article, we will see how we can achieve the same using Kotlin library function.Example: Using arrayOf()Kotlin library provides a function to create an array of ... Read More
Kotlin provides multiple ways to generate a random number. In this article, we will see different ways to generate a random number and access it throughout the program.Example – Using Random classRandom() is an abstract class which generates random numbers with the given conditions. It can be accessed after importing Kotlin.random.Random.As per the Kotlin documentation, the companion object Random.Default is the default instance of Random class. In the following example, we will generate a list of random values with int (1-30) .Exampleimport kotlin.random.Random fun main() { val myRandomValues = List(5) { Random.nextInt(0, 30) } // Prints ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP