[R] How to re-combine values based on an index?

William Dunlap wdunlap at tibco.com
Sun Dec 2 05:34:12 CET 2012


> newdataset[testindex] = testset[testindex]
>   object 'dataset' not found

Is that really what R printed?  I get
  > newdataset[testindex] = testset[testindex]
  Error in newdataset[testindex] = testset[testindex] : 
    object 'newdataset' not found
but perhaps you have a different problem.  Copy and paste
(and read) the error message you got.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Brian Feeny
> Sent: Saturday, December 01, 2012 8:04 PM
> To: r-help at r-project.org
> Subject: [R] 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
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list