I have a file with 59 comments and 93 variables in Excel file and I have converted it to .csv. to create the table in R, however my 93 variables appear in the same column. How do I make them appear separate?
I have a file with 59 comments and 93 variables in Excel file and I have converted it to .csv. to create the table in R, however my 93 variables appear in the same column. How do I make them appear separate?
Try to run the command
read.table(file="nomedoarquivo.csv", header=T, sep=",")
This command will work if your file has named columns. If the columns are not named, replace the header = T argument with header = F.
If you saved .csv from excel in Portuguese, you should use read.csv2
. As for read.csv
, it changes because it uses sep = ";"
and dec = ","
, which is the non-American standard.
It's also worth using stringsAsFactors = FALSE
to avoid mess with non-numeric columns:
read.csv2("arquivo.csv", stringsAsFacotrs = FALSE)
Read straight from Excel using the readxl
package
read_excel("arquivo.xlsx")
You can still use the sheet
argument if your spreadsheet has multiple tabs.
Read the help using ?read_excel
. And before all this do not forget to install the package: install.packages("readxl")
.
Reading Excel directly has the advantage of already reading numbers, dates, and strings correctly without having to save .csv
.