Problem with calling the columns in R

Hello everyone,

I have a R code which I run it once, the second time I want to run it, I receive the error which one column could not be found.
This is the code:

dat <- read.csv2("donnees/donneesOdeurs_400180_202310013.csv") %>%
  dplyr::select(Traitement:P5)

and this is the error:

rlang::last_trace()
<error/vctrs_error_subscript_oob>
Error in dplyr::select():
! Can't select columns that don't exist.
:heavy_multiplication_x: Column Traitement doesn't exist.


is there anyone could help me?

Could you show us

glimpse(read.csv2("donnees/donneesOdeurs_400180_202310013.csv"))

Hi @azinzand, this said that the Traitement doesn't exist in the data frame dat. So, you need to check the correct names of the data frame.

names(dat) # You get col names and next try your script.

but it does really exist as you can see in the image below:

but it does really exist as you can see in the image below:

But column P5 does not exist. Are you sure this is the file it loads on the first run? Does the code change the file?

I changed P5 to P4, but still received the same error

I can see why you're puzzled. Maybe post a few rows of the csv file here, as text not as a picture.

sure, here it is:

Traitement Periode Repetition P1 P2 P3 P4
Fumier_VacheL_B.Verticaux Avant 27 240 240 240 240
Fumier_VacheL_B.Verticaux Pendant 27 480 480 960 960
Fumier_VacheL_B.Verticaux Après 27 480 480 240 240
Fumier_VacheL_B.Verticaux Avant 28 240 480 240 480
Fumier_VacheL_B.Verticaux Pendant 28 960 1940 1940
Fumier_VacheL_B.Verticaux Après 28 240 480 480
Fumier_VacheL_B.Verticaux Avant 29 240 240 240 480
Fumier_VacheL_B.Verticaux Pendant 29 480 480 240 480
Fumier_VacheL_B.Verticaux Après 29 480 240 240 240
Fumier_VacheL_B.Horizontaux Avant 30 240 480 1940 480
Fumier_VacheL_B.Horizontaux Pendant 30 480 240 960 480
Fumier_VacheL_B.Horizontaux Après 30 480 240 960 480

Works perfectly for me...which I realize is not very helpful.

Hello everyone, it seems I found the problem with this code. it can only read up to P2 in a line and shift the rest of columns in another line. do you have any idea to modify it in my csv file or in R studio?

This suggests that there is something funky with the file, like an end-of-line where it doesn't belong. What happens if you read it into Excel? If it reads in properly, you might save a copy from Excel and try to load that copy into R.

Could I ask how many rows the table has? And are the contents publicly shareable, or are they private or proprietary in nature?

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.