Programming Articles - Page 1144 of 3366

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

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:54:19

17K+ 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 − Live Demox

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

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:52:48

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 − Live Demox1

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

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:51:44

921 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 − Live Demox

How to find the proportion using normal distribution in R?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:50:26

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 − Live Demopnorm(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 − Live Demopnorm(60, mean=50, sd=8, lower.tail=FALSE)Output[1] ... Read More

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

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:49:08

218 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 − Live Demox

How to find the row and column index for upper triangular matrix elements in R?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:47:45

616 Views

To find the row and column index for upper triangular matrix elements in R, we can follow the below steps −First of all, create a matrix.Then, use which function with upper.tri function to find the row and column index for upper triangular matrix elements.After, that attach the values corresponding to each index using cbind function.Create the matrixLet’s create a matrix as shown below − Live DemoM

How to divide the row values by row mean in R matrix?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:45:53

316 Views

To divide matrix row values by row mean in R, we can follow the below steps −First of all, create a matrix.Then, use apply function to divide the matrix row values by row mean.Create the matrixLet’s create a matrix as shown below − Live DemoM

How to combine multiple R data frames stored in multiple lists based on a common column?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:44:45

498 Views

To combine multiple R data frames stored in multiple lists based on a common column, we can follow the below steps −First of all, create two lists of data frames.Then, use map2_df function from purrr package and inner_join function from dplyr package to combine the data frames stored in lists based on a common column.Create the two lists of data framesLet's create a data frames as shown below − Live Demodf1

How to create plotly bar chart with values on top of bars in R?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:42:02

1K+ Views

To create plotly bar chart with values on top of bars in R, we can follow the below steps −First of all, create two vectors one having categories and one counts and create the bar chart using plotly.Then, create the same bar chart with add_text function of plotly package.Create the vectors and plotly bar chartUsing c function to create the vectors and plotly function with layout function to create the bar chart with axes titles −x

How to find the sum of numbers stored in character vector separated with a special character in R?

Nizamuddin Siddiqui
Updated on 13-Aug-2021 10:38:59

454 Views

To find the sum of numbers stored in character vector separated with a special character in R, we can follow the below steps −First of all, create a vector having numbers stored in character vector separated with a special character.Then, use sapply and strsplit function to find the sum of numbers.Example1Create a vector with numbers stored in character vector separated with hyphen − Live Demo> x1 x1On executing, the above script generates the below output(this output will vary on your system due to randomization) − [1] "11-2-15-19-10"   "11-2-15-19-10"    "13-12-75-29-18"  "15-25-52-91-10"  [5] "15-25-52-91-10"  "17-27-55-91-100"  "13-12-75-29-18"  "15-25-52-91-10"  [9] "13-12-75-29-18"  "10-4-5-19-10"     ... Read More

Advertisements