Last active
November 4, 2019 09:42
-
-
Save romain9292/a8eadaf3feec46e69c984afec211902a to your computer and use it in GitHub Desktop.
[Concatener plusieurs fichiers textes en un dataframe ] En applicant un pattern matching sur l'extension .txt #dataframe #text #R #bind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Une librairie pour la data manipulation (Jointures,Subsetting) | |
library(data.table) | |
#Créer une liste de tous les fichiers .txt avec les noms | |
filelist = list.files(pattern = ".*.txt") | |
#Dans la liste des fichiers, on va charger comme data frame tous les fichiers .txt | |
data_list = lapply(filelist, read.table, sep = ",") | |
#Creation du dataframe, en assumant que les headers sont les mêmes | |
datafr = do.call("rbind", data_list) | |
#Conversion en minuscules | |
datafr$V1 <- tolower(datafr$V1) | |
#Supression des doublons | |
datafr <- datafr[!duplicated(datafr$V1),] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment