- Modern R Programming Cookbook
- Jaynal Abedin
- 273字
- 2021-07-08 09:48:32
How it works…
The data.frame() function works similarly to the cbind() function, but it preserves data types of each of the columns. In the cbind() function, all the columns are converted to character if any of the columns are of character type. See the conversion rules in the earlier recipe, Creating a vector and accessing its properties for more details.
The other functions such as nrow(), ncol(), and colnames() work in the same way as they do in a matrix. The str() function is a special function to know the structure of the data frame. It gives the output of data types for each column, along with the first few values of the columns and column names.
To get access to a column, you can use the dollar sign $ next to the data frame name, such as datA$ID, to get access to the ID column of the data frame. Similarly, you can specify the column name with double-square brackets and use quotation, for example, datA[["ID"]]. Moreover, the columns are implicitly indexed by serial numbers from 1 to the number of columns, for example, 1 to 3 in this case. You can get access to a column by giving the position index of the column. For example, to get access to the ID column, you can execute the following code:
datA[,1] # this is similar to extracting elements from a matrix
The other two functions head() and tail() are to print the content of the dataset from the top six and bottom six rows. If you use only head(datA), by default, it will print the top six rows of the data frame.
- Monkey Game Development:Beginner's Guide
- Visual FoxPro 程序設(shè)計
- Designing Hyper-V Solutions
- PHP+MySQL+Dreamweaver動態(tài)網(wǎng)站開發(fā)實(shí)例教程
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲案例實(shí)戰(zhàn)全流程詳解(高級進(jìn)階篇)
- Java Web程序設(shè)計任務(wù)教程
- Scala程序員面試算法寶典
- Java網(wǎng)絡(luò)編程實(shí)戰(zhàn)
- Modernizing Legacy Applications in PHP
- HTML5移動Web開發(fā)
- 原型設(shè)計:打造成功產(chǎn)品的實(shí)用方法及實(shí)踐
- 體驗(yàn)之道:從需求到實(shí)踐的用戶體驗(yàn)實(shí)戰(zhàn)
- Thymeleaf 3完全手冊
- Building E-Commerce Solutions with WooCommerce(Second Edition)
- Python AI游戲編程入門:基于Pygame和PyTorch