data.frame, cbindは文字列(character)ではなく因子(Factor)がデフォルトだった・・・っけ?

掲題の件、どうやらそうだったらしい。
なので、毎回stringsAsFactorsを設定すると(Hadleyverseはあえてつかわない)


お元気で。

> df <- data.frame(x=1:3, y=letters[1:3])
> str(df)
'data.frame':	3 obs. of  2 variables:
 $ x: int  1 2 3
 $ y: Factor w/ 3 levels "a","b","c": 1 2 3
> df <- data.frame(x=1:3, y=letters[1:3], stringsAsFactors = FALSE)
> str(df)
'data.frame':	3 obs. of  2 variables:
 $ x: int  1 2 3
 $ y: chr  "a" "b" "c"
> 
> str(cbind(df, LETTERS[1:3]))
'data.frame':	3 obs. of  3 variables:
 $ x           : int  1 2 3
 $ y           : chr  "a" "b" "c"
 $ LETTERS[1:3]: Factor w/ 3 levels "A","B","C": 1 2 3
> str(cbind(df, LETTERS[1:3]), stringsAsFactors = FALSE)
'data.frame':	3 obs. of  3 variables:
 $ x           : int  1 2 3
 $ y           : chr  "a" "b" "c"
 $ LETTERS[1:3]: Factor w/ 3 levels "A","B","C": 1 2 3