- 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)
推薦閱讀
- C語言程序設計案例教程(第2版)
- WSO2 Developer’s Guide
- Web程序設計(第二版)
- Ext JS 4 Web Application Development Cookbook
- Mobile Device Exploitation Cookbook
- 案例式C語言程序設計實驗指導
- Simulation for Data Science with R
- Java EE架構設計與開發實踐
- 零基礎學Java第2版
- FusionCharts Beginner’s Guide:The Official Guide for FusionCharts Suite
- Getting Started with the Lazarus IDE
- Python GUI設計tkinter菜鳥編程(增強版)
- 微信公眾平臺服務號開發:揭秘九大高級接口
- C++ Game Development Cookbook
- 跟著迪哥學Python數據分析與機器學習實戰