0

I am trying to read a file which has a column of + and - but apparently associated with a space after that. In anyway I read (read.csv or read.table or read_excel that file I pick up the space after.

For example:

df = data.frame(x = c('a', 'b', 'c'), y = c('+ ', "- ", "+ "))
df
  x  y
1 a + 
2 b - 
3 c + 

Now, is there a way to specifically instruct not to pick up space after the value in read.csv or read_excel

Or is there a way to clean up the spaces after reading into a dataframe?

h3rm4n
  • 4,126
  • 15
  • 21
PDM
  • 84
  • 10
  • 1
    `df$y <- trimws(df$y)` – alistaire Apr 16 '17 at 03:50
  • There is an option in read.table like blank.line.skip. check ?read.table, not sure with csv. – din Apr 16 '17 at 03:50
  • See this thread to learn more about removing whitespace: http://stackoverflow.com/questions/5992082/how-to-remove-all-whitespace-from-a-string – www Apr 16 '17 at 03:56
  • Thanks. the `trimws()` function is not available in my Rstudio. I am able to do that with `stringr` – PDM Apr 16 '17 at 04:35
  • You're using R, not RStudio. RStudio is an IDE. Lack of availability of `trimws` means you're on R < 3.2.0. Upgrade. Tomorrow. – hrbrmstr Apr 16 '17 at 09:03

0 Answers0