[R] Replace columns in a data.frame randomly splitted
R. Michael Weylandt
michael.weylandt at gmail.com
Wed Nov 30 17:58:00 CET 2011
Two ways immediately come to mind:
1) Change the values before splitting
2) Use the same seed for the two splits so the rows match exactly and
then just do the changes directly
Any more automated solution will depend on whether your data has
rownames or not.
PS - As a general rule, most folks don't like to download unknown xls
files -- it's much easier to create a plain text representation of R
data using the dput() command.
On Wed, Nov 30, 2011 at 8:15 AM, agent dunham <crosspide at hotmail.com> wrote:
> Dear community,
> I'm working with the data.frame attached (
> http://r.789695.n4.nabble.com/file/n4122926/df1.xls df1.xls ), let's call it
> I typed: df1<- read.xls("C:/... dir .../df1.xls",colNames= TRUE, rowNames=
> Then I splited randomly df1 using splitdf function
> So now, I have df1 divided in another 2 dataframes: trainset and testset.
> (They both have the same row names and column names as df1)
> I'd like to change df1$v1 and df1$v2 values in the trainset and testset by
> the ones in df2 ( http://r.789695.n4.nabble.com/file/n4122926/df2.xls
> df2.xls )
> How can I explain R to identify in trainset/testset$v1 and $v2 the rownames
> and replace the values by the corresponding ones in df2?
> Thanks in advance,
> user at host.com
> View this message in context: http://r.789695.n4.nabble.com/Replace-columns-in-a-data-frame-randomly-splitted-tp4122926p4122926.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> 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