我遇到了問題expand.grid
。它似乎忽略了我在腳本頂部設置的選項。爲什麼expand.grid忽略選項?
對於〔實施例:
options(stringsAsFactors = FALSE)
tmp <- expand.grid(x = letters, y = 1:10)
回報:
> str(tmp)
'data.frame': 260 obs. of 2 variables:
$ x: Factor w/ 26 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10 ...
$ y: int 1 1 1 1 1 1 1 1 1 1 ...
- attr(*, "out.attrs")=List of 2
..$ dim : Named int 26 10
.. ..- attr(*, "names")= chr "x" "y"
..$ dimnames:List of 2
.. ..$ x: chr "x=a" "x=b" "x=c" "x=d" ...
.. ..$ y: chr "y= 1" "y= 2" "y= 3" "y= 4" ...
我在做什麼錯?
因爲參數是硬編碼,而不是設置爲'default.stringsAsFactors()'。可以說,如果你有厚厚的皮膚,那麼可以把它作爲一種潛在的改變提出來。 – joran
'?options'表明'options(stringsAsFactors = FALSE)'只會影響'data.frame'和'read.table':''stringsAsFactors':'data.frame'和'read的參數的默認設置。表'。」 –