0

One of the columns in my dataframe contains semicolon(;) and when I try to download the dataframe to a csv using fwrite, it is splitting that value into different columns.

Ex: Input : abcd;#6 After downloading it becomes : 1st column : abcd, 2nd column: #6

I want both to be in the same column.

Could you please suggest how to write the value within a single column.

I am using below code to read the input file:

InpData <- read.table(File01, header=TRUE, sep="~", stringsAsFactors = FALSE, 
                      fill=TRUE, quote="", dec=",", skipNul=TRUE, comment.char="‌​") 

while for writing:

fwrite(InpData, File01, col.names=T, row.names=F, quote = F, sep="~")
Z.Lin
  • 28,055
  • 6
  • 54
  • 94
KarthikDG
  • 11
  • 1
  • 1
  • 3
  • 7
    Please provide a minimal [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with data and code so that we can run and test the problem. – MrFlick Sep 06 '17 at 14:37
  • Perhaps you mean `read.csv`? And which separator are you using? `sep=","`? – CPak Sep 06 '17 at 14:58
  • I am using below code to read the input file InpData <- read.table(File01,header=TRUE,sep="~",stringsAsFactors = FALSE,fill=TRUE,quote="",dec=",",skipNul=TRUE,comment.char="") while for writing fwrite(InpData,File01,col.names=T,row.names=F,quote = F,sep="~") – KarthikDG Sep 06 '17 at 15:40

1 Answers1

1

You didn't give us an example, but it is possible you need to use a different separator than ";"

fwrite(x, file = "", sep = ",")

sep: The separator between columns. Default is ",".

If this simple solution does not work, we need the data to reproduce your problem.

Ale
  • 946
  • 4
  • 17
  • 28
  • I am using below code to read the input file InpData <- read.table(File01,header=TRUE,sep="~",stringsAsFactors = FALSE,fill=TRUE,quote="",dec=",",skipNul=TRUE,comment.char="‌​") while for writing fwrite(InpData,File01,col.names=T,row.names=F,quote = F,sep="~") – KarthikDG Sep 06 '17 at 15:43