rdata

Extracting specific data from an RData file

夙愿已清 提交于 2019-12-13 02:36:44
问题 I ask to be excused for my ignorance of R which I have been learning for the past one month. Specifically I have downloaded xxx_adm-_RData files (xxx for the country and - being 0, 1 or 2) for a number of countries of interest. My real interest are just the long/lat coordinates of each country, which I can use to overlay on analyses of climate fields like rainfall, temperature, etc. For the past two weeks I have been going through SO posts on how I can access a country's coordinates in an

Combine different elements of the same list in different R workspaces

爱⌒轻易说出口 提交于 2019-12-12 03:25:33
问题 For example: Three R workspaces A.RData , B.RData and C.RData . In A.RData : A list object list.example <- list(1,2) In B.RData : The same name list object list.example <- list(NULL,NULL,3) In C.RData : The same name list object list.example <- list(NULL,NULL,NULL,4) What i want to get in a new workspace is an object list.new.example printed as: [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 4 I have tried file.full <- list.files(directory, full.names = TRUE) list.new.example <- list() for (i

How to append a vector as a row in a saved .RData file with R

你说的曾经没有我的故事 提交于 2019-12-11 09:44:04
问题 The question a bit self explanatory but I should add that I do not want to load the file. I'm looking for something like append = TRUE for saving a .RData file . I want to do something like this: save(df, file="mtcars.Rda",append = TRUE) Here is a reproducible example: # load data data("mtcars") head(mtcars) # save original DF save(mtcars, file="mtcars.Rdata") # create another DF df <- mtcars # append DF to a saved Rdata file save(df, file="mtcars.Rdata",append = TRUE) Error in save(df, file

Get specific object from Rdata file

时光毁灭记忆、已成空白 提交于 2019-12-11 07:14:50
问题 I have a Rdata file containing various objects: New.Rdata |_ Object 1 (e.g. data.frame) |_ Object 2 (e.g. matrix) |_... |_ Object n Of course I can load the data frame with load('New.Rdata') , however, is there a smart way to load only one specific object out of this file and discard the others? 回答1: .RData files don't have an index (the contents are serialized as one big pairlist). You could hack a way to go through the pairlist and assign only entries you like, but it's not easy since you

How to solve issue loading large Rdata file which is actually a bit smaller than RAM?

坚强是说给别人听的谎言 提交于 2019-12-11 07:07:42
问题 I have a large *.Rdata file of size 15 Gb (15'284'533'248 Bytes) created in RStudio on a MacBook Pro with 8 Gb RAM, containing several lists of dataframes. Now I want to load() the file into RStudio on my PC with 32 Gb RAM, but only the RAM swells beyond all measure and at the end I get this: Error: cannot allocate vector of size 78 Kb The comic is, when I reload it on the Mac it works totally fine. What's going wrong? [Edit1] RStudio 1.0.136 on Mac, RStudio 1.1.383 on PC. Both R 3.4.2.

Updating an existing Rdata file

跟風遠走 提交于 2019-12-03 04:55:57
问题 I have found myself in the position of needing to update one or two data objects in an Rdata file previously created using save . If I'm not careful to load the file I can forget to re-save some objects in the file. As an example, I'm working on a package with some objects stored in sysdata.rda (look-up tables for internal use which I do not want to export) and only want to worry about updating individual objects. I haven't managed to work out if there is a standard way to do this, so created

Updating an existing Rdata file

荒凉一梦 提交于 2019-12-02 18:14:11
I have found myself in the position of needing to update one or two data objects in an Rdata file previously created using save . If I'm not careful to load the file I can forget to re-save some objects in the file. As an example, I'm working on a package with some objects stored in sysdata.rda (look-up tables for internal use which I do not want to export) and only want to worry about updating individual objects. I haven't managed to work out if there is a standard way to do this, so created my own function. resave <- function (..., list = character(), file = stop("'file' must be specified"))

Converting Rdata files to CSV - Error in data.frame arguments imply differing number of rows

谁都会走 提交于 2019-12-01 12:13:19
I'm trying to use the R code from this answer to convert a bunch of rdata files to CSV. resave <- function(file){ e <- new.env(parent = emptyenv()) load(file, envir = e) objs <- ls(envir = e, all.names = TRUE) for(obj in objs) { .x <- get(obj, envir =e) message(sprintf('Saving %s as %s.csv', obj,obj) ) write.csv(.x, file = paste0(obj, '.csv')) } } resave('yourData.RData') However on one of the files I'm getting this error: Error in data.frame(`2` = list(pos = c(6506L, 6601L, 21801L, 21811L, 21902L, : arguments imply differing number of rows: 7670, 9729, 114, 2422 Calls: resave ... as.data

Turning RData file into script files

一世执手 提交于 2019-11-30 05:12:37
Is there a straightforward way to turn the functions of a .RData file into a normal code file (.R)? Check out ?dump . For example: newEnv <- new.env() load("myFunctions.Rdata", newEnv) dump(c(lsf.str(newEnv)), file="normalCodeFile.R", envir=newEnv) You may also be interested in ?prompt (which creates documentation files for objects) and / or ?package.skeleton . This recent blog post addresses a basically the same problem: http://www.r-statistics.com/2010/09/dumping-functions-from-the-global-environment-into-an-r-script-file/ DeadlyStorm There's another solution from another post using sink

Saving a single object within a function in R: RData file size is very large

一世执手 提交于 2019-11-29 23:55:45
问题 I am trying to save trimmed-down GLM objects in R (i.e. with all the "non-essential" characteristics set to NULL e.g. residuals, prior.weights, qr$qr). As an example, looking at the smallest object that I need to do this with: print(object.size(glmObject)) 168992 bytes save(glmObject, "FileName.RData") Assigning this object in the global environment and saving leads to an RData file of about 6KB. However, I effectively need to create and save the glm object within a function, which is in