3/9/2024 0 Comments Pca columns in dataframe r![]() ![]() Not surprisingly, the variables also have vastly different variances: the UrbanPop variable measures the percentage of the population in each state living in an urban area, which is not a comparable number to the number of crimes committeed in each state per 100,000 individuals. We can also examine the variances of the four variables using the apply() function: apply(USArrests, 2, var) ![]() We see right away the the data have vastly different means. ![]() The second input here denotes whether we wish to compute the mean of the rows, 1, or the columns, 2: apply(USArrests, 2, mean) We can use the apply() function to apply a function - in this case, the mean() function - to each row or column of the data set. Let’s start by taking a quick look at the column means of the data. The columns of the data set contain four variables relating to various crimes: names(USArrests) The rows of the data set contain the 50 states, in alphabetical order: library(dplyr) In this lab, we perform PCA on the USArrests data set, which is part of the base R package. 10.4 Lab 1: Principal Components Analysis ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |