csv file import

I am trying to read a csv file using read.table() function as follows:

mapfile = "metadata_copy.csv"
map <- read.table(mapfile, header=TRUE, sep=",")

Why is there a < ca > between the two words "biofloc" and technology?
I checked the structure of my table as follows:

dput(map)

structure(list(Sample.Name = c("Sample 1", "Sample 2", "Sample 3",
"Sample 4", "Sample 5", "Sample 6", "Sample 7", "Sample 8", "Sample 9",
"Sample 10", "Sample 11"), Sample.Type = c("type 1", "type 1",
"type 1", "type 1", "type 2", "type 2", "type 2", "type 2", "type 2",
"type 2", "type 2"), Sample.Source = c("Source 1", "Source 1",
"Source 1", "Source 1", "Source 2", "Source 2", "Source 2", "Source 2",
"Source 3", "Source 3", "Source 3"), Aquaculture.Technique = c("Biofloc\xcatechnology",
"Biofloc\xcatechnology", "Earthen pond", "Earthen pond", "Biofloc\xcatechnology",
"Biofloc\xcatechnology", "Earthen pond", "Earthen pond", "Biofloc\xcatechnology",
"Biofloc\xcatechnology", "Biofloc\xcatechnology"), Fish.feed = c("Feed 1",
"Feed 2", "Feed 1", "Feed 2", "Feed 1", "Feed 2", "Feed 1", "Feed 2",
"Feed 1", "Feed 1", "Feed 2")), class = "data.frame", row.names = c(NA,
-11L))

In the structure, the < ca > is shown as \xca.
Please tell me what is this and how can I read the table correctly?

Regards
Hira

Try to load data by read.csv() and add encoding.

mapfile = "metadata_copy.csv"
map <- read.csv(mapfile, header=TRUE, encoding = "UTF-8")
1 Like

Sir, I tried what you suggested but now it is like this

map <- read.csv(mapfile, header=TRUE, encoding = "UTF-8")

> dput(map)
structure(list(Sample.Name = c("Sample 1", "Sample 2", "Sample 3", 
"Sample 4", "Sample 5", "Sample 6", "Sample 7", "Sample 8", "Sample 9", 
"Sample 10", "Sample 11"), Sample.Type = c("type 1", "type 1", 
"type 1", "type 1", "type 2", "type 2", "type 2", "type 2", "type 2", 
"type 2", "type 2"), Sample.Source = c("Source 1", "Source 1", 
"Source 1", "Source 1", "Source 2", "Source 2", "Source 2", "Source 2", 
"Source 3", "Source 3", "Source 3"), Aquaculture.Technique = c("Biofloc\xcatechnology", 
"Biofloc\xcatechnology", "Earthen pond", "Earthen pond", "Biofloc\xcatechnology", 
"Biofloc\xcatechnology", "Earthen pond", "Earthen pond", "Biofloc\xcatechnology", 
"Biofloc\xcatechnology", "Biofloc\xcatechnology"), Fish.feed = c("Feed 1", 
"Feed 2", "Feed 1", "Feed 2", "Feed 1", "Feed 2", "Feed 1", "Feed 2", 
"Feed 1", "Feed 1", "Feed 2")), class = "data.frame", row.names = c(NA, 
-11L))

When I have problems with .csv file turn load with tidyverse.
For better help you try to load the .cvs file.

library(tidyverse)
map <- read_csv(mapfile, header=TRUE, encoding = "UTF-8")
1 Like

Thank you for replying. I loaded the tidyverse library but got an error:

map <- read_csv(mapfile, header=TRUE, encoding = "UTF-8")
Error in read_csv(mapfile, header = TRUE, encoding = "UTF-8") :
unused arguments (header = TRUE, encoding = "UTF-8")

As I had this table in excel so i saved it like this:

map <- read.delim(mapfile, sep = ",")

This worked just correctly. :slight_smile:

Previously I was saving my file like this

This .csv (comma-separated values) was not being read correctly into Rstudio.

Thank you for helping.
Regards
Hira

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.