1

New to R: I have a csv file with 4 coloumns "Accountnumber" ,"description", "estimatedprice", "negotiatedprice"

I wanted to clean the description and remove marks like ,?!#*[}]}';: how do I do it?

I'm writing the following code but the output table doesnot work.

positivefiles <- read.csv('E:/Sanj/text/Second/positive files.csv')
sf <-positivefiles
df <- gsub("[?.;!¡¿·,']/", "", sf)

When I do this df is stored as value but not csv file.

I would like to have the cleaned csv file with description without marks.

Please help me on this Thank You.

4
  • 1
    write.csv(df,"yourCSVname.csv") that will export df to CSV
    – Steve Reno
    Feb 25, 2014 at 19:39
  • 1
    Fyi, [:punct:] will find all the punctuation. A bit easier than writing all the punctuation. Feb 25, 2014 at 19:41
  • Thank you Steve it did export to CSV in my directory, But it contains only numbers My Data is Accountnumbe Description EstPrice NegPrice 12334 This is small,Order: 50 45 When I export the csv it gives me some random numbers
    – Sanjeev
    Feb 25, 2014 at 19:52
  • Are you trying to remove the [ and ]? If so, they should be preceded by a double-backslash. Useful R regex site Feb 25, 2014 at 20:02

2 Answers 2

1

You need to specify to gsub which column in sf you'd like to modify.

Try:

df <- sf
df$description <- gsub("[?.;!¡¿·,']/", "", df$description)

You may need to adjust your statement to match the correct set of characters you'd like to delete.

2
  • Thank you , This one works but it doesnot have the other columns such as accountnumber, Estdol, Netdol df$CLAIM_DESCRIPTION <- gsub("[?.;!¡¿·,:;'/*#@$]", "", df$CLAIM_DESCRIPTION) write.csv(df$CLAIM_DESCRIPTION, "stack.csv")
    – Sanjeev
    Feb 25, 2014 at 20:24
  • I got it finally Thank you.
    – Sanjeev
    Feb 25, 2014 at 20:30
1

Just in case if some one is looking for final code/Experiencing similar problem.

positivefiles <- read.csv('E:/Sanj/text/Second/positive files.csv')
sf <-positivefiles
df <- sf
df$DESCRIPTION <- gsub("[[:punct:]]","",df$DESCRIPTION)
write.csv(df,"cool.csv)

Dictionary : Cool.csv is my final output file stored in directory

Description is one of my column that is only required to modify.

Thank you all for input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.