将CSV文件作为R中的单个字符串读取



我有几个.csv文件,其中包含文本字符串。我需要一种RStudio将文本字符串及其文件名存储为dataFrame的方法。

uniqueName_KIwwciwldv.csv包含Hello, I, contain, some numbers like, 12, 10.321

我想要的是,我应该能够创建一个具有列名的单个数据帧,例如:

head(df)
uniqueID                 text
uniqueName_KIwwciwldv    "Hello, I, contain, some numbers like, 12, 10.321"  

我试过读取csv,但它为列分配了单独的值(这不是我想要的(。

也许list.filesreadLines的某种组合可以帮助

csv_files <- list.files(pattern = "\.csv$")
Text <- purrr::map_chr(csv_files, readLines)
data.frame(UniqueID = gsub("\.csv", "", csv_files), 
text=Text)
text
1         uniqueName_KIwwciwldv    Hello, I, contain, some numbers like, 12, 10.321
2 uniqueName_KIwwciwldv_letters    Hello, I, contain, some letters like, A, B, C

相关内容

最新更新