My pos_TAT data frame contains 7 rows but the last one appears only when I do summary because its value is 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
That poses problem if I want to add a column with the count for example as it tells me there's a different number of rows 6, 7.
I've spent hours looking into that problem but can't find the answer. Thank you.
This could be possible when there are unused levels for factor
columns in the dataset. Either convert the column to character
or if we need to keep it as factor
class, then use droplevels
or call factor
again.
df2 <- droplevels(pos_TAT)
Or
df2 <- transform(pos_TAT, Delayed$position.type= as.character(Delayed$position.type))
The summary
would also give the unused levels as the OP showed
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.