.RData에 데이터 파일을 저장하는 방법은 무엇입니까?
데이터를 .RData
파일 에 저장하고 싶습니다 .
예를 들어 1.RData
두 개의 csv 파일과 몇 가지 정보 로에 저장하고 싶습니다 .
여기에 두 개의 csv 파일이 있습니다.
1) file_1.csv contains object city[[1]]
2) file_2.csv contains object city[[2]]
추가로 다음과 같이 다른 값, 국가 및 인구를 저장합니다. 따라서 먼저 두 개의 csv 파일에서 '도시'객체를 만들어야한다고 생각합니다.
1. RData의 구조는 다음과 같습니다.
> data = load("1.RData")
> data
[1] "city" "country" "population"
> city
[[1]]
NEW YORK 1.1
SAN FRANCISCO 3.1
[[2]]
TEXAS 1.3
SEATTLE 1.4
> class(city)
[1] "list"
> country
[1] "east" "west" "north"
> class(country)
[1] "character"
> population
[1] 10 11 13 14
> class(population)
[1] "integer"
file_1.csv
및 file_2.csv
행과 열 무리가있다.
csv 파일 및 값으로 이러한 유형의 RData를 어떻게 만들 수 있습니까?
또는 개별 R 개체를 저장하려는 경우 saveRDS
.
를 사용하여 R 객체를 저장 한 다음를 사용하여 saveRDS
새 변수 이름으로 R에로드 할 수 있습니다 readRDS
.
예:
# Save the city object
saveRDS(city, "city.rds")
# ...
# Load the city object as city
city <- readRDS("city.rds")
# Or with a different name
city2 <- readRDS("city.rds")
But when you want to save many/all your objects in your workspace, use Manetheran's answer.
There are three ways to save objects from your R session:
Saving all objects in your R session:
The save.image()
function will save all objects currently in your R session:
save.image(file="1.RData")
These objects can then be loaded back into a new R session using the load()
function:
load(file="1.RData")
Saving some objects in your R session:
If you want to save some, but not all objects, you can use the save()
function:
save(city, country, file="1.RData")
Again, these can be reloaded into another R session using the load()
function:
load(file="1.RData")
Saving a single object
If you want to save a single object you can use the saveRDS()
function:
saveRDS(city, file="city.rds")
saveRDS(country, file="country.rds")
You can load these into your R session using the readRDS()
function, but you will need to assign the result into a the desired variable:
city <- readRDS("city.rds")
country <- readRDS("country.rds")
But this also means you can give these objects new variable names if needed (i.e. if those variables already exist in your new R session but contain different objects):
city_list <- readRDS("city.rds")
country_vector <- readRDS("country.rds")
Just to add an additional function should you need it. You can include a variable in the named location, for example a date identifier
date <- yyyymmdd
save(city, file=paste0("c:\\myuser\\somelocation\\",date,"_RData.Data")
This was you can always keep a check of when it was run
참고URL : https://stackoverflow.com/questions/19967478/how-to-save-data-file-into-rdata
'program tip' 카테고리의 다른 글
지연 로딩 vs Eager 로딩 (0) | 2020.12.01 |
---|---|
메이크 파일 디버깅 도구 (0) | 2020.12.01 |
Kotlin의 리소스에서 텍스트 파일을 읽는 방법은 무엇입니까? (0) | 2020.11.30 |
translatable =“false”인 strings.xml의 "여기에서 번역되었지만 기본 로케일에서 찾을 수 없음"오류 (0) | 2020.11.30 |
“Mapping architecture arm64 to x86_64”경고는 무엇을 의미합니까? (0) | 2020.11.30 |