I have a dataframe with 288 rows and 4 columns. I only need the values of rows 12, 24, 36, ..., 288 that is to say regular intervals of 12, how can I do it?
            Asked
            
        
        
            Active
            
        
            Viewed 34 times
        
    2 Answers
1
            
            
        You can use slice() function from the dplyr package
P.S: next time please provide a reproducible problem with data & code so others can help. See more here: How to make a great R reproducible example?
library(tibble)
library(dplyr)
chosen_vect <- seq(12, 120, 12)
chosen_vect
#>  [1]  12  24  36  48  60  72  84  96 108 120
iris %>% 
  rownames_to_column() %>% # to test if we slice the right rows
  slice(chosen_vect)
#>    rowname Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#> 1       12          4.8         3.4          1.6         0.2     setosa
#> 2       24          5.1         3.3          1.7         0.5     setosa
#> 3       36          5.0         3.2          1.2         0.2     setosa
#> 4       48          4.6         3.2          1.4         0.2     setosa
#> 5       60          5.2         2.7          3.9         1.4 versicolor
#> 6       72          6.1         2.8          4.0         1.3 versicolor
#> 7       84          6.0         2.7          5.1         1.6 versicolor
#> 8       96          5.7         3.0          4.2         1.2 versicolor
#> 9      108          7.3         2.9          6.3         1.8  virginica
#> 10     120          6.0         2.2          5.0         1.5  virginica
Created on 2018-10-31 by the reprex package (v0.2.1.9000)
 
    
    
        Tung
        
- 26,371
- 7
- 91
- 115
0
            
            
        In addition to the above answer, you could also try sequencing in the indexing method.
df <- data.frame(a = 1:288, b = sample(LETTERS, 288, replace = T))
# new data frame
df1 <- df[seq(12,288,12),]
df1
 
    
    
        Mohammed
        
- 11
- 5
 
    