I am trying to import a data downloaded from Qualtrics into R. It is a csv file.
However, I encounter 2 problems.
- R could not figure out the format of each column by itself, probably because row 2 and row 3 (highlighted above) are all useless text. R thinks that all columns are
character
. However, obviously some aredate
, some arefactor
, and some areinteger
. How can R figure out the data class of each column correctly by itself?
library(tidyverse) filename <- "mydata.csv" df = read_csv(filename, col_names = TRUE) Parsed with column specification: cols( .default = col_character() ) See spec(...) for full column specifications.
- I also tried to load the variable name (
header
) and data matrix separately. Unfortunately, using theskip = 3
argument does not work. It says that my data only has 1 observation... Why?
filename <- "mydata.csv" headers = read_csv(filename, col_names = FALSE, n_max = 1) df = read_csv(filename, skip = 3, col_names = FALSE) colnames(df)= headers
Error in names(x) <- value :
'names' attribute [273] must be the same length as the vector [1]
What is a good way to import my csv file into R?