I am not sure the title is worded correctly, I am somewhat new to R. I am using a meaningless task to refresh my memory. I have some United States population data. What I want to do is make a for loop that goes through and plots the population of each state. Here is what I have done so far. Right now I am trying to figure out how to make it print the population as a test.
a <- split(data,list(state)) ##split factor state into individual states
For example str(a$'Alabama'$Population)
is numeric of the populations I want to plot.
for(i in 1:53){
b <- noquote((paste(c("a","$", "'",state.list[i],"'", "$","Population"),collapse="")))
}
Now If I print(b) the ouput is a$'Alabama'$Population, however str(print(b)) says it is a character. If I could get it to be a numeric I could move on the next part of my code.
Does this make sense?
Any tips are appreciated. Since this is a learning exercise for me I'd like to know how to solve this problem. However, I am open to better ways of doing this.
dput(head(data, 10))
structure(list(State = structure(c(46L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L), .Label = c("Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut", "Delaware", "District of Columbia",
"Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana",
"Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland",
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
"Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey",
"New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Puerto Rico", "Rhode Island",
"South Carolina", "South Dakota", "Tennessee", "Texas", "United States",
"Utah", "Vermont", "Virginia", "Washington", "West Virginia",
"Wisconsin", "Wyoming"), class = "factor"), Population = c(308.745538,
4.779736, 0.710231, 6.392017, 2.915918, 37.253956, 5.029196,
3.574097, 0.897934, 0.601723), Year = structure(c(6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("2,010", "2,011", "2,012",
"2,013", "2,014", "Census"), class = "factor")), .Names = c("State",
"Population", "Year"), row.names = c(NA, 10L), class = "data.frame")
link to full dput
: http://pastebin.com/Mg16q67m
link to manual plot https://i.stack.imgur.com/A15sm.jpg