r - How to remove the extra commas from a csv file? -


i trying use csv file in r in read.transactions() command arules package.

the csv file when opened in notepad++ shows commas every non-existing values. so, i'm having manually delete commas before using csv in read.transactions(). example, actual csv file when opened in notepad++ looks like:

d115,dx06,slz,,,, hc,,,,,, dx06,,,,,, dx17,pg,,,,, dx06,rt,dty,dtcr,, 

i want appear below while sending read.transactions():

d115,dx06,slz hc dx06 dx17,pg dx06,rt,dty,dtcr 

is there way can make change in read.transactions() itself, or other way? before that, don't see commas in r(that output showed notepad++)..

so how can remove them in r when can't see it?

a simple way create new file without trailing commas is:

file_lines <- readlines("input.txt") writelines(gsub(",+$", "", file_lines),            "without_commas.txt") 

in gsub command, ",+$" matches 1 or more (+) commas (,) @ end of line ($).

since you're using notepad++, substitution in program: search > replace, replace ,+$ nothing, search mode=regular expression.


Comments