我有一个数据框架( table1
),具有以下架构:
> table1
sides frequency relFrequency
1 1 1 0.1
2 2 3 0.3
3 3 0 0.0
4 4 3 0.3
5 5 1 0.1
6 6 2 0.2
> summary(table1)
sides frequency relFrequency
Min. :1.00 n.vars :1 n.vars :1
1st Qu.:2.25 n.cases:10 n.cases:1
Median :3.50
Mean :3.50
3rd Qu.:4.75
Max. :6.00
我想创建一个类似于绘图直方图的直方图:
plot(table1$sides, table1$relFrequency, type="h")
不幸的是,y轴没有值。我认为这是因为relFrequency
被视为一个因素。我可以将因子转换为数值吗?
谢谢。
//编辑
> dput(table1)
structure(list(side = c(1, 2, 3, 4, 5, 6), frequency = structure(c(1L,
3L, 0L, 3L, 1L, 2L), .Dim = 6L, class = "table"), relFrequency = structure(c(0.1,
0.3, 0, 0.3, 0.1, 0.2), class = "table", .Dim = 6L)), row.names = c(NA,
6L), class = "data.frame")
> str(table1)
'data.frame': 6 obs. of 3 variables:
$ side: num 1 2 3 4 5 6
$ frequency : 'table' int [1:6(1d)] 1 3 0 3 1 2
$ relFrequency : 'table' num [1:6(1d)] 0.1 0.3 0 0.3 0.1 0.2
答案 0 :(得分:0)
在此之后,它确实起作用了:
table1$frequency <- as.numeric(table1$frequency)
aufgabe1$relFrequency <- as.numeric(table1$frequency)