官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 含山县| 安龙县| 麻城市| 常德市| 肃南| 巴彦县| 二手房| 义乌市| 亳州市| 应城市| 皮山县| 池州市| 溧阳市| 通江县| 江北区| 改则县| 敖汉旗| 盐边县| 晴隆县| 于都县| 庆元县| 汝阳县| 广德县| 陕西省| 建水县| 罗定市| 罗甸县| 黑龙江省| 原平市| 遂平县| 湖州市| 高雄县| 奉节县| 建瓯市| 滦南县| 墨脱县| 海门市| 琼海市| 泗洪县| 色达县| 岱山县|