Add rows and columns in R

-1

Good morning,

I have been using the R for quite some time and have learned in practice. Now I came across a difficulty with a table. How can I sum all the rows of certain columns and display the result in a new column?

In case my initial table has six columns that will be summed in two three-column blocks. Example: Technology Contracts, Computer Program and Industrial Design. But I wanted the results by countries that are separated by lines, in a new column that will be Technological Production.

An example of the worksheet I'm working on: link

    
asked by anonymous 19.01.2018 / 07:26

1 answer

1

Assuming that Produção Tecnologica = CONTRATOS DE TECNOLOGIA + DESENHO NDUSTRIAL + PROGRAMA DE COMPUTADOR and Registros = INDICAÇÃO GEOGRÁFICA + MARCA + PATENTE . Using the basic package of R just use the code below. The code is not pretty or sophisticated, but it is basic and easy to understand. The $ operator is used to access the columns of a data.frame and R automatically adds the rows of their corresponding positions.

base.dados <- read.delim2("clipboard", as.is = T)

base.dados$PRODUCAOTENCOLOGIA <- base.dados$CONTRATOS.DE.TECNOLOGIA + base.dados$DESENHO.INDUSTRIAL + base.dados$PROGRAMA.DE.COMPUTADOR

base.dados$REGISTRO <- base.dados$INDICAÇÃO.GEOGRÁFICA + base.dados$MARCA + base.dados$PATENTE

Just to register I used the command read.delim2 , because I gave ctrl+c to the base you sent via Google Docs.

    
19.01.2018 / 11:58