문제

data(kyphosis)
ky<- kyphosis

By this I made a data set consisting of 40% of original one.

ky_40 <- ky[sample(1:nrow(ky), nrow(ky)*0.4,replace=FALSE),] 

By this statement I want to make a data set consisting of 60% of the original one excluding

ky_40.
ky_the_others<- ???????  

How can I make the last code?

도움이 되었습니까?

해결책

Just move the sampling out of your extraction so you can refer to it again:

ky <- mtcars

## Here, I've moved the sampling out of your extraction
forty <- sample(1:nrow(ky), nrow(ky)*0.4,replace=FALSE)

## Now you can extract whatever you want
ky[ forty, ]    # This will be the 40% of original dataset
ky[-forty, ]    # This will be the remaining rows.

다른 팁

unique(rbind(ky_40,ky))[-(1:nrow(ky_40)),]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top