Closed jharsell closed 4 years ago
This looks good and correctly uses the |
operator.
files_BGN <- list.files(bys_dir, pattern = "bend_gate|niagara", full.names = TRUE)
## check
files_BGN
Moving to the next bit
## init list
df_BGN_list <- list(files_BGN)
you don't need to put files_BGN
inside list()
: you can just use list()
with empty parentheses, which will make sure that R knows df_BGN_list
is a list object with, for the moment, nothing in it.
Moving forward:
## 2.
## use loop to read in files
for (i in 1:length(files_BGN)) {
df_bgn_list[[i]] <- read_csv(files_BGN[i])
mutate(df_BGN_list, relative_path =="../data/schools/by_test/bend_gate_1980.csv")
}
First, your loop looks correctly set up as does your first bit of code inside the loop. My guess is that if you just deleted the second line inside the loop, your code runs. Yes?
The second line inside the loop,
mutate(df_BGN_list, relative_path =="../data/schools/by_test/bend_gate_1980.csv")
is where I see a couple of issues. First, remember that {dplyr} works with data frames (tibbles) and that df_BNG_list
is a list. It contains data frames, but as a whole is a list. Instead of calling df_BGN_list
, could you use a %>%
to connect read_csv()
and mutate()
? That way, you can leave out the first .data
argument inside mutate()
and just add your new column.
Two last things.
mutate()
, remember that in general, =
means assignment (like <-
) whereas ==
is a test for equality. Closing (see the example code in your repo), but reopen if you have other questions.
Hi All,
Definitely losing the war with the assignment this week. I seem to get a bit of traction (as in no red) running the code below; however, I get the following error "Error: Argument 1 must have names". Can anyone pinpoint why I have that error or any additional errors in the code for all of question one below?
Many thanks for any help or insight you can provide! Jaime