我想删除名为" row.names。"的列。

时间:2014-09-30 13:28:25

标签: r

structure(list(age = c(33L, 21L, 37L, 29L, 45L), workclass = structure(c(4L, 
7L, 4L, 4L, 4L), .Label = c(" Federal-gov", " Local-gov", " Never-worked", 
" Private", " Self-emp-inc", " Self-emp-not-inc", " State-gov", 
" Without-pay"), class = "factor"), fnlwgt = c(319854L, 41183L, 
103323L, 176027L, 264526L), education = structure(c(10L, 16L, 
12L, 10L, 8L), .Label = c(" 10th", " 11th", " 12th", " 1st-4th", 
" 5th-6th", " 7th-8th", " 9th", " Assoc-acdm", " Assoc-voc", 
" Bachelors", " Doctorate", " HS-grad", " Masters", " Preschool", 
" Prof-school", " Some-college"), class = "factor"), education.num = c(13L, 
10L, 9L, 13L, 12L), marital.status = structure(c(6L, 5L, 5L, 
5L, 1L), .Label = c(" Divorced", " Married-AF-spouse", " Married-civ-spouse", 
" Married-spouse-absent", " Never-married", " Separated", " Widowed"
), class = "factor"), occupation = structure(c(10L, 10L, 3L, 
10L, 7L), .Label = c(" Adm-clerical", " Armed-Forces", " Craft-repair", 
" Exec-managerial", " Farming-fishing", " Handlers-cleaners", 
" Machine-op-inspct", " Other-service", " Priv-house-serv", " Prof-specialty", 
" Protective-serv", " Sales", " Tech-support", " Transport-moving"
), class = "factor"), relationship = structure(c(2L, 4L, 2L, 
2L, 4L), .Label = c(" Husband", " Not-in-family", " Other-relative", 
" Own-child", " Unmarried", " Wife"), class = "factor"), race = structure(c(5L, 
5L, 5L, 5L, 5L), .Label = c(" Amer-Indian-Eskimo", " Asian-Pac-Islander", 
" Black", " Other", " White"), class = "factor"), sex = structure(c(2L, 
1L, 2L, 1L, 2L), .Label = c(" Female", " Male"), class = "factor"), 
capital.gain = c(4650L, 0L, 0L, 0L, 0L), capital.loss = c(0L, 
0L, 0L, 0L, 0L), hours.per.week = c(35L, 20L, 40L, 40L, 40L
), native.country = structure(c(39L, 39L, 39L, 39L, 39L), .Label = c(" Cambodia", 
" Canada", " China", " Columbia", " Cuba", " Dominican-Republic", 
" Ecuador", " El-Salvador", " England", " France", " Germany", 
" Greece", " Guatemala", " Haiti", " Holand-Netherlands", 
" Honduras", " Hong", " Hungary", " India", " Iran", " Ireland", 
" Italy", " Jamaica", " Japan", " Laos", " Mexico", " Nicaragua", 
" Outlying-US(Guam-USVI-etc)", " Peru", " Philippines", " Poland", 
" Portugal", " Puerto-Rico", " Scotland", " South", " Taiwan", 
" Thailand", " Trinadad&Tobago", " United-States", " Vietnam", 
" Yugoslavia"), class = "factor"), RESULT = structure(c(1L, 
1L, 1L, 1L, 1L), .Label = c(" <=50K", " >50K"), class = "factor")), .Names = c("age", 
"workclass", "fnlwgt", "education", "education.num", "marital.status", 
"occupation", "relationship", "race", "sex", "capital.gain", 
"capital.loss", "hours.per.week", "native.country", "RESULT"), row.names = c(25231L, 
17952L, 24945L, 25524L, 11025L), class = "data.frame")

这是从原始数据“成人”中抽样的数据。     样本(1:nrow(成人),nrow(成人)* 0.4,替换= FALSE)

我上面做了样品。但问题是我有row.names。有时候有行名称真的不好,特别是当我需要使用回归时。

你能帮我吗?

1 个答案:

答案 0 :(得分:1)

假设您的数据框名称为test

数据集中没有列名称row.names:

> names(test)
[1] "age"            "workclass"      "fnlwgt"         "education"      "education.num"  "marital.status" "occupation"     "relationship"   "race"           "sex"           [11] "capital.gain"   "capital.loss"   "hours.per.week" "native.country" "RESULT"        

row.names是行的名称:

> row.names(test)
[1] "25231" "17952" "24945" "25524" "11025"

以下命令有效:

row.names(test)  <- NULL