[英]R data.frame with 0 values
我的 pos_TAT 數據框包含 7 行,但最后一行僅在我進行匯總時出現,因為它的值為 0。
summary(pos_TAT)
Delayed$position.type Delayed$TAT
JF :1
S20 :1
S40 :1
S60 :1
Specials :1
S70 :1
14-19 :0
pos_TAT
Delayed$position.type Delayed$TAT
1 JF 45.10965
2 S20 44.37831
3 S40 44.18750
4 S60 45.40698
5 Specials 43.30079
6 S70 42.44444
如果我想添加一個帶有計數的列,這會帶來問題,因為它告訴我第 6 行、第 7 行的行數不同。
我花了幾個小時研究這個問題,但找不到答案。 謝謝你。
當數據集中的factor
列存在未使用的級別時,這可能是可能的。 將列轉換為character
或者如果我們需要將其保留為factor
類,則使用droplevels
或再次調用factor
。
df2 <- droplevels(pos_TAT)
或者
df2 <- transform(pos_TAT, Delayed$position.type= as.character(Delayed$position.type))
該summary
還將提供未使用的級別,如 OP 所示
summary(pos_TAT[1])
# Delayed$position.type
# JF :1
# S20 :1
# S40 :1
# S60 :1
# Specials:1
# S70 :1
# 14-19 :0
pos_TAT <- structure(list(`Delayed$position.type` = structure(1:6, .Label = c("JF",
"S20", "S40", "S60", "Specials", "S70", "14-19"), class = "factor"),
Delayed.TAT = c(45.10965, 44.37831, 44.1875, 45.40698, 43.30079,
42.44444)), .Names = c("Delayed$position.type", "Delayed.TAT"
), row.names = c("1", "2", "3", "4", "5", "6"), class = "data.frame")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.