A boxplot in base R already consists three horizontal lines that represents minimum, median, and the maximum but we might to create an extra horizontal to showcase some threshold value. For example, we might to create a horizontal line at 2 to understand the variation in values that are greater than say 2. This can be done very easily by using abline function after creating the boxplot.Example1Live Demo> x boxplot(x) > abline(h=1)Output:Example2Live Demo> y boxplot(y) > abline(h=15)Output:Example3Live Demo> z boxplot(z) > abline(h=3)Output:
How to create normal quantile-quantile plot for a logarithmic model in R?A logarithmic model is the type of model in which we take the log of the dependent variable and then create the linear model in R. If we want to create the normal quantile-quantile plot for a logarithmic model then plot function can be used with the model object name and which = 2 argument must be introduced to get the desired plot.Example1Live Demo> x1 x1Output[1] 4.735737 3.631521 5.522580 5.538314 5.580952 4.341072 4.736899 2.455681 [9] 4.042295 5.534034 4.717607 6.146558 4.466849 5.444437 5.390151 4.491595 [17] 4.227620 4.223362 5.452378 5.690660 5.321716 ... Read More
Sometimes we get unnecessary information in our data set that needs to be removed, this information could be a single case, multiple cases, whole variable or any other thing that is not helpful in achieving our analytical objective, hence we want to remove it. If we want to remove such type of rows from an R data frame with the help of dplyr package then anti_join function can be used.ExampleConsider the below data frame:Live Demo> set.seed(2514) > x1 x2 df1 df1Output x1 x2 1 5.567262 4.998607 2 5.343063 4.931962 3 2.211267 ... Read More
To generate passwords, we can use stri_rand_strings function of stringi package. If we want to have passwords of varying length then we need to create the passwords using the particular size separately. For example, for a size or length of the password equals to 8, we can use the argument length in the stri_rand_strings function.Loading stringi package:> library(stringi)Example1> stri_rand_strings(n=5, length=8, pattern="[0-9a-zA-Z]") [1] "YkIEDYQz" "t42JCzYO" "rOE9YN8U" "2lu9AonY" "6lDUxScX"Example2> stri_rand_strings(n=20, length=8, pattern="[0-9a-zA-Z]") [1] "glH3ysoX" "X0Sgvg3F" "P3YOePTa" "45GOb2hA" "tLCwszus" "CerCi1ks" [7] "UtFwzrSc" "pG8AJCQX" "NTCdMRHj" "5thI1wKb" "Ic8Rol1Y" "JakWa1Wd" [13] "9AfeXo7T" "SFJVn9XV" "lIRhLbJ9" "DNFyAbkJ" "jV4jJRZk" "IthkzfEU" [19] "talj9nBq" "Nak9Tidh"Example3> ... Read More
This example demonstrates how to create EditText accepts Alphabets only in Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.kt
This example demonstrates how to generate random numbers in a given range in Android using KotlinStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Button import android.widget.EditText import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() { lateinit var editTextMin: EditText lateinit var editTextMax: EditText lateinit var button: Button ... Read More
This example demonstrates how to add a TextView to a LinearLayout dynamically in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.graphics.Color import android.os.Bundle import android.widget.LinearLayout import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinAp" val linearLayout: LinearLayout = ... Read More
This example demonstrates how toStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Build import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.TextView class MainActivity : AppCompatActivity() { private lateinit var textView: TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" textView = findViewById(R.id.textView) val ... Read More
This example demonstrates how to send a SMS using SMSmanager in Dual SIM mobile in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.Manifest import android.content.pm.PackageManager import android.os.Bundle import android.telephony.SmsManager import android.text.TextUtils import android.view.View import android.widget.Button import android.widget.EditText import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat class MainActivity : AppCompatActivity() { lateinit var button: Button ... Read More
This example demonstrates how to implement an endless list with RecyclerView in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.os.Handler import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView class MainActivity : AppCompatActivity() { lateinit var recyclerView: RecyclerView lateinit var recyclerViewAdapter: RecyclerViewAdapter var rowsArrayList: ArrayList = ArrayList() var isLoading = false override fun onCreate(savedInstanceState: Bundle?) ... Read More