Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have 18 years TRMM daily rainfall data (6573 .nc4 files). I need to combine all those .nc4 files into one and to organize them as a time series data for any specific location. How can I get rid of this?
I have tried nccopy, cdo, free netCDF extractor is not support these operation. I am a new researcher.
I would suggest to do this with python and xarray. It is very easy to build up a script doing this:
import xarray
from datetime import datetime
time_delta = datetime(2018, 1, 1)-datetime(2000, 1, 1)
list_of_file_names = [f"{day}.nc" for day in range(time_delta.days)]
all_data = xarray.open_mfdataset(list_of_file_names)
An alternative would be using cdo. You can find an example here example
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I know that there is a Python package that imports RData file.
But I was wondering if that is the best option for me.
I have Dataframes in R that I want to use in Python.
I was wondering if I should save this as json or csv and then read with pandas in Python, or I should just save it as RData and use the rpy2 package.
All I need is just turn these R dataframes into Python data frame, so I can manipulate and combine with other results I calculated in Python...
You can use feather.
It's a data format for data frames (created by #Wes McKinney and #hadley) to make data sharing between R and python easy (and some other languages too).
In R:
library(feather)
file_path <- "foo.feather"
data_frame <- read_feather(file_path)
write_feather(data_frame, file_path)
In python:
import feather
file_path = 'foo.feather'
data_frame = feather.read_dataframe(file_path)
feather.write_dataframe(data_frame, file_path)
PS.: Podcast on feather where authors discuss it's application, pros/cons and future.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm at the moment learning R from a fellow student. I have heard that it's possible to download data from Bloomberg and then, for example, calculate the Returns from Prices. Do I have to convert the data into a time series ?
An example would be great.
yes this is possible but you need be able access Bloomberg of course.
The code I'm using to download the data into R is:
start.date=as.Date('2016-01-04')
end.date= as.Date('2017-02-17')
opt = c("periodicitySelection"="DAILY")
blpConnect()
Bloombergdata=bdh(c("DAX Index", INDU Index"),"PX_LAST",start.date,end.date,options=opt,include.non.trading.days = TRUE)
After getting the data I transform this into time series with a function:
f.xts=function(dat.l){
out=as.xts(dat.l[,2],order.by=dat.l[,1])
return(out)}
out=na.locf(do.call("merge",lapply(data,f.xts)))
I hope this will help...
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm working on a project in R, regarding baseball. I have two CSV's that I'm working with. One file, CSV2: "PitchingPost.csv" is all postseason pitching stats, and the column I'm looking at there is the "teamID". I'm trying to evaluate regular season pitching stats in another file, CSV1: "pitching.csv" but only for teams that made the postseason. So I'm trying to remove all of the items in the "teamID" of CSV1 EXCEPT for those occur in CSV2 "teamID".
Help?
To keep only the rows from your first file that share an ID with rows in your second file, you could try something like that:
pitch <- read.csv("pitching.csv")
pitch_post <- read.csv("PitchingPost.csv")
pitch <- pitch[pitch$teamID %in% unique(pitch_post$teamID),]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an R dataset (an .Rdata file) that I need to convert to either SAS (.sas7bdat or .xpt) or SPSS (.sav or .por). How can I import this dataset into SAS or SPSS?
If you want to use this in SPSS, consider using the STATS_GETR extension command. It can read R workspace or data files and map appropriate elements directly to an SPSS dataset. This extension command is available from the SPSS Community (www.ibm.com/developerworks/spssdevcentral) website or, for Statistics 22, it can be installed via the Utilities menu.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have very big .csv file, it's around a few GB.
I want to read first few thousand lines of it.
Is there any method to do this efficiently?
Use the nrows argument in read.csv(...)
df <- read.csv(file="my.large.file.csv",nrows=2000)
There is also a skip= parameter that tells read.csv(...) how many lines to skip before you start reading.
If your file is that large you might be better off using fread(...) in the data.table package. Same arguments.
If you're on UNIX or OS/X, you can use the command line:
head -n 1000 myfile.csv > myfile.head.csv
Then just read it in R like normal.