Reputation: 55
I have an issue with the dataset I want to import in R. Basically I got some economic data into excel (MacOS) and then saved the first sheet as a csv file.
However, when I import it: French_data<- read.csv("/Users/lillumultipass/Dropbox/WORK/Economics/French data.csv",header=T,fill=T)
I get something like this (there are 6 columns of data):
1 56\377695 ; 33\377713 ; 56\377836 ; 60\377339 ; 190\377418 ; 333\377382
2 57\377686 ; 33\377546 ; 57\377933 ; 60\377201 ; 190\377083 ; 334\377998
3 58\377296 ; 33\377393 ; 60\377121 ; 62\377610 ; 191\377775 ; 338\377832
So, I have ";" where I should have nothing and instead of the blank space that separates thousands, I have \377 (i.e., the first figure is 56 695). I have tried different combinations of dec and sep but to no avail.
I know this should be very simple, but I am stuck here... thanks!
Upvotes: 1
Views: 1245
Reputation: 59355
If your data starts out in Excel, consider using the XLConnect package. I've had much more success with this than with exporting Excel to CSV and importing that. So, something like this:
library(XLConnect)
myWB <- "myWorkbook.xlsx"
wb <- loadWorkbook(myWB)
data <- readWorksheet(wb, sheet="Sheet1")
Upvotes: 0
Reputation: 59479
read.table
doesn't have an option for thousands delimiter. But you can filter the character out manually:
French_data$column <- as.integer(gsub("\377", "", French_data$column))
Upvotes: 0
Reputation: 66834
Use read.csv2
. It is designed specifically for continental European csv files.
read.csv and read.csv2 are identical to read.table except for the defaults. They are intended for reading ‘comma separated value’ files (‘.csv’) or (read.csv2) the variant used in countries that use a comma as decimal point and a semicolon as field separator.
Upvotes: 4