0

When importing data using readxl into R (i don't have the other version requiring java as it won't install), using col_names = false, the data will import as characters instead of numbers - which means I can't actually do any functions on them. Similarly, using writexl when creating a table, making col_names = false also turns numbers into text. I can't seem to find a workaround for this (I can't seem to find a function where I can create custom column names so I tried converting the characters into numbers using:

databook[] <- lapply(databook, function(x) as.numeric(as.character(x)))

this worked, however the row that had the specific column titles I wanted (which were letters only) disappeared. I had to import the table using col_names = FALSE because colmn 2 onwards all have the same title and so when r imports it they rename the column titles which I don't want. I tried specifying a particular set of rows on which to run the changes:

databook[2:13,] <- lapply(databook, function(x) as.numeric(as.character(x)))

However, this caused it to no longer convert the characters (using str(databook) returned chr results instead of num). Furthermore, a random empty row was added in row 2, giving me 14 rows when the original table had 13.

I'd be grateful for any help fixing this.

  • 1
    You are better off importing with `col_names=TRUE`, but setting `.name_repair="minimal"` as this won't change your column names at all. Or skip the first row (`skip=1`) when you're reading the data then add your own column names later. – George Savva Feb 27 '20 at 11:07
  • No worries. Its a good idea to read all of the documentation when you use a new function for the first time so you can find things like this. – George Savva Feb 27 '20 at 17:47

0 Answers0