这是非常基本的,但我一直坚持这一段时间了。删除观察
我想从数据集hitters.txt
删除观察-Steven Sax
:
> dput(hitters[280:290,])
structure(list(AtBat = c(439L, 453L, 528L, 633L, 16L, 562L, 281L,
593L, 687L, 368L, 263L), Hits = c(96L, 103L, 122L, 210L, 2L,
169L, 76L, 152L, 213L, 103L, 70L), HmRun = c(0L, 8L, 1L, 6L,
0L, 17L, 3L, 23L, 10L, 3L, 1L), Runs = c(44L, 53L, 67L, 91L,
1L, 88L, 42L, 69L, 91L, 48L, 26L), RBI = c(36L, 33L, 45L, 56L,
0L, 73L, 25L, 75L, 65L, 28L, 23L), Walks = c(65L, 52L, 51L, 59L,
0L, 53L, 20L, 53L, 27L, 54L, 30L), Years = c(4L, 2L, 4L, 6L,
2L, 8L, 8L, 6L, 4L, 8L, 4L), CAtBat = c(711L, 507L, 1716L, 3070L,
28L, 3181L, 2658L, 2765L, 1518L, 1897L, 888L), CHits = c(148L,
123L, 403L, 872L, 4L, 841L, 657L, 686L, 448L, 493L, 220L), CHmRun = c(1L,
8L, 12L, 19L, 0L, 61L, 48L, 133L, 15L, 9L, 9L), CRuns = c(68L,
63L, 211L, 420L, 1L, 450L, 324L, 369L, 196L, 207L, 83L), CRBI = c(56L,
39L, 146L, 230L, 0L, 342L, 300L, 384L, 137L, 162L, 82L), CWalks = c(99L,
58L, 155L, 274L, 0L, 373L, 179L, 321L, 89L, 198L, 86L), League = structure(c(2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L), .Label = c("A", "N"), class = "factor"),
Division = structure(c(1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L,
2L, 1L), .Label = c("E", "W"), class = "factor"), PutOuts = c(229L,
289L, 209L, 367L, 247L, 351L, 106L, 315L, 294L, 209L, 81L
), Assists = c(406L, 407L, 372L, 432L, 4L, 442L, 144L, 10L,
445L, 246L, 147L), Errors = c(22L, 6L, 17L, 16L, 8L, 17L,
7L, 6L, 13L, 3L, 4L), Salary = c(150, 105, 350, 90, NA, 530,
341.667, 940, 350, 326.667, 250), NewLeague = structure(c(2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L), .Label = c("A",
"N"), class = "factor")), .Names = c("AtBat", "Hits", "HmRun",
"Runs", "RBI", "Walks", "Years", "CAtBat", "CHits", "CHmRun",
"CRuns", "CRBI", "CWalks", "League", "Division", "PutOuts", "Assists",
"Errors", "Salary", "NewLeague"), row.names = c("-Steve Jeltz",
"-Steve Lombardozzi", "-Spike Owen", "-Steve Sax", "-Tony Armas",
"-Tony Bernazard", "-Tom Brookens", "-Tom Brunansky", "-Tony Fernandez",
"-Tim Flannery", "-Tom Foley"), class = "data.frame")
如果我知道我会用第一列的名称:
hitters <- hitters[!hitters$Colname == "-Steve Sax",]
或
hitters <- hitters[hitters$AtBat != "-Steve Sax", ]
但我不k现在第一列的名称:
。我曾尝试:read.table("hitters.txt", head = F)
`和
read.table("hitters.txt", head = F)
我的问题是:
- 我怎样才能取出观察?
- 为什么
head = T
没有用?
你可以使用'名(打者)列的名字' – G5W
可以调用第一列'打者[,1]'如果你不知道这个名字。尽管如此,你能告诉我们“打击者”对象的类别,它的尺寸和打印“头部(打击者)”给你的东西吗? – R18
@Danke不要把'head'函数与'header'参数混淆。你应该把'header = T'放在第一位。 – Smich7