我是R和机器学习算法的新手,并试图使用kaggle scikit example来学习。从一个数据帧中添加列作为另一个数据帧的最后一列
我有以下两个数据帧:
> str(d.train)
'data.frame': 1000 obs. of 40 variables:
$ V1 : num 0.299 -1.174 1.192 1.573 -0.613 ...
> str(d.trainLabels)
'data.frame': 1000 obs. of 1 variable:
$ V1: int 1 0 0 1 0 1 0 1 1 0 ...
从我的理解,大多数布线工具是为了用相同的数据帧中的类信息使用。出于这个原因,我试图将trainLabels作为最后一列添加到列车数据框中。
我曾尝试下面的代码:
# http://www.gm.fh-koeln.de/~konen/WPF-DM-Cup/DM-Template/ClassifyTemplate/utils_DMC.r
######################################################################################
# bind the column with name response.predict and contents vec as last column
# to data frame d
######################################################################################
bind_response <- function(d,response.predict,vec)
{
# drop column response.predict if there, do nothing if not there
d <- d[,setdiff(names(d),response.predict)]
# bind column response.predict as last column to data frame d
d <- cbind(d, prediction=vec)
names(d)[names(d)=="prediction"] <- response.predict
return(d)
}
d.totalTrain <- bind_response(d.train, d.trainLabels, "1")
,但我不知道结果是什么,我想:
> str(d.totalTrain)
'data.frame': 1000 obs. of 41 variables:
...
$ V40 : num 0.101 -1.818 2.987 1.883 0.408 ...
$ c(1, 0, 0, 1, 0, 1, 0, 1, ...
*你想要什么结果? –
我想要的是:$ V41:int 1 0 0 1 0 1 0 1 1 0 ... – tucson