Skip to content
Back to formatted view

Raw Message

Message-ID: <31FFF4A6-2FB1-4965-875A-B7D631C7BE52@mac.com>
Date: 2012-12-02T04:04:11Z
From: Brian Feeny
Subject: How to re-combine values based on an index?

I am able to split my df into two like so:

dataset <- trainset
index <- 1:nrow(dataset)
testindex <- sample(index, trunc(length(index)*30/100))
trainset <- dataset[-testindex,]
testset <- dataset[testindex,-1]

So I have the index information, how could I re-combine the data using that back into a single df?

I tried what I thought might work, but failed with:

newdataset[testindex] = testset[testindex]
  object 'dataset' not found
newdataset[-testindex] = trainset[-testindex]
  object 'dataset' not found

Brian