Reputation: 3
I'm new to R and this is definitely a beginner question but I can't seem to figure out how to solve it looking at other questions on here - I have a vector with a row of years and a row of values:
Is there any way to pinpoint to a specific value by year? I know I can extract a specific value by its coordinates through vector[x,y], but is there any way to do that to extract the value of y where x="1900" for example?
Upvotes: 0
Views: 39
Reputation: 41285
As @SamR also said in the comments you can use the following code. First I created your data with the year 1900
added as an example to show:
df <- data.frame(Year = c(1901, 1906, 1911, 1916, 1921, 1900),
population.size = c(45549, 50310, 52722, 52998, 56988, 57291))
df$population.size[df$Year==1900]
Output:
[1] 57291
Upvotes: 1