![]() ![]() We get an error because the data contains missing observations! R will not skip missing values unless explicitly requested to do so. > apply(airquality, 2, mean) #do for multiple columns at onceĮrror in FUN(newX. Let's first find the column means using the apply command: apply() is extremely useful, as are its cousins tapply() and lapply() (more on these functions later). We can also get summary statistics for multiple columns at once, using the apply() command. ![]() How would you use this method to get quintiles? Answer Apply() Commands To get the deciles, use the sequence function: It is also possible to obtain other quantiles this is done by adding an argument containing the desired percentage cut points. The difference between the first and third quartiles is called the interquartile range (IQR) and is sometimes used as an alternative to the standard deviation. Never attach two data sets that share the same variable names- this could lead to confusion and errors! A good idea is to detach a data set as soon as you have finished working with it.įor now, let's keep this data set attached, while we test out some other functions.īy default you get the minimum, the maximum, and the three quartiles - the 0.25, 0.50, and 0.75 quantiles. Once we are finished working with this data set, we can use the detach() command to remove this data set from the working memory. For example, the above can then be accomplished by: If we don't want to keep using the "$" sign to point to the data set, we a can use the attach command to keep the data set as the current or working one in R, and then just call the variables by name. Similarly, we can compute the median Temp: Recall that we can compute the mean Temp by "extracting" the variable Temp from the dataset using the $ function as follows: To recall the components of the data set, print out the first 5 rows. We will continue this with the airquality data. #Rcode to construct a bar plot series#The first module in this series provided an introduction to working with datasets and computing some descriptive statistics.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |