Reputation: 1769
How to keep every fifth row (and deleting all the others) in a file Excel? For example, I have a starting file like this:
07/12/1989 106,9
08/12/1989 106,05
12/12/1989 103,1
13/12/1989 106,5
14/12/1989 104,75
15/12/1989 105,6
18/12/1989 104,5
19/12/1989 106,2
20/12/1989 106,5
21/12/1989 107,5
22/12/1989 109,8
and I would like the result:
07/12/1989 106,9
15/12/1989 105,6
22/12/1989 109,8
Upvotes: 0
Views: 85
Reputation: 11659
Let assume you have this dataset:
dt<-data.frame(ID=LETTERS, stringsAsFactors = F)
Then you can do:
as.data.frame( dt[ 1:nrow(dt) %% 5 ==0,])
Upvotes: 2
Reputation: 3221
Try this:
Step 1: Read excel file in R using read.xlsx
Step 2: Generate the sequences and then retrieve rows based on sequences
indexes<-seq(1,nrow(df),5) # Set index
df[indexes,] # Retrive only index
Output:
V1 V2
1 07/12/1989 106,9
6 15/12/1989 105,6
11 22/12/1989 109,8
Step 3: Store this result to excel file using write.xlsx
Upvotes: 3