Removing specific rows from a dataset

I have a dataset with 40 columns of 100,000 rows. Since the number of columns is large, I want to remove some of them. I want to remove rows from 10.000-20.000; from 30.000-40.000 and from 60.000-70.000; so I have as a result a dataset with 40 columns with 70,000 rows. The first column - the identifier begins with 1 (called ItemID) and ends with 100,000 for the last. Can someone please help me.

I tried this to remove columns from 10,000 to 20,000, but it does not work (let the data set be called "Data"):

Data <- Data[Data$ItemID>10000 && Data$ItemID<20000]
+4
source share
2 answers

Hard ways to do it. Does something like this fit your needs?

dat <- data.frame(ItemID=1:100, x=rnorm(100))

# via row numbers
ind <- c(10:20,30:40,60:70)
dat <- dat[-ind,]

# via logical vector
ind <- with(dat, { (ItemID >= 10 & ItemID <= 20) |
                   (ItemID >= 30 & ItemID <= 40) |
                   (ItemID >= 60 & ItemID <= 70) })
dat2 <- dat[!ind,]

, ind (, ).

+2

,

data <- data[-(10000:20000),]

.

+1

Source: https://habr.com/ru/post/1599593/


All Articles