Find Maximum Value in an R Data Frame

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:31:57

2K+ Views

The maximum value is a part of summary statistics and we always need to understand the end limits of our data; therefore, it is highly required. If we have a data frame that contains numerical columns then the maximum value can be found by using max function and the data frame object name.Example1 Live DemoConsider the below data frame −set.seed(357) x1

Remove Column Names from an R Data Frame

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:26:14

12K+ Views

There are situations when we might want to remove column names such as we want to manually replace the existing column names by new names or we simply don’t want to use them if we are very much familiar with the column characteristics. To remove the columns names we can simply set them to NULL as shown in the below examples.Example1Consider the below data frame − Live Demoset.seed(357) x1

Find Position of NA in an R Vector

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:20:00

2K+ Views

When we have NA’s/missing values in an R vector then we want to replace those NA’s and for this purpose we might be needing the position of those values. These positions will be helpful especially in situations when we want to manually replace the missing values. The replacement can be done by using which function with is.na.Example1 Live Demox1

Check If a Matrix Is Invertible in R

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:15:19

1K+ Views

If the matrix is singular then it is not invertible and if it is non−singular then it is invertible. Therefore, we can check if a matrix is singular or not. We can use is.singular.matrix function of matrixcalc for this purpose. For example, if we have a matrix called M then to check whether it is invertible or not, we can use is.singular.matrix(M).Example1Loading matrixcalc package and creating a matrix −library(matrixcalc) M1

Majority Element in Python

Dev Prakash Sharma
Updated on 05-Feb-2021 08:10:17

3K+ Views

Let’s suppose we have an array of integers. The task is to find the index of a particular element in the given array. For example, Input-1 −N = 8 A[ ] = { 1, 2, 4, 3, 3, 1, 1, 5}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus the output is ‘1’.Input-2 −N = 6 A[ ] = {1, 5, 4, 4, 1, 1}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus we can return the output ‘1’.Approach to solve this problemThe given array contains ... Read More

Remove Repeated Column Names in Data Table Object in R

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:00:04

502 Views

In data analysis, we sometimes deal with duplicated data or just the representation of the data with same name. One such situation is column names are same for two columns in a data.table object. For this purpose, we can make use of which function with the combination of duplicated function and set the output of that duplicate to NULL to remove the repeated column names.Example1Loading data.table package and creating a data.table object −library(data.table) x1

Counting Elements in Two Arrays Using C++

Dev Prakash Sharma
Updated on 05-Feb-2021 07:16:38

741 Views

Let us assume that we have given two unsorted arrays arr1[] and arr2[]. The task is to count the total number of elements in arr2[] for which each element of arr1[] are less than or equal to the elements present in arr2[]. However, the element in both the array may contain duplicates too.For example, Input-1 −N = 6 M = 7 arr1[N] = {1, 2, 5, 0, 6, 3} arr2[M] = {0, 0, 1, 2, 1, 3, 4, 6, 8}Output −4 5 7 2 8 6The approach used to solve this problemTo count every element of arr1[] and check if ... Read More

Maximum Erasure Value in C++

Kiran P
Updated on 04-Feb-2021 12:01:30

269 Views

Given an array of positive integers, the task is to erase a subarray containing all the unique elements. What you get by erasing the subarray is equal to the sum of its elements.Return the maximum sum of the current subarray by erasing the terms before or after it, we can get the maximum sum by erasing exactly one subarray.An array arr is called to be a subarray of a if it forms a contiguous subsequence of a that is if it is equal to a[l], a[l+1], ..., a[r] for some (l, r). For example, Input-1 −arr[ ] = { 1, 2, ... Read More

Find Odd and Even Numbers Using Bit Operation in Go

Kiran P
Updated on 04-Feb-2021 11:31:15

545 Views

ExamplesInput num = 5 => 101 & 1 = 001 => True, i.e., Odd; else num would be Even.Approach to solve this problemStep 1: Define a method that accepts a number.Step 2: Perform & operation with that number.Step 3: If the & operator returns a non-zero value, then that number would be odd.Step 4: Else, the number would be even.ProgramLive Demopackage main import "fmt" func oddEven(num int){    if num & 1 != 0 {       fmt.Println("ODD")    } else {       fmt.Println("EVEN")    } } func main(){    oddEven(13)    oddEven(50)    oddEven(0) }OutputODD EVEN EVEN

Sort a Binary Array in Linear Time using Go

Kiran P
Updated on 04-Feb-2021 11:30:28

338 Views

There are two methods in which we can solve this problem. Let’s check the first method.Method 1ExamplesInput Array = [1, 0, 1, 0, 1, 0, 0, 1] => [0, 0, 0, 0, 1, 1, 1, 1]Approach to solve this problemStep 1: Define a method that accepts an array.Step 2: Count number of 0.Step 3: Store 0 till count becomes 0 and store 1 at the remaining indexes.Step 4: At the end, return the array.ProgramLive Demopackage main import "fmt" func binarySort(arr []int) []int{    count := 0    for i:=0; i

Advertisements