I am a beginner to the R language and I need to achieve the following "Result" table using "Yield_CRD" table. Any help is appreciated.
I need to obtain the "Results" table below. How can I achieve this using r. Please help me.
Yield_CRD:
CRD YEAR Har_Ac Plant_Ac Har_Yield Plant_Yield
10 1951 1498300 1568100 39.5 37.7
10 1952 1551700 1589500 61.5 60
10 1953 1628200 1675200 55.1 53.6
10 1954 1451400 1504800 59.7 57.6
10 1955 1498100 1585700 46.3 43.7
10 1956 1214400 1532600 45.8 36.3
10 1957 1448900 1505500 58 55.8
10 1958 1483900 1567100 53.5 50.7
10 1959 1871400 1957900 58.3 55.7
10 1960 1855700 1945700 64.8 61.8
20 1951 1498300 1568100 49.5 47.7
20 1952 1551700 1589500 71.5 70
20 1953 1628200 1675200 65.1 63.6
20 1954 1451400 1504800 69.7 67.6
20 1955 1498100 1585700 56.3 53.7
20 1956 1214400 1532600 55.8 46.3
20 1957 1448900 1505500 68 65.8
20 1958 1483900 1567100 63.5 60.7
20 1959 1871400 1957900 68.3 65.7
20 1960 1855700 1945700 74.8 71.8
Now I need the "Results" table below:
For CRD (10):
Year HHar_Ac Plant_Ac Har_Yield Plant_Yield
1951 1498300 1568100 39.5 37.7
1951 1498300 1568100 39.5 37.7
1952 1551700 1589500 61.5 60
1953 1628200 1675200 55.1 53.6
1954 1451400 1504800 59.7 57.6
1955 1498100 1585700 46.3 43.7
1956 1214400 1532600 45.8 36.3
1957 1448900 1505500 58 55.8
1958 1483900 1567100 53.5 50.7
1959 1871400 1957900 58.3 55.7
1960 1855700 1945700 64.8 61.8
I have the following code but it does not work
flows <- list()
i <- which(YieldCRD[,1] == 20, arr.ind=TRUE)
t0 <- i[1]
tend <- i[length(i)]
for (j in t0:tend) {
flows <- t(as.numeric(YieldCRD[j,2:ncol(YieldCRD)]))
colnames(flows) <- c('Year','Harvest_Acres','Planted_Acres','Harvest_Yield','Planted_Yield')
}