title: Converting object to a Raster brick/Raster stack
body: <p>After using rasterToPoints to create the matrix, is it possible to have the new object return to the original Raster Stack/Raster Brick form? My object is called "avghist" and has 138 values/layers, but I would like this to become a Raster Stack/Brick for other use. This is how avghist was created:</p>
  
  <pre><code>data("wrld_simpl")
  b&lt;-wrld_simpl
  
  data("wrld_simpl")
  b&lt;-wrld_simpl
  
  landhist &lt;- mask(RCP1pctCO2Median,b)
  histnew&lt;-rasterToPoints(landhist)
  weighthist &lt;- cos(histnew[,"y"]*(pi/180))
  histnew[,3:ncol(histnew)] = apply(histnew[,3:ncol(histnew)], 2, function(x) x  
  * weighthist)
  avghist &lt;- colSums(histnew[,3:ncol(histnew)])/sum(weighthist)
  
  avghist
  
  
  head(avghist)
  
  layer.1  layer.2  layer.3  layer.4  layer.5  layer.6 
  
  52.75701 50.86984 49.91926 49.35157 52.78295 48.57297 
  </code></pre>
  
  <p>"landhist" was already a Raster Brick but was converted to a matrix using rasterToPoints to eventually obtain "avghist". landhist looks like this:</p>
  
  <pre><code>class       : RasterBrick 
  dimensions  : 64, 128, 8192, 138  (nrow, ncol, ncell, nlayers)
  resolution  : 2.8125, 2.789327  (x, y)
  extent      : -181.4062, 178.5938, -89.25846, 89.25846  (xmin, xmax, ymin, ymax)
  coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
  data source : in memory
  names       :   layer.1,   layer.2,   layer.3,   layer.4,   layer.5,   layer.6,   layer.7,     
  layer.8,   layer.9,  layer.10,  layer.11,  layer.12,  layer.13,  layer.14,  layer.15, ... 
  min values  :  52.88060,  54.93341,  55.79788,  54.18263,  53.85123,  55.68460,  50.17187,    
  49.60006,  55.21446,  62.36937,  56.81446,  64.73854,  54.57714,  55.34295,  59.67952, ... 
  max values  :  99.60231,  96.26976, 115.46164, 123.63807, 108.63827, 107.94791, 102.06677,   
  102.09359, 132.50890, 138.31932, 101.19222,  97.19884, 115.07969, 131.96504, 120.14971, ... 
  </code></pre>
  
  <p>To transform "avghist" into a rasterbrick, I attempted the following: </p>
  
  <pre><code>library(raster) 
  newly&lt;-rasterize(avghist) 
  </code></pre>
  
  <p>Doing this, however, I receive this error: </p>
  
  <pre><code>"Error in (function (classes, fdef, mtable) : unable to find an inherited method for function   ‘rasterize’ for signature ‘"numeric", "missing"’ 
  </code></pre>
  
  <p>Why would this error emerge? To my understanding, the rasterize function should change avghist into a raster brick or stack, no? </p>
  
  <p>This is what this as.raster(avghist/255) yields:</p>
  
  <p>newly&lt;-as.raster(avghist/255)</p>
  
  <pre><code>&gt; print(newly)
       [,1]     
  [1,] "#353535"
  [2,] "#333333"
  [3,] "#323232"
  [4,] "#313131"
  [5,] "#353535"
  [6,] "#313131"
  [7,] "#313131"
  [8,] "#333333"
  [9,] "#333333"
  [10,] "#303030"
  [11,] "#333333"
  [12,] "#363636"
  [13,] "#353535"
  [14,] "#363636"
  [15,] "#333333"
  [16,] "#353535"
  [17,] "#353535"
  [18,] "#353535"
  [19,] "#383838"
  [20,] "#343434"
  [21,] "#353535"
  [22,] "#353535"
  [23,] "#383838"
  [24,] "#383838"
  [25,] "#333333"
  [26,] "#373737"
  [27,] "#363636"
  [28,] "#353535"
  [29,] "#393939"
  [30,] "#343434"
  [31,] "#333333"
  [32,] "#343434"
  [33,] "#353535"
  [34,] "#373737"
  [35,] "#383838"
  [36,] "#3D3D3D"
  [37,] "#393939"
  [38,] "#373737"
  [39,] "#3C3C3C"
  [40,] "#353535"
  [41,] "#383838"
  [42,] "#3C3C3C"
  [43,] "#363636"
  [44,] "#363636"
  [45,] "#3B3B3B"
  [46,] "#3B3B3B"
  [47,] "#383838"
  [48,] "#373737"
  [49,] "#383838"
  [50,] "#343434"
  [51,] "#363636"
  [52,] "#393939"
  [53,] "#393939"
  [54,] "#3C3C3C"
  [55,] "#3D3D3D"
  [56,] "#383838"
  [57,] "#393939"
  [58,] "#3B3B3B"
  [59,] "#383838"
  [60,] "#383838"
  [61,] "#383838"
  [62,] "#3E3E3E"
  [63,] "#3B3B3B"
  [64,] "#3C3C3C"
  [65,] "#3E3E3E"
  [66,] "#404040"
  [67,] "#3F3F3F"
  [68,] "#393939"
  [69,] "#383838"
  [70,] "#383838"
  [71,] "#393939"
  [72,] "#3C3C3C"
  [73,] "#3F3F3F"
  [74,] "#3B3B3B"
  [75,] "#3E3E3E"
  [76,] "#3A3A3A"
  [77,] "#373737"
  [78,] "#3A3A3A"
  [79,] "#3E3E3E"
  [80,] "#3E3E3E"
  [81,] "#434343"
  [82,] "#393939"
  [83,] "#444444"
  [84,] "#454545"
  [85,] "#3C3C3C"
  [86,] "#404040"
  [87,] "#3E3E3E"
  [88,] "#444444"
  [89,] "#414141"
  [90,] "#444444"
  [91,] "#464646"
  [92,] "#3F3F3F"
  [93,] "#434343"
  [94,] "#424242"
  [95,] "#424242"
  [96,] "#404040"
  [97,] "#3C3C3C"
  [98,] "#454545"
  [99,] "#444444"
  [100,] "#414141"
  [101,] "#484848"
  [102,] "#454545"
  [103,] "#494949"
  [104,] "#434343"
  [105,] "#444444"
  [106,] "#464646"
  [107,] "#424242"
  [108,] "#464646"
  [109,] "#494949"
  [110,] "#414141"
  [111,] "#414141"
  [112,] "#454545"
  [113,] "#3E3E3E"
  [114,] "#4B4B4B"
  [115,] "#4A4A4A"
  [116,] "#424242"
  [117,] "#414141"
  [118,] "#484848"
  [119,] "#424242"
  [120,] "#474747"
  [121,] "#434343"
  [122,] "#444444"
  [123,] "#454545"
  [124,] "#3F3F3F"
  [125,] "#424242"
  [126,] "#474747"
  [127,] "#464646"
  [128,] "#414141"
  [129,] "#3E3E3E"
  [130,] "#474747"
  [131,] "#484848"
  [132,] "#414141"
  [133,] "#454545"
  [134,] "#474747"
  [135,] "#444444"
  [136,] "#4C4C4C"
  [137,] "#4F4F4F"
  [138,] "#494949"
  </code></pre>
  
  <p>Is this now is rasterize format?</p>
  
  <p>Thanks, and any help would be greatly appreciated!</p>