High.order <- order(education$high, decreasing=TRUE) Similarly, you can order from greatest to least by setting decreasing to TRUE in order(). The function gives you a vector of indices, which you pass to the education data frame and assign to education.high. For example, you can sort states by the percentage of people with at least high school diplomas, least to greatest, using the order() function. It’s often useful to sort rows by a certain column. The data are US state estimates for people with at least high school degrees, bachelors, or higher - one column for each education level. education <- read.csv("2009education.csv", header=TRUE, sep=",", as.is=TRUE) The first index is the row number, and the second is the column number. However, unlike the vector, the data frame is two-dimensional (rows and columns), so use two indices separated with a comma. The data is assigned to the education variable as a data frame, so you can access rows and columns using index values. To save it for later, assign the vector to a variable.įakedata Change Working Directory… menu.With data frame and vectors in mind, load “2009education.csv” with read.csv(). When you enter the above, you create a vector of values, and it’s just sort of gone. Imagine that the values 1 through 5 are data points that you want to access later. Enter this in the window that opened up aka the console.) # Vector Use the c() function to create one, as shown in the line of code below. It’s a structure in R that you use to store data, and you use it often. The c() function is short for “combine” so you essentially tell the computer (in the R language) to combine the values.You have to load and be able to handle data before you can chart it. Loading and handling dataĪ function is a way to tell the computer what to do. For the Linux folk, I’ll leave you to your own devices. For Windows, download the base and the latest version. You can download R for Windows, OS X, or Linux here. I know, I know, the R homepage looks horrible, but just ignore that part.Of course, you need to actually have R installed and running on you computer before you do anything. This straightforward tutorial should teach you the basics, and give you a good idea of what you want to do next. So you want to make some charts in R, but you don’t know where to begin.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |