How can I load my Excel dataset into R [duplicate] - r

This question already has answers here:
Read an Excel file directly from a R script
(12 answers)
Closed 8 years ago.
I am doing a project about wind turbines where I test whether it is possible to heat a house only with energi from the wind turbine. So I made this R code. The code can predict the inside temperature. I have dataset in Excel that contains the outside temperature and windspeed every hour in january 2009.
R <- 5 This is the isolation of the wall
C <- 4 This is heat capacity of the wall
Ta <- rep(3,24) constant outside temperature in 24 hour
Ph <- rep(2,24) constant effect of the wind turbine in kW in 24 hour
Ti0 <- 20 This is the beginning temperature in the house
a <- -1/(R*C)
for(k in 2:24) {
Ti[k] <- Ta[k] + exp(a) * (Ti[k-1] - Ta[k]) + R * (1-exp(a)) * Ph[k]
}
My question is. How can I load my Excel dataset into R so R can predict the inside temperatur with changing temperature in 24 hour and changing effect in 24 hour, instead of holding these constant

Use this to load Excel data:
data = read.xls("excelfile.xls")
This will get the data from the first worksheet in your Excel file and save it in a dataset.
(Just make sure the file is in the working directory).
Just in case this doesn't work, try loading the gdata package before importing from the Excel file:
library(gdata)

Related

How can I convert vector to raster?

I am working on SDM project using Max-Ent, and Random Forest.
When I prepare tiff, or raster files of environmental data, I have difficulties, because of I’m a beginner.
For example: We have a csv file (1981_1991_ta_totalAverage.csv), which is contains average min temperature from 1981 to 1991.
Question 1: How can I convert this csv file to raster format?
I tried to convert it. When I need raster map of Korea, I used bclim6.asc (BIO6=Minimum Temperature of the Coldest Month for Korea. It seems something wrong. Question 2: How can I get taster file of Korea?

Subtracting a raster from a value in txt file in R

I am working with hourly air temperature raster maps for several months. I also have a .txt file with hourly air temperature values for each month. For each hour I want to calculate UHI:
UHI_1/1/2011_0am = raster - air temperature value (line 1 in .txt file)
UHI_1/1_2011_1am = raster - air temperature value (line 2 in .txt file)
And so on ....
How can I make this in R, instead of uploading each individual raster and calculate UHI individually at each hour?
This is my script, but this is very time consumming:
install.packages("raster")
install.packages("rgdal")
install.packages ("sp")
install.packages("xlsx")
library(raster)
library(rgdal)
library(sp)
library (xlsx)
setwd ("C:/Users/Claudia/Desktop/apr_2014")
apr_1 = raster ("apr__1.tif")
apr_2 = raster ("apr__2.tif")
dif_apr_1= abr_1 - 287.04
writeRaster(dif_apr_1,filename= "dif_apr_1",format="GTiff")
Is there an easier way to do this?

Is there a way to perform batch interpolation in ArcGIS from 1 excel file?

I have an excel file with station weather data. For each station, for each year (70 years), I have temperature data, as well as associated latitude and longitude of the stations. I want to create interpolated raster maps (using IDW) for each year for temperature.
My excel files are set up like this, but with 70 years of data:
I would therefore like 70 interpolated maps for each year of temperature. It also may be important to note that the stations for each year are not all the same.
I am willing to try to do this as a batch process in ArcGIS, but find that can be tedious. Is there a faster way to do this, through arcpy or even through R?

How to add dates to remote sensing data?

I am working with remote sensing data to create time series of NDVI and Cloud cover. The data consists of 30 rows (latitude) and 40 columns (Longitude) and 212 matrix slices which are the months from 2000-03 until 2017-10. How ever R sees the data as an array and there is no date visible in the data. Except that I know that the 212 matrix are the months. How can I add a date to the matrix slices but still have the latitude and longitude to work with?
When I use:
NDVI_timeserie <- ts(name.ts.ndvi, frequency=12, start=c(2000,3))
This gives the correct time to the data but then it is not saved as date. So when I want to select only the rain season, I can't because I can't select the months and years.
I am open to suggestions and advice of creating a time series.
Thank you so much!

Strange R random component

I'm relatively new to R so maybe I'm missing something but by my own I cannot figure it out.
I've this data-set: DOWNLOAD .TXT that contains sales data aggregated by week (51 weeks for 2 years leading to 102 entries).
This is the code I use to transform data in a timeserie, plot and then decompose in the main components
# creating a timeseries element, frequency sets the intervals of data collection, starts sets the data collection date
timeseries = ts(data, frequency = 51, start = c(2011))
plot.ts(timeseries, type = "o")
#TimeSeries decomposition in trend, seasonal and random-walk
plot(decompose(timeseries))
The result is a decompose figure very strange, especially for the random part.
These are my qustions:
Why the charts starts at 2011.5 when the data starts 2011.1?
Why the random component is so strange?
What I'm missing?

Resources