Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 删除行时已删除索引标签,是否修复此问题?_R_Indexing_Row_Rows_Delete Row - Fatal编程技术网

R 删除行时已删除索引标签,是否修复此问题?

R 删除行时已删除索引标签,是否修复此问题?,r,indexing,row,rows,delete-row,R,Indexing,Row,Rows,Delete Row,我从我的R数据框中删除了行,现在索引号出现了错误。例如,行索引以前是1,2,3,4,5,但现在是2,3,4,因为我删除了行1和行5 是否要将新数据帧上的索引标签从2,3,4更改为1,2,3 如果是,我该怎么做? 若否,原因为何 library(rvest) url <- "https://en.wikipedia.org/wiki/Mid-American_Conference" pg <- read_html(url) # Download webpage pg tb <

我从我的R数据框中删除了行,现在索引号出现了错误。例如,行索引以前是1,2,3,4,5,但现在是2,3,4,因为我删除了行1和行5

是否要将新数据帧上的索引标签从2,3,4更改为1,2,3

如果是,我该怎么做? 若否,原因为何

library(rvest)

url <- "https://en.wikipedia.org/wiki/Mid-American_Conference"
pg <- read_html(url) # Download webpage
pg

tb <- html_table(pg, fill = TRUE) # Extract HTML tables as data frames
tb

macdf <- tb[[2]]


macdf <- subset(macdf, select=c(1,2,5))


colnames(macdf) <- c("School","Location","NumStudent")


macdf <- macdf[-c(1,8),]
库(rvest)

url您可以这样做-

> library(data.table)
> subset(setDT(macdf,row.names),select=-rn)


rownames(macdf)您可以这样做-

> library(data.table)
> subset(setDT(macdf,row.names),select=-rn)


rownames(macdf)您可以使用以下方法将标签从
“2”“3”“4”“5”“6”“7”“9”“10”“11”“12”“13”“14”更改为
“1”“2”“3”“4”“5”“6”“7”“8”“9”“10”“11”“12”

行名称(macdf)您可以使用以下方法将标签从
的“2”“3”“4”“5”“6”“7”“9”“10”“11”“12”“13”“14”更改为
“1”“2”“3”“4”“5”“6”“7”“8”“9”“10”“12”
行名称(macdf)