R-Amature
R-Amature

Reputation: 1

R: Change every 5th value in a column in a data frame

I have a data frame uploaded from excel with 10 columns and 100 rows, and all the data is 0. Now I would like to change every 5th value in the second column to 1. Is this possible? If so, how?

Upvotes: 0

Views: 184

Answers (1)

nghauran
nghauran

Reputation: 6768

One approach using seq is df[seq(from = 5, to = nrow(df), by = 5), 2] <- 1

Upvotes: 1

Related Questions