Server Side Programming Articles

Page 1232 of 2109

How to find the rank of a vector elements in R from largest to smallest?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

To find the rank of a vector of elements we can use rank function directly but this will result in ranks from smallest to largest. For example, if we have a vector x that contains values 1, 2, 3 in this sequence then the rank function will return 1 2 3. But if we want to get ranks from largest to smallest then it would be 3 2 1 and it can be done in R as rank(-x).Examplex1

Read More

How to check whether a string is in lowercase or uppercase in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

We can use str_detect function to check whether a single string or a vector of strings is in lowercase or uppercase. Along with str_detect function, we need to use either upper or lower to check whether the string is in lowercase or uppercase and the output will be returned in TRUE or FALSE form, if the string will be in lowercase and we pass lower with str_detect function then the output will be TRUE and vice-versa.Examplex1

Read More

How to remove the row names or column names from a matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 24K+ Views

To remove the row names or column names from a matrix, we just need to set them to NULL, in this way all the names will be nullified. For example, if we have a matrix M that contain row names and column names then we can remove those names by using the command colnames(M)

Read More

How to create unordered triplets of a vector elements in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 312 Views

To create triplets of a vector elements, we can use combn function. For example, if we have a vector x that contain values 1, 2, 3, 4, 5 then the unordered triplets of x can be created by using combn(x,3). This will create a matrix where the elements of the vector x would not be arranged in a particular order.Examplex1

Read More

How to create a list of matrices in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

To create a list of matrices, we simply need to find the matrix object inside list function. For example, if we have five matrix objects either of same or different dimensions defined as Matrix1, Matrix2, Matrix3, Matrix4, and Matrix5 then the list of these matrices can be created as −List_of_Matrix

Read More

How to find the maximum value for each column of a matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 5K+ Views

To find the maximum value for each column of a matrix, we need to use apply function. For example, if we have a matrix M that contains 2 rows and 2 columns with values 1, 2 in the first row and 3, 4 in the second row then the maximum for each of the columns in that matrix can be found by using the syntax; apply(M,2,max), hence the result will be 3, 4.ExampleM1−-matrix(1:36,ncol=6) M1Output   [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1    7    13   19   25   31 [2,] 2    8    14   20   26   32 [3,] 3    9    15   21   27   33 [4,] 4    10   16   22   28   34 [5,] 5    11   17   23   29   35 [6,] 6    12   18   24   30   36Exampleapply(M1,2,max)Output[1] 6 12 18 24 30 36ExampleM2

Read More

How to create a sequence of time in minutes with date in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To create a sequence of time in minutes with date we can use seq function and define the date and time with as.POSIXct. For example, if we want to generate a sequence of time between 2 pm on tenth October 2020 to 4 pm on the same date then we can use the following code −seq(from=as.POSIXct("2020-10-10 14:00"), to=as.POSIXct("2020-10-10 16:00"), by="min")Exampleseq(from=as.POSIXct("2020-01-01 00:01"), to=as.POSIXct("2020-01-01 01:00"), by="min")Output[1] "2020-01-01 00:01:00 IST" "2020-01-01 00:02:00 IST" [3] "2020-01-01 00:03:00 IST" "2020-01-01 00:04:00 IST" [5] "2020-01-01 00:05:00 IST" "2020-01-01 00:06:00 IST" [7] "2020-01-01 00:07:00 IST" "2020-01-01 00:08:00 IST" [9] "2020-01-01 00:09:00 IST" "2020-01-01 00:10:00 IST" [11] "2020-01-01 ...

Read More

How to generate random samples rounded to 4 decimal places in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

Random samples can be generated in many ways such as using discrete and continuous distributions, using integer vectors, using numerical vectors, using character vectors and/or factor vectors, also with columns of a data set. If we have the sample that is continuous in nature then the values are likely to contain many values after decimal point and we can limit those values to 4 or use any other limit using round function.Examplex1

Read More

How to combine array of vectors in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 876 Views

To combine array of vectors we can use rbind function. For example, if we have multiple vectors say x, y, z of same size or different sizes but the total number of elements are even then we can use rbind(x,y,z) to combine those vectors. Check out the examples to understand how it works.Example1x1

Read More

How to replicate a vector to create matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

The matrix can be created by using matrix function in R and if we want to create a matrix by replicating a vector then we just need to focus on the replication. For example, if we have a vector V and we want to create matrix by replicating V two times then the matrix can be created as matrix(replicate(2,V),nrow=2).Example1V1

Read More
Showing 12311–12320 of 21,090 articles
Advertisements