Extracting a column from data frame to a vector

I want to extract a column from the data frame (gapminder dataset) as a vector using various code:

head(gapminder)

country continent year lifeExp pop gdpPercap

1 Afghanistan Asia 1952 28.8 8425333 779.
2 Afghanistan Asia 1957 30.3 9240934 821.
3 Afghanistan Asia 1962 32.0 10267083 853.
4 Afghanistan Asia 1967 34.0 11537966 836.
5 Afghanistan Asia 1972 36.1 13079460 740.
6 Afghanistan Asia 1977 38.4 14880372 786.

i try to take life expectancy column with varius codes

#1
gapminder %>% filter(year == 1952) %>% select(lifeExp)

#2
gapminder[gapminder$year==1952,4]

all the returns are data with this class

[1] "tbl_df"     "tbl"        "data.frame"

I change the class with as.vector(), but the result still the same

Question:

  1. What is the class mean?
  2. how can i change to vector? I want to make a plot, and plot (x,y) require a vector

Have you tried gapminder[["lifeExp"]]?

Yes, that's helpful. Thank you.

May you explain more how that code works?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.