1

I have single quote (' ') in every item of my dataframe, mydf. How can I remove those single quotes? For example, if I print colnames(mydf), I get 'column1', 'column2' and so forth.

I just want column1, column2 without any quotes. I want same for all the vectors in those columns.

MAPK
  • 5,635
  • 4
  • 37
  • 88
  • 1
    it's a data frame and not a matrix, correct? please add the `dput` or something – rawr Dec 08 '15 at 02:14
  • @rawr Yes, it is a dataframe. – MAPK Dec 08 '15 at 02:14
  • 1
    You mean you have single quotes inside double quote in the output? R typically prints out character values in quotes. What are you planning to do with the unquoted values? A [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output would be most helpful. – MrFlick Dec 08 '15 at 02:29
  • 1
    print(colnames(mydf), quote=F) – Ven Yao Dec 08 '15 at 02:31

1 Answers1

2

This technique should work

x <- data.frame(c1=c("'hello'", "'goodbye'"),
            c2=c("'why'","'mumble'"))
names(x) <- c("'c1'", "'c2'")

names(x) <- substr(names(x), 2, nchar(names(x))-1)
x <- as.matrix(x)
x <- substr(x, 2, nchar(x)-1)
x <- as.data.frame(x)

I've edited my original answer to show how you could convert the data frame to a matrix and back to a data frame.

nathanesau
  • 1,681
  • 16
  • 27