2011-10-27 3 views
29

저는 R을 한동안 사용 해왔고 data.frame에 포함 된 설명 데이터를 첨부 할 수 있다면 많은 도움이 될 것임을 깨달았습니다. 유용한 연구 정보를 .Rdata 파일에 모을 수 있기 때문입니다.R의 data.frame에 문서를 추가하는 방법은 무엇입니까?

나는?에 의해 표시되는 것과 같은 내 dataframe 정보에 추가 할 내가 할 수있는 방법을 찾을 수 없습니다 그러나 (조리개 dataframe의 데이터를 설명하는) 조리개

.

attr(df,"doc") = "This is my documentation" 

이런 일들은 대부분 n 개의 서브 세트를 슬라이스로 유지되지만 일부 프로세스는 그들을 떨어집니다 :

+1

여기 제공된 답변을 참조하여 data.frames도 똑같이 작동해야합니다. http://stackoverflow.com/questions/6324568/function-commenting-conventions-in-r/ 6324618 # 6324618 – Chase

답변

19

당신은 임의의 속성으로 추가 할 수 있습니다. 그러한 것이 가치 전달 시스템의 성격입니다.

심지어 일부 래퍼 함수 속성과 같은보다 복잡한 메타 데이터에 대한 CRAN에서 패키지가있을 수 있지만, 그 아래에 모든 속성 ...

23

@Spacedman는 이런 종류의 좋은 일반적인 대답이있다.

좀 더 애호가가 있다면 comment()을 사용해보세요. Hmisc 패키지의에서

comment(iris) <- 
"  This famous (Fisher's or Anderson's) iris data set gives the 
measurements in centimeters of the variables sepal length and 
width and petal length and width, respectively, for 50 flowers 
from each of 3 species of iris. The species are _Iris setosa_, 
_versicolor_, and _virginica_.\n" 

cat(comment(iris)) 
# This famous (Fisher's or Anderson's) iris data set gives the 
# measurements in centimeters of the variables sepal length and 
# width and petal length and width, respectively, for 50 flowers 
# from each of 3 species of iris. The species are _Iris setosa_, 
# _versicolor_, and _virginica_. 

label()units()는 data.frames에서 개별 열을 문서화하는 메커니즘을 제공합니다. contents()은 동일한 패키지에서 data.frame에 첨부 한 속성 중 하나를 요약합니다.

+0

'comment'는'Hmisc'가 아니라'base' 패키지에 있습니다. –

+1

@ 리치 코튼 - 지적 해 주셔서 고맙습니다. 나는 '주석'이'Hmisc'를 첨부 한 후에 항상 사용할 수 있기 때문에'Hmisc'에 의해 제공된다는 것을 추정하는 것이 공평하지 않다고 생각합니다;) –

2

또 다른 가능성은 두 개의 필드로 정식 클래스 (S4, 참조 클래스)의 객체로 DF를 설정하는 것입니다 - "데이터"(당신의 DF)와 "정보"(설명과 함께 문자열)

? setRefClass를 참조하십시오. 예를 들어

관련 문제