I want to add a new column (Scannumber_1m) in dfs within a list (=dfs_list). Another df (single_df) contains values in the column row_start. I want now to take the value from df$row_start, go within dfs in list to the column Scannumber (continious numbers starting at 1) and when value of Scannumber == df$row_start I want to start counting in the new column (Scannumber_1m) to start counting from 1 to 500 the following rows. The other rows should contain 0.
I tried already, but only could fill in 0 in the new_column
new_list <- lapply(dfs_list, function(df) {
df <- df %>%
add_column(Scannumber_1m = 0, .after = "Scannumber")
return(df)
})
Like that the new column is there already, but I don’t know how to start at certain row with the value from single_df$row_start with counting. names(dfs_list) == single_df$data.
Please make this question reproducible. This includes sample unambiguous data (e.g.,
data.frame(x=...,y=...)
or the output fromdput(head(x))
into a code block), and intended output given that input. Refs: stackoverflow.com/q/5963269, minimal reproducible example, and stackoverflow.com/tags/r/info.