我有下表:
X.5 X.6 X.7 X.8 X.9 X.10 X.11 X.12 X.13
17 Zip CuCurrent PaCurrent PoCurrent Contact Ext Fax email Status
18 74136 0 1 0 918-491-6998 0 918-491-6659 1
19 30329 1 0 0 404-321-5711 1
20 74136 1 0 0 918-523-2516 0 918-523-2522 1
21 80203 0 1 0 303-864-1919 0 1
22 80120 1 0 0 345-098-8890 456 1
如何使第一行“ zip,cucurrent,pacurrent ...”成为列标题?
谢谢,
下边是 dput(dat)
dput(dat)structure(list(X.5 = structure(c(26L,14L,6L,14L,17L,16L),. Label = c(“”,“ 1104”,“ 1234我不知道Ave. ”,“ 139.98”,“ 300 Morgan St。”,“ 30329”,“ 312.95”,“ 4101 S. 4th Street,Traff”,“ 500 Highway 89 North”,“ 644.04”,“ 656.73”,“ 72160”, “ 72336-7000”,“ 74136”,“ 75501”,“ 80120”,“ 80203”,“ 877.87”,“ Address1”,“ BZip”,“ General Svcs Admin(WPY)”,“ InvFileName2”,“ LDC_Org_Cost” ,“ N / A”,“ NULL”,“ Zip”),class =“ factor”),X.6 =结构(c(7L,2L,3L,3L,2L,3L),.Label = c(“ ”,“ 0”,“ 1”,“ 301第七街”,“ 800-688-6160”, “ Address2”,“ CuCurrent”,“ Emergency”,“ LDC_Cost_Adj”,“ Metlemetry”,“ N / A”,“ NULL”,“ Suite 1402”),类=“ factor”),X.7 =结构(c (8L,3L,2L,2L,3L,2L),.Label = c(“”,“ 0”,“ 1”,“ Address3”,“ Cucustomer”,“ LDC_Misc_Fee”,“ NULL”,“ PaCurrent”, “ Room 7512”),class =“ factor”),X.8 = structure(c(14L,2L,2L,2L,2L,2L),.Label = c(“”,“ 0”,“ 100.98”, “ 237.02”,“ 242.33”,“ 335.04”,“ 50.6”,“城市”,“达勒姆”,“ LDC_FinalVolume”,“ Leavenwoth”,“ Pacustomer”,“ Petersburg”,“ PoCurrent”,“ Prescott”,“华盛顿”),class =“ factor”),X.9 = structure(c(18L,16L,10L,17L,7L,9L),.Label = c(“”,“ 0”,“ 1”,“ 139.98”, “ 20024”,“ 27701”,“ 303-864-1919”,“ 312.95”,“ 345-098-8890”,“ 404-321-5711”,“ 644.04”,“ 656.73”,“ 66048”,“ 86313” “,” 877.87“,” 918-491-6998“,” 918-523-2516“,”联系人“,” LDC_FinalCost“,” PoCustomer“,”邮编“),类=” factor“),X.10 =结构(c(14L,2L,1L,2L,2L,9L),.Label = c(“”,“ 0”,“ 2.620194604”,“ 2.710064788”,“ 2.717239052”,“ 2.766403162”,“ 202-708- 4995“,” 3.09912854“,” 456“,” 804-504-7200“,”913-682-2000”,“ 919-956-5541”,“ 928-717-7472”,“ Ext”,“需要发票”,“ LDC_UnitPrice”,“ NULL”,“ Phone”),类=“ factor”) ,X.11 = structure(c(7L,4L,1L,5L,1L,1L),.Label = c(“”,“”,“ 1067”,“ 918-491-6659”,“ 918-523- 2522”,“ Ext”,“ Fax”,“ InvoiceMonths”,“ LDC_UnitPrice_Original”,“ NULL”,“ x2951”),class =“ factor”),X.12 = structure(c(13L,1L,1L,1L ,1L,1L),.Label = c(“”,“ 0”,“ 100.98”,“ 202-401-3722”,“ 237.02”,“ 242.33”,“ 335.04”,“ 50.6”,“ 716-344 -3303“,” 804-504-7227“,” 913-758-4230“,” 919-956-7152“,”email“,” Fax“,” GSA“,” Supp_Vol“),class =” factor“),X.13 =结构(c(10L,2L,2L,2L,2L,2L)、. Label = c(” “,” 1“,” 15“,” 202-497-6164“,” 3“,” 804-504-7200“,”紧急情况“,” MajorTypeId“,” NULL“,”状态“,” Supp_Vol_Adj“) ,class =“ factor”)),.Names = c(“ X.5”,“ X.6”,“ X.7”,“ X.8”,“ X.9”,“ X.10”, “ X.11”,“ X.12”,“ X.13”),row.names = 17:22,class =“ data.frame”) “ 804-504-7200”,“紧急情况”,“ MajorTypeId”,“ NULL”,“状态”,“ Supp_Vol_Adj”),类=“ factor”))、. Names = c(“ X.5”,“ X .6”,“ X.7”,“ X.8”,“ X.9”,“ X.10”,“ X.11”,“ X.12”,“ X.13”),row.names = 17:22,类=“ data.frame”) “ 804-504-7200”,“紧急情况”,“ MajorTypeId”,“ NULL”,“状态”,“ Supp_Vol_Adj”),类=“ factor”))、. Names = c(“ X.5”,“ X .6”,“ X.7”,“ X.8”,“ X.9”,“ X.10”,“ X.11”,“ X.12”,“ X.13”),row.names = 17:22,类=“ data.frame”)
如果您不想将数据重新读到R中(看起来好像不是来自注释),则可以执行以下操作。我必须添加一些零以使您的数据完全读取,因此请忽略这些零。
dat
## V2 V3 V4 V5 V6 V7 V8 V9 V10
## 17 Zip CuCurrent PaCurrent PoCurrent Contact Ext Fax email Status
## 18 74136 0 1 0 918-491-6998 0 918-491-6659 0 1
## 19 30329 1 0 0 404-321-5711 0 0 0 1
## 20 74136 1 0 0 918-523-2516 0 918-523-2522 0 1
## 21 80203 0 1 0 303-864-1919 0 0 0 1
## 22 80120 1 0 0 345-098-8890 456 0 0 1
首先将第一行作为列名。接下来删除第一行。通过将列转换为适当的类型来完成此操作。
names(dat) <- as.matrix(dat[1, ])
dat <- dat[-1, ]
dat[] <- lapply(dat, function(x) type.convert(as.character(x)))
dat
## Zip CuCurrent PaCurrent PoCurrent Contact Ext Fax email Status
## 1 74136 0 1 0 918-491-6998 0 918-491-6659 0 1
## 2 30329 1 0 0 404-321-5711 0 0 0 1
## 3 74136 1 0 0 918-523-2516 0 918-523-2522 0 1
## 4 80203 0 1 0 303-864-1919 0 0 0 1
## 5 80120 1 0 0 345-098-8890 456 0 0 1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句