data<-c(ID Math History Chem Group 1 S1 98 92 95 J 2 S2 96 90 93 S 3 S3 99 93 96 J 4 S4 100 94 97 J 5 S5 99 93 96 S 6 S6 95 89 92 S 7 S7 93 87 90 J 8 S8 94 88 91 S 9 S9 99 93 96 J 10 S10 97 91 94 J 11 S11 95 89 92 S 12 S12 92 86 89 S 13 S13 91 85 88 J 14 S14 89 83 86 S 15 S15 93 87 90 J 16 S16 99 93 96 S 17 S17 92 86 89 J 18 S18 91 85 88 S 19 S19 99 93 85 J ), 在R语言中,check the mode of each column 代码
时间: 2024-01-02 22:01:56 浏览: 70
可以使用str函数来查看数据框中每列变量的类型,示例代码如下:
```
data<-data.frame(ID=c(1:19),
Math=c(98,96,99,100,99,95,93,94,99,97,95,92,91,89,93,99,92,91,99),
History=c(92,90,93,94,93,89,87,88,93,91,89,86,85,83,87,93,86,85,93),
Chem=c(95,93,96,97,96,92,90,91,96,94,92,89,88,86,90,96,89,88,85),
Group=c("J","S","J","J","S","S","J","S","J","J","S","S","J","S","J",
"S","J","S","J"))
str(data)
```
运行结果如下:
```
'data.frame': 19 obs. of 5 variables:
$ ID : int 1 2 3 4 5 6 7 8 9 10 ...
$ Math : num 98 96 99 100 99 95 93 94 99 97 ...
$ History: num 92 90 93 94 93 89 87 88 93 91 ...
$ Chem : num 95 93 96 97 96 92 90 91 96 94 ...
$ Group : Factor w/ 2 levels "J","S": 1 2 1 1 2 2 1 2 1 1 ...
```
从运行结果可以看出,ID、Math、History、Chem列的类型是numeric,Group列的类型是factor。
阅读全文