'Change row names based on row number

I have a column with 82 rows, which are completely filled with NA's, called 'treatment'. I want to change the rows 1-21 and 43-64 to 'Control', and the rows 22-42 and 65-82 to 'Fluox'.

How can I achieve this without having to define every row by itself?



Solution 1:[1]

You can do the following:

NAME_OF_DATASET$treatment[c(1:21, 43:64)] = 'Control'
NAME_OF_DATASET$treatment[c(22:42, 65:82)] = 'Fluox'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tivd