将字符元素添加到数值矩阵

时间:2019-01-10 18:33:07

标签: r function matrix character

我在<script > var myApp = angular.module('myApp', []); myApp.controller('studentController', ['$scope', '$http', function($scope, $http) { $scope.searchitem = ''; // set the default search/filter term $scope.users = []; //Get List $http({ method: 'GET', url: 'serve-products.php' }).then(function successCallback(response) { $scope.users = response.data;}, function errorCallback(response) { alert("Error. Try Again!"); }); //Update list $scope.refreshUser = function(user) { $http({ method: 'GET', url: 'serve-products.php?d=' + user.code }).then(function successCallback(response) { $scope.users = response.data;}, function errorCallback(response) { alert("Error. Try Again!"); }); }; }]); </script> <body class="container" ng-app="myApp" ng-controller="studentController" > <form> <div class="form-group"> <div class="input-group"> <input type="text" class="form-control" placeholder="Search" ng-model="searchitem" > </div> </div> </form> <table class="table table-condensed table-striped"> <thead> <tr> <td>ID</td> <td>Name</td> <td>Stock</td> </tr> </thead> <tbody> <tr ng-repeat="user in users | filter:searchitem "> <td> {{user.code}} </td> <td> {{user.name}} </td> <td> <span ng-class="{'st0': user.stocktext == 'OUT OF STOCK'}"> {{user.stocktext}} </span></td> <td> <span ng-repeat="(key,value) in user.stock"> <span class="st{{value}}">{{key}}</span> </span> </td> <td> <button class="btn btn-primary btn-sm" ng-click="refreshUser(user)">Refresh</button> </td> </tr> </tbody> </table> </body> 中有一个2 x 30的矩阵,由1和2组成。我想知道如何在矩阵的每个元素之前添加一个额外的R

例如"p:",依此类推。

这是我尝试没有成功的事情:

p1: 1, p2: 2, p3: 1, p4: 2

2 个答案:

答案 0 :(得分:2)

我们用序列paste'p',然后用paste'a'matrix并将输出分配回'a'

a[] <- paste(paste0("p", 1:30), a, sep=": ")

答案 1 :(得分:0)

使用套用的另一种方法:

ReadableStream<string>