I have a vector of file extensions like (.txt,.TXT,.csv,.xls), i tried "\\.(TXT|txt|csv|xls)$" according to this which return TRUE if any of the extensions are present, however i am interested to return a TRUE if all the extensions are present in the vector otherwise FALSE. Thanks
1 Answer
Try
v1 <- c('a1.txt', 'a2.TXT', 'a3.csv', 'a22.txt', 'a13.TXT', 'a23.txt') ext <- c('txt', 'TXT', 'csv', 'xls') all(ext %in% sub('.*\\.', '', v1) ) #[1] FALSE 16 Comments
Hashim
Still 4 mins to go :):)
Hashim
If i need to check if
txt orTXT and csv and xls, how can i do thatakrun
@Hashim Isn't that the condition in the question or do you need
any in place of all?akrun
@Hashim Based on the example showed, what do you want to return
Hashim
i mean can i do
ignore.case here with all |
allbut it returnsTRUEalways if any of the extension is present.