1

How do I call the index of my data.frame in R like this

x <- index(data) 

y1 <- data$y1

y2 <- data$y2

My data.frame have 3 variables. My ID variables does not have all unique values, as most of my individuals have two scenarios. While the index (provided by R) lists my data from 1:40 (40 values). I want my x-axis to go from 1 to 40.

ID {1, 1, 2, 3, 3, 4, 7, 12, ..., 50, 51, 57, 57}

y1 {....}

y2 {....}

plot(y1) 

plots the index automatically as x-axis. I want to specify this manually.

patL
  • 2,259
  • 1
  • 17
  • 38
kiniena
  • 11
  • 4
  • 1
    Welcome on SO! Please see [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and share your data using `dput()` – MonJeanJean Apr 20 '22 at 11:48
  • 1
    Are you looking for `seq(nrow(data))`? Also `seq_along(y)` is another option. – Allan Cameron Apr 20 '22 at 11:52
  • Yeah I was looking for nrow. This question have been answered before: https://stackoverflow.com/a/2370770/4190720. x <- 1:nrow(df) was the solution for my problem. Thank you! – kiniena Apr 20 '22 at 12:16

0 Answers0