Rstudio: Dataset Error

hello, I am having trouble with a code as everything is fine until I find there is nothing happening when I want to fix the name of a country column for my data.

I have done the following and has worked:

# Load "oil consumption per capita" dataset from CSV.
oil_consumption_per_cap <- read_csv("oil_consumption_per_cap.csv")
# View first few lines
head(oil_consumption_per_cap)

this is where I got the problem:

# Fix name of country column
colnames(oil_consumption_per_cap)[1] <- "country"

and nothing happens to my data to appear that it has been adjusted. please help

I do not see anything wrong with your code. I tried a similar thing just to be sure and the results are below. How exactly do you check that the column name has not changed?

> DF <- read_csv("Dummy.csv")
Parsed with column specification:
cols(
  A = col_double(),
  B = col_double(),
  C = col_double(),
  D = col_double()
)
> DF
# A tibble: 2 x 4
      A     B     C     D
  <dbl> <dbl> <dbl> <dbl>
1     1     2     3     4
2     5     6     7     8
> colnames(DF)[1] <- "Z"
> DF
# A tibble: 2 x 4
      Z     B     C     D
  <dbl> <dbl> <dbl> <dbl>
1     1     2     3     4
2     5     6     7     8

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