在以下脚本中:
dataset <- read.csv("/home/adam/Desktop/Temp/lrtest.csv")
for(i in 3:ncol(dataset)){
uq <- unique(dataset[,i])
j <- i * 100
for(x in uq){
dataset[,i][dataset[,i] == x] <- j #dataset$nm[dataset$nm == x] <- j
j <- j + 1
}
}
我想遍历每一列,并将其每个String值替换为数字。问题是替换NA中的值(第6行)结果,看一下输出。
我该如何解决?
数据:
Class Branch LA_type Method_type Method_call Branch_type Branch_condition Tested_parameter
Goal 12 Smooth public static never called IFNE TRUE String
TreeApp 20 Rugged constructor none IF_ICMPGE FALSE int
Password 4 Smooth private never called IFEQ FALSE int
XMLParser 9 Rugged constructor none IFNONNULL TRUE String
MapClass 33 Smooth public never called IFGT FALSE double
输出:
Class Branch LA_type Method_type Method_call Branch_type Branch_condition Tested_parameter
1 Goal 12 <NA> <NA> <NA> <NA> 700 <NA>
2 TreeApp 20 <NA> <NA> <NA> <NA> 701 <NA>
3 Password 4 <NA> <NA> <NA> <NA> 701 <NA>
4 XMLParser 9 <NA> <NA> <NA> <NA> 700 <NA>
5 MapClass 33 <NA> <NA> <NA> <NA> 701 <NA>
答案 0 :(得分:2)
我们可以使用var modalModificationSeuil =
{
backdrop : 'static',
keyboard : true,
size: 'lg',
templateUrl : "templates/modification-threshold/modification.threshold.view.html",
controller : [
'$scope',
'$rootScope',
'$uibModalInstance',
'items',
'parameters',
function($scope, $rootScope, $uibModalInstance, items, parameters)
{
$scope.endDateOptions = {};
$scope.popup1 = { opened: false};
$scope.parameters = parameters;
$scope.disabled=true;
$scope.parametersChanged = new Object();
$scope.statusMessage = {
message : undefined,
isOpen : false,
templateUrl : 'templates/status.message.template.html'
};
var filterChanged = false;
$scope.items = traiterItems(items);
$scope.createDatePickerModel = function(items)
{
for (var a in items)
{
if (items[a].value.editorType == 'DATEPICKER')
{
$scope.datepicker = new Object();
$scope.datepicker[items[a].value.id] = items[a].value._value;
}
}
}
$scope.createDatePickerModel($scope.items);
}
],
resolve:
{
items : function ()
{
return service.items;
},
parameters : function ()
{
return service.parameters;
}
}
};
遍历第3列到数据帧的末尾,将数据转换为具有唯一级别的(可能已经存在),并增加100的顺序。
lapply
数据
factor