R Programming Articles

Page 17 of 174

How to find the frequency of continuously repeated string values in an R data frame column?

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

To find the frequency of continuously repeated string values in an R data frame column, we can follow the below steps −First of all, create a data frame with a string column.Then, use sequence function and rleid function after converting the data frame into data.table object to find the frequency of continuously repeated string values in data frame column.Create the data frameLet's create a data frame as shown below −x

Read More

How to check if a character column only contains alphabets in R data frame?

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

To check if a character column only contains alphabets in R data frame, we can follow the below steps −First of all, create a data frame with a character column.Then, use grepl function to check if all the values in the column contains only alphabets.Example 1Let's create a data frame as shown below −x

Read More

How to find the proportion using normal distribution in R?

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

To find the proportion using normal distribution in R, we can use pnorm function where we can provide the mean and standard deviation of population along with sample, also the tail position can be set by using lower.tail argument to TRUE or FALSE. Check out the below examples to understand how it can be done.Example 1Finding the proportion of values above 55 when sample mean is 50 and standard deviation is 8 −pnorm(55, mean=50, sd=8, lower.tail=FALSE)Output[1] 0.2659855Example 2Finding the proportion of values above 60 when sample mean is 50 and standard deviation is 8 −pnorm(60, mean=50, sd=8, lower.tail=FALSE)Output[1] 0.1056498Example 3Finding ...

Read More

How to create a subset of an R data frame based on multiple columns?

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

To create a subset of an R data frame based on multiple columns, we can follow the below steps −First of all, create a data frame.Then, use single square brackets to subset the data frame based on multiple columns.Create the data frameLet's create a data frame as shown below −x1

Read More

How to extract the p-value from t test in R?

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

To extract the p-value from t test in R, we can follow the below steps −First of all, create a data frame with numerical column or a numerical vector.Then, use t.test function to perform the test and put $p.value at the end to extract the p-value from the test output.Example1Create the data frameLet's create a data frame as shown below −x

Read More

How to add regression residuals to data frame in R?

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

To add regression residuals to data frame in R, we can follow the below steps −First of all, create a data frame.Then, use lm function to create the regression model and find the residuals using resid function and adding them to the data frame with $ operator.Create the data frameLet's create a data frame as shown below −x

Read More

How to truncate character vector with three dots after n characters in R?

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

To truncate character vector with three dots after n characters can be done with the help of str_trunc function of stringr package. For example, if we have a character vector say x and each value containing 10 characters then truncating those values with three dots after 5 characters can be done by using the command str_trunc(x, 8).Example1> x1 x1Output[1] "rstuvwxyz" "rstuvwxyz" "abcbefgh" "rstuvwxyz" "ijklmnopq" "ijklmnopq" [7] "ijklmnopq" "rstuvwxyz" "rstuvwxyz" "rstuvwxyz" "rstuvwxyz" "abcbefgh" [13] "rstuvwxyz" "abcbefgh" "abcbefgh" "ijklmnopq" "ijklmnopq" "ijklmnopq" [19] "ijklmnopq" "rstuvwxyz" "rstuvwxyz" "abcbefgh" "abcbefgh" "ijklmnopq" [25] "ijklmnopq" "ijklmnopq" "rstuvwxyz" "rstuvwxyz" "rstuvwxyz" "rstuvwxyz" [31] "rstuvwxyz" "abcbefgh" "abcbefgh" "rstuvwxyz" "rstuvwxyz" "abcbefgh" ...

Read More

How to get the colour name from colour code in R?

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

To get the color name from color code, we can use the color_id function of plotrix package. If we have a vector of colour codes say x then the colour name can be found by using the command sapply(x, color.id).Example> x xOutput[1] "#FF0000" "#FF1F00" "#FF3D00" "#FF5C00" "#FF7A00" "#FF9900" "#FFB800" [8] "#FFD600" "#FFF500" "#EBFF00" "#CCFF00" "#ADFF00" "#8FFF00" "#70FF00" [15] "#52FF00" "#33FF00" "#14FF00" "#00FF0A" "#00FF29" "#00FF47" "#00FF66" [22] "#00FF85" "#00FFA3" "#00FFC2" "#00FFE0" "#00FFFF" "#00E0FF" "#00C2FF" [29] "#00A3FF" "#0085FF" "#0066FF" "#0047FF" "#0029FF" "#000AFF" "#1400FF" [36] "#3300FF" "#5200FF" "#7000FF" "#8F00FF" "#AD00FF" "#CC00FF" "#EB00FF" [43] "#FF00F5" "#FF00D6" "#FF00B8" "#FF0099" "#FF007A" "#FF005C" "#FF003D" [50] "#FF001F"Loading plotrix ...

Read More

How to sort a vector in R based on manual position of elements?

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

To sort a vector based on manual position of elements, we can use order function along with the factor function. The factor function will help us to arrange the vector elements in the order we want by defining the levels as vector elements and order function will order them. Check out the below examples to understand how it works.Example1> x1 x1Output[1] 0 1 0 0 1 2 1 2 3 1 2 2 2 4 3 1 4 1 0 1 1 3 3 0 0 4 4 2 4 2 4 2 0 4 0 1 1 [38] 4 ...

Read More

How to format all decimal places in an R vector and data frame?

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

To format all decimal places in an R vector and data frame, we can use formattable function of formattable package where we can specify the number of digits after decimal places. For example, if we have a numerical vector say x then the values in x can be formatted to have only 2 decimal places by using the command formattable(x,format="f",digits=2).Example1Loading formattable package −library(formattable)x1

Read More
Showing 161–170 of 1,740 articles
« Prev 1 15 16 17 18 19 174 Next »
Advertisements