How do I reference the row number of an observation? For example, if you have a data.frame called \"data\" and want to create a variable data$rownumber
data.frame
data$rownumber
This is probably the simplest way:
data$rownumber = 1:dim(data)[1]
It's probably worth noting that if you want to select a row by its row index, you can do this with simple bracket notation
data[3,] vs. data[data$rownumber==3,]
So I'm not really sure what this new column accomplishes.