Johannes Wiesner
Johannes Wiesner

Reputation: 1307

How to read in a CSV file in R without the quotation marks?

All the values except in my .csv file except for one column called year are surrounded by three double-quotation marks. When I read in the file in RStudio using read.csv2, all values (including the column names) still got double-quotation marks (one before and after) around them. How do I switch off this behavior?

Here's an example with the column names and the first row.

"""Title""";"""Author""";"""year""";"""doi""";"""query_title"""
"""This is a title""";"""Smith""";2002;"""12345""";"""Another Title"""

Upvotes: 1

Views: 1903

Answers (1)

Georgery
Georgery

Reputation: 8127

You can simply remove them afterwards:

library(tidyverse)

df <- read_csv("yourFile.csv")

removeQuotes <- function(x) gsub("\"", "", x)

df <- df %>%
    mutate_if(is.character, removeQuotes)

Upvotes: 2

Related Questions