请用R语言创建数据集 年龄 工作 FNLWGT 教育 教育数字 婚姻状况 职业 关系 种族 性别 资本收益 资本损失 每周小时数 原产国 income 39 State-gov 77516 Bachelors 13 Never-married Adm-clerical Not-in-family White Male 2174 0 40 United-States <=50K 50 Self-emp-not-inc 83311 Bachelors 13 Married-civ-spouse Exec-managerial Husband White Male 0 0 13 United-States <=50K 38 Private 215646 HS-grad 9 Divorced Handlers-cleaners Not-in-family White Male 0 0 40 United-States <=50K 53 Private 234721 11th 7 Married-civ-spouse Handlers-cleaners Husband Black Male 0 0 40 United-States <=50K 28 Private 338409 Bachelors 13 Married-civ-spouse Prof-specialty Wife Black Female 0 0 40 Cuba <=50K 37 Private 284582 Masters 14 Married-civ-spouse Exec-managerial Wife White Female 0 0 40 United-States <=50K 49 Private 160187 9th 5 Married-spouse-absent Other-service Not-in-family Black Female 0 0 16 Jamaica <=50K 52 Self-emp-not-inc 209642 HS-grad 9 Married-civ-spouse Exec-managerial Husband White Male 0 0 45 United-States >50K 31 Private 45781 Masters 14 Never-married Prof-specialty Not-in-family White Female 14084 0 50 United-States >50K 42 Private 159449 Bachelors 13 Married-civ-spouse Exec-managerial Husband White Male 5178 0 40 United-States >50K
时间: 2023-07-08 19:29:43 浏览: 86
2023年第三届长三角数学建模c题考试题目.zip
可以使用以下代码创建该数据集:
```R
# 创建数据框
data <- data.frame(
age = c(39, 50, 38, 53, 28, 37, 49, 52, 31, 42),
workclass = c("State-gov", "Self-emp-not-inc", "Private", "Private", "Private", "Private", "Private", "Self-emp-not-inc", "Private", "Private"),
fnlwgt = c(77516, 83311, 215646, 234721, 338409, 284582, 160187, 209642, 45781, 159449),
education = c("Bachelors", "Bachelors", "HS-grad", "11th", "Bachelors", "Masters", "9th", "HS-grad", "Masters", "Bachelors"),
education_num = c(13, 13, 9, 7, 13, 14, 5, 9, 14, 13),
marital_status = c("Never-married", "Married-civ-spouse", "Divorced", "Married-civ-spouse", "Married-civ-spouse", "Married-civ-spouse", "Married-spouse-absent", "Married-civ-spouse", "Never-married", "Married-civ-spouse"),
occupation = c("Adm-clerical", "Exec-managerial", "Handlers-cleaners", "Handlers-cleaners", "Prof-specialty", "Exec-managerial", "Other-service", "Exec-managerial", "Prof-specialty", "Exec-managerial"),
relationship = c("Not-in-family", "Husband", "Not-in-family", "Husband", "Wife", "Wife", "Not-in-family", "Husband", "Not-in-family", "Husband"),
race = c("White", "White", "White", "Black", "Black", "White", "Black", "White", "White", "White"),
sex = c("Male", "Male", "Male", "Male", "Female", "Female", "Female", "Male", "Female", "Male"),
capital_gain = c(2174, 0, 0, 0, 0, 0, 0, 0, 14084, 5178),
capital_loss = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
hours_per_week = c(40, 13, 40, 40, 40, 40, 16, 45, 50, 40),
native_country = c("United-States", "United-States", "United-States", "United-States", "Cuba", "United-States", "Jamaica", "United-States", "United-States", "United-States"),
income = c("<=50K", "<=50K", "<=50K", "<=50K", "<=50K", "<=50K", "<=50K", ">50K", ">50K", ">50K")
)
# 打印数据框
print(data)
```
请注意,此代码创建了一个名为data的数据框,其中包含了您提供的所有列。
阅读全文