- Modern R Programming Cookbook
- Jaynal Abedin
- 113字
- 2021-07-08 09:48:32
There's more…
The data.frame() function has an optional argument stringsAsFactors, which prevents the character columns' automatic conversion into factors. A factor is another R data type that is used to represent categorical variables such as 1 for M and 2 for the F category. In the dataset that you have created using the data.frame() function, notice that the column GENDER is a factor type, though you did not explicitly mention it. Intuitively, the GENDER column should be a character column with values M and F. To prevent this automatic conversion, you must use stringsAsFactors=FALSE as follows:
datB <- data.frame(ID = 1:5, hourSpetOnInternet = c(5,3,4,1,2),
GENDER = c("M", "F", "F", "M", "F"), stringsAsFactors=FALSE)
推薦閱讀
- Visual Basic程序開發(學習筆記)
- INSTANT FreeMarker Starter
- Functional Kotlin
- Big Data Analytics
- 琢石成器:Windows環境下32位匯編語言程序設計
- Spring+Spring MVC+MyBatis整合開發實戰
- Go并發編程實戰
- SciPy Recipes
- Learning C++ by Creating Games with UE4
- Java EE 8 and Angular
- Python物理建模初學者指南(第2版)
- 大規模語言模型開發基礎與實踐
- 大話程序員:從入門到優秀全攻略
- Analytics for the Internet of Things(IoT)
- 走近SDN/NFV