Create Boxplot in Base R with Higher Width of Box Lines

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:38:19

244 Views

To create boxplot in base R with higher width of the box lines, we can use the boxlwd argument inside boxplot function. For example, if we have a vector called x then we can create the boxplot with higher width of the box lines using the command −boxplot(x,boxlwd=5)Example Live Demox

Find Fractional Power of a Negative Number in R

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:35:04

322 Views

To find the fractional power of a negative number, we can find the power separately for the numerator and denominator where denominator will have the numerator 1. For example, if we have a vector called x that contains a single value -10 then the fractional power 15/7 of x can be found by using the command ((x)^15)^(1/7)Example Live Demox1

Sum of Every N Values in R Data Frame Considering Missing Values

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:32:42

746 Views

To find the sum of every n values in R data frame columns if there exist missing values, we can use rowsum function along with rep function that will repeat the sum for rows and na.rm=TRUE to exclude the rows with missing values. For example, if we have a data frame called df that contains 4 columns each containing twenty values with some missing values then we can find the row sums for every 5 rows by using the command rowsum(df,rep(1:5,each=4),na.rm=TRUE).Example Live Demox1

Draw a Line on an Image Using OpenCV

Prasad Naik
Updated on 17-Mar-2021 07:29:18

1K+ Views

In this program, we will draw a simple line on an image using the OpenCV function line().Original ImageAlgorithmStep 1: Import cv2. Step 2: Read the image using imread(). Step 3: Get the dimensions of the image using the image.shape method. Step 4: Define starting point of the line. Step 5: Define the end point of the line. Step 6: Define the thickness of the line. Step 7: Draw the line using the cv2.line() function and pass Step 3 to Step 4 as parameters.Example Codeimport cv2 image = cv2.imread('testimage.jpg') height, width, channels = image.shape startpoint = (0, 0) endpoint = ... Read More

Check R Matrix Column for Duplicate Values

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:25:41

223 Views

To check if an R matrix column contains only duplicate values, we can use dim function for the dimension of the column after accessing the matrix column with table function. For example, if we have a matrix called M having five columns then we can check whether first column contains only duplicate values using the command dim(table(M[,1]))==1ExampleConsider the below data frame − Live DemoM1

Find Number of Levels in R for a Factor Column

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:21:09

960 Views

To find the number of levels in R for a factor column, we can use length function along with unique function. For example, if we have a data frame called df that contains a factor column X then we can find the number of levels in the factor column using the command −length(unique(df$X))ExampleConsider the below data frame − Live Demox1

Replace Space with Underscore in R Data Frame Column

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:17:38

3K+ Views

To replace space between two words with underscore in an R data frame column, we can use gsub function. For example, if we have a data frame called df that contains character column x having two words having a single space between them then we can replace that space using the command df$x

Find Standard Deviation for Rows in an R Data Frame

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:11:49

942 Views

To find the standard deviation for rows in an R data frame, we can use mutate function of dplyr package and rowSds function of matrixStats package. For example, if we have a data frame called df that contains two columns x and y then we can find the standard deviation for rows using the below command −df%>%mutate(STDEV=rowSds(as.matrix(.[c("x","y")])))ExampleConsider the below data frame − Live Demox1

Find Correlation Between Columns of Two Matrices in R

Nizamuddin Siddiqui
Updated on 17-Mar-2021 07:05:10

869 Views

To find the correlation between corresponding columns of two matrices, we can use mapply function but we will have to read the matrices using as.data.frame function. For example, if we have two matrices called M_1 and M_2 and each of these matrices contains 5 columns then the correlation between corresponding columns of these matrices can be found by using the command mapply(cor,as.data.frame(M_1),as.data.frame(M_2))ExampleConsider the below matrices − Live DemoM1

Delete Matrix Rows Based on Column Value Condition in R

Nizamuddin Siddiqui
Updated on 17-Mar-2021 06:58:30

917 Views

To delete matrix rows if a particular column satisfies some condition, we can use subsetting with single square brackets and take the subset of the matrix based on the condition. For example, if we have a matrix M and want to delete rows if column first of M do not contain value 5 then we can use the command M[M[,1]==5,].ExampleConsider the below matrix − Live DemoM1

Advertisements