0

When I try to grep the last line of this list, R returns all the lines in the list, is there a way to make R only grep the last line in this example?

stringlines<-as.list(c("Total des actifs immobilisés 350 952","Total des actifs non courants 357 268",
               "Total des actifs courants 4 324 646",
               "Total des actifs 4 682 115"))
  
  
stringlines[grep("Total des actifs",stringlines,fixed = T)]
#> [[1]]
#> [1] "Total des actifs immobilisés 350 952"
#> 
#> [[2]]
#> [1] "Total des actifs non courants 357 268"
#> 
#> [[3]]
#> [1] "Total des actifs courants 4 324 646"
#> 
#> [[4]]
#> [1] "Total des actifs 4 682 115"

Created on 2021-05-18 by the reprex package (v1.0.0.9002)

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

1 Answers1

0

In case you have a larger file and only want the entries that contain "Total des actifs" followed by numbers and spaces you can use:

stringlines[grep("^Total des actifs [0-9 ]*$", stringlines)]

fisher-j
  • 68
  • 7