Unused argument?

HI

I have a problem, with the dataset I have. when I import it with CSV, without specifying anything all the columns are character class, while some are definitly numeric. So I tried to pass the option stringsAsFactors as False may be it will differentiate between them, but I got a message that Unused argument (stringsAsFactors = FALSE), so I don't understand. In the first version after all the columns were character, I used the as.numeric to convert them to numeric and I see it is done in the environment, but when I check the class there are still character. does someone have an answer please?

# To clean up the memory of your current R session run the following line
rm(list=ls(all=TRUE))

#install tidyverse and reprex
install.packages("tidyverse")
#> Installing package into 'C:/Users/walid/Documents/R/win-library/3.4'
#> (as 'lib' is unspecified)
#> package 'tidyverse' successfully unpacked and MD5 sums checked
#> 
#> The downloaded binary packages are in
#>  C:\Users\walid\AppData\Local\Temp\Rtmpgz0mZh\downloaded_packages
library(reprex)

# Set your directory to the folder where you have downloaded the SKU dataset



# install readr
library(readr)

# Let's load our dataset

data <- read_csv('New_York_City_Leading_Causes_of_Death.csv', stringsAsFactors = FALSE)
#> Error in read_csv("New_York_City_Leading_Causes_of_Death.csv", stringsAsFactors = FALSE): argument inutilisé (stringsAsFactors = FALSE)

dataset link

https://www.dropbox.com/s/3usf8y75vz2cpj4/New_York_City_Leading_Causes_of_Death.csv?dl=0


Created on 2018-04-16 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0).


Created on 2018-04-16 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0).
 cordially
walid

I haven't tested this, but I would suspect that the . characters used to denote missing values are being read as character values. If you would like those to be read as missing values, try using

data <- read_csv('New_York_City_Leading_Causes_of_Death.csv', na = ".")

That function has no stringsAsFactors argument, which is why you see that message. You can see this by reading the docs ?readr::read_csv or using the args function:

> args(readr::read_csv)
function (file, col_names = TRUE, col_types = NULL, locale = default_locale(), 
    na = c("", "NA"), quoted_na = TRUE, quote = "\"", comment = "", 
    trim_ws = TRUE, skip = 0, n_max = Inf, guess_max = min(1000, 
        n_max), progress = show_progress()) 

I haven't tested your example since I'm not clear on what you're expecting with factors, strings and numbers.

3 Likes

To add to @Frank's correct reply: none of the tidyverse packages transforms characters to factors. So you can just remove your stringsAsFactors = FALSE and no factor will be created.

thank you very much for all your responses

actually I would like to make a linear regression, so I need numeric values no characters, am I right?

also I just skipped the tydiverse library and only used the utils, and set the na = c("", "NA", ".") to make sure all kink of NAs are taken in account, and now all the data have the correct class. :grinning: