Get filename without extension in R

后端 未结 7 1908
野趣味
野趣味 2020-12-01 05:56

I have a file

ABCD.csv 

The length before the .csv is not fixed and vary to any length.

How can I extract the portion

7条回答
  •  误落风尘
    2020-12-01 06:27

    You can try this also:

    data <- "ABCD.csv"
    gsub(pattern = "\\.csv$", "", data)
    
    #[1] "ABCD"
    

    This will be helpful in case of list of files as well, say

    data <- list.files(pattern="\\.csv$") , using the code will remove extension of all the files in the list.

提交回复
热议问题