0

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')

}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3408139
  • 197
  • 1
  • 12
  • are you trying to split the data set up according to one of its collumns? there are plenty of options for that. by far my favourite is `dplyr` – roman Oct 19 '16 at 14:03
  • `subset(Yield_CRD, CRD==10, select=-CRD)` but read http://stackoverflow.com/questions/9860090/why-is-better-than-subset – jogo Mar 23 '17 at 19:12

1 Answers1

0

It looks like you're just trying to grab a subset of rows and drop a column ( is that right?):

Results<-Yield_CRD[Yield_CRD$CRD==10,-YieldCRD$CRD]
John
  • 1,018
  • 12
  • 19