title: How to converst a CSV into raster?
body: <p>I have a CSV (value, carbon, latitude, longitude) that I am trying to create a raster from. I am not able to change into raster. This code is not working.</p>
  <p>CSV file sample:</p>
  <p><a href="https://i.stack.imgur.com/rwrgY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rwrgY.png" alt="enter image description here" /></a></p>
  <pre><code>class       : SpatialPointsDataFrame 
  features    : 13135 
  extent      : 35, 37, 73, 76  (xmin, xmax, ymin, ymax)
  crs         : NA 
  variables   : 3
  names       : Carbon, Latitude, Longitude 
  min values  :      1,       35,        73 
  max values  :   5829,       37,        76 
  </code></pre>
  <p>R Script:</p>
  <pre><code>library(sp)  # vector data
  library(raster)  # raster data
  library(rgdal)  # input/output, projections
  library(rgeos)  # geometry ops
  library(spdep)  # spatial dependence
  
  foresta&lt;-carbonstock
  head(carbonstock)
  
  data&lt;-data.frame(carbonstock$Longitude,carbonstock$Latitude,carbonstock$Carbon)
  data&lt;-data.frame(carbonstock)
  
  # points from scratch
  
  coords = cbind(carbonstock$Latitude, carbonstock$Longitude)
  sp = SpatialPoints(coords)
  
  # make spatial data frame
  
  spdf = SpatialPointsDataFrame(coords, data)
  spdf = SpatialPointsDataFrame(sp, data)
  
  # promote data frame to spatial
  
  coordinates(data) = cbind(carbonstock$Latitude, carbonstock$Longitude)
  coordinates(data) = ~lon + lat
  
  # back to data
  
  as.data.frame(data)
  plot(data,)
  
  library(raster)
  </code></pre>