4 개의 열이있는 데이터 프레임을 다시 포맷하려고합니다. 그러나 하나의 열 (dem_profile_description)에는 ~ 20 개의 변수가 있으며 열로 변경하려고합니다. 나는 모양 패키지를 다운로드했다. 그러나 나는이와 끝까지r에 reshape를 사용하여 열 값을 열로 전환하는 방법은 무엇입니까?
library(reshape2)
census3 <- dcast(census2, "dem_profile_field" + "Community" ~
"dem_profile_description", value.var = "dem_profile_data")
:
이dem_profile_field Community (1) (2) (3) (4) (5) (6)
dpsf0010042 Gnar 4
dpsf0010043 Yoke 20
dpsf0010044 Law 5 5
dpsf0010046 Ark 24
dpsf0010047 Riverland 30
내 코드는 이것이다 :
dem_profile_field dem_profile_description dem_profile_data Community
dpsf0010042 Female 10 to 14 years(1) 4 Gnar
dpsf0010043 Female 15 to 19 years(2) 20 Yoke
dpsf0010044 Female 20 to 24 years(3) 22 Law
dpsf0010045 Female 25 to 29 years(4) 23 Law
dpsf0010046 Female 30 to 34 years(5) 24 Ark
dpsf0010047 Female 35 to 39 years(6) 30 Riverland
내가이 원하는 :
내 dataframe의 처음 몇 줄
이있다 :dem_profile_field Community dem_profile_description
1 Community 2
처럼 작동까요? –
@ 42-이 오류가 발생합니다 : % 이름 (데이터)의 value.var %의 오류 : 'dem_profile_data'객체가 없습니다. –
왜 행 4에 5가 2 개 있습니까? –