![]() ![]() Note that quantile(VAR) command can also be used. > #what are the 25th and 75th percentiles for age in the sample?.> #calculate desired percentile values using quantile(VAR, c(PROB1, PROB2,…)).The following example shows how this function can be used to find the data value that corresponds to a desired percentile. The probabilities must be between 0 and 1, therefore making them equivalent to decimal versions of the desired percentiles (i.e. Here, VAR refers to the variable name and PROB1, PROB2, etc., relate to probability values. Given a dataset and a desired percentile, a corresponding value can be found using the quantile(VAR, c(PROB1, PROB2,…)) command. Percentiles Values from Percentiles (Quantiles) > #what range of age values are found in the sample?.> #calculate the range of a variable with range(VAR).This operation is demonstrated in the following code sample. Consequently, it is recommended that ranges also be computed on individual variables. As with the min and max functions, using range(DATAVAR) is not very useful, since it considers the entire dataset, rather than each individual variable. The range of a particular variable, that is, its maximum and minimum, can be retrieved using the range(VAR) command. > #what is the maximum age found in the sample?.> #calculate the max of a variable with max(VAR).> #what is the minimum age found in the sample?.> #calculate the min of a variable with min(VAR).The sample code below demonstrates the use of the min and max functions. Therefore, it is recommended that minimums and maximums be calculated on individual variables, rather than entire datasets, in order to produce more useful information. However, in contrast to the mean and standard deviation functions, min(DATAVAR) or max(DATAVAR) will retrieve the minimum or maximum value from the entire dataset, not from each individual variable. The maximum, via max(VAR), operates identically. Keeping with the pattern, a minimum can be computed on a single variable using the min(VAR) command. > #what is the standard deviation of each variable in the dataset?.> #calculate the standard deviation of all variables in a dataset with sd(DATAVAR).> #what is the standard deviation of Age in the sample?.> #calculate the standard deviation of a variable with sd(VAR).The code sample below demonstrates both uses of the standard deviation function. Similarly, a standard deviation can be calculated for each of the variables in a dataset by using the sd(DATAVAR) command, where DATAVAR is the name of the variable containing the data. The standard deviation of a single variable can be computed with the sd(VAR) command, where VAR is the name of the variable whose standard deviation you wish to retrieve. Within R, standard deviations are calculated in the same way as means. > #what is the mean of each variable in the dataset?.> #calculate the mean of all variables in a dataset with mean(DATAVAR).> #calculate the mean of a variable with mean(VAR).The code sample below demonstrates both uses of the mean function. Alternatively, a mean can be calculated for each of the variables in a dataset by using the mean(DATAVAR) command, where DATAVAR is the name of the variable containing the data. ![]() In R, a mean can be calculated on an isolated variable via the mean(VAR) command, where VAR is the name of the variable whose mean you wish to compute. Note that all code samples in this tutorial assume that this data has already been read into an R variable and has been attached. This dataset contains hypothetical age and income data for 20 subjects. ![]() Be sure to right-click and save the file to your R working directory. Tutorial Filesīefore we start, you may want to download the sample data (.csv) used in this tutorial. Also introduced is the summary function, which is one of the most useful tools in the R set of commands. This tutorial will explore the ways in which R can be used to calculate summary statistics, including the mean, standard deviation, range, and percentiles. Thus, in spite of being composed of simple methods, they are essential to the analysis process. They also form the foundation for much more complicated computations and analyses. Summary (or descriptive) statistics are the first figures used to represent nearly every dataset. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |