cbind() 帮助文档中有这么一段话:
The cbind data frame method is just a wrapper for data.frame(..., check.names = FALSE). This means that it will split matrix columns in data frame arguments, and convert character columns to factors unless stringsAsFactors = FALSE is specified.
意思是cbind()构建数据框data frame的时候,如果参数有矩阵matrix,会拆分矩阵列,并将字符串列chr转换为因子Factor,但是可以用参数stringsAsFactors = FALSE指定关闭这个默认转换功能。
The cbind data frame method is just a wrapper for data.frame(..., check.names = FALSE). This means that it will split matrix columns in data frame arguments, and convert character columns to factors unless stringsAsFactors = FALSE is specified.
意思是cbind()构建数据框data frame的时候,如果参数有矩阵matrix,会拆分矩阵列,并将字符串列chr转换为因子Factor,但是可以用参数stringsAsFactors = FALSE指定关闭这个默认转换功能。
举例:
> a <- matrix(c('A','B','C','D'))
> b <- data.frame(b=c('a','b','c','d'))
> c <- data.frame(c=c('1','2','3','4'),stringsAsFactors = FALSE)
> str(a)
chr [1:4, 1] "A" "B" "C" "D"
> str(b)
'data.frame': 4 obs. of 1 variable:
$ b: Factor w/ 4 levels "a","b","c","d": 1 2 3 4
> s