Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

Convert ; (semicolon) seperated csv file to xlsx using R

I have a CSV file seperated by ; which i need to convert in xlsx using R

I am able to convert it but only issue i found in the output file is that there is a semicolon(;) inbetween data column like "Material Description" "CONNECTION SET PP G5/8-HOSE6/12;10/16" due to which the data is getting split in between columns which is creating an issue as attached in the image.

Is there any way to handle such scenario which generally occurs due to bad data entry There are 1-2 lines with such issues , is there any way to fix this issue before creating the dataframe.??

Output of R code - Data getting split in columns:

enter image description here


Coding efforts of the TO:

library(xlsx)
library(xlsxjars)
library(openxlsx)

ab<-read.csv2("C:/Path/Jan-2020.csv",sep = ";",quote = "")
ab<-as.data.frame(sapply(ab,function(x) gsub('"','',x)))
ab<-as.data.frame(sapply(ab,function(x) gsub(',,,','',x)))
ab<-as.data.frame(sapply(ab,function(x) gsub(',,','',x)))
ab<-as.data.frame(sapply(ab,function(x) gsub('#','',x)))
question from:https://stackoverflow.com/questions/65950933/convert-semicolon-seperated-csv-file-to-xlsx-using-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...