Add rows and columns in R

Asked

Viewed 2,736 times

-1

Good morning,

I have been using R for a short time and have been learning in practice. I have now come across a difficulty with a table. How can I add all rows of certain columns and display the result in a new column?

In the case my initial table has six columns that will be summed into two blocks of three columns. Example: Technology, Computer Program and Industrial Design Contracts. 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 spreadsheet I’m working on: https://docs.google.com/spreadsheets/d/1_HTtYC6h8ycXJO83jJiFRfWviqz-EOCHsytV0PtC2kU/edit?usp=sharing

  • To speed up the answer to your question always use a dput of your table on R and post here what comes out on your console.

1 answer

2


Assuming Produção Tecnologica = CONTRATOS DE TECNOLOGIA + DESENHO NDUSTRIAL + PROGRAMA DE COMPUTADOR and Registros = INDICAÇÃO GEOGRÁFICA + MARCA + PATENTE. Using the basic R package just use the code below. The code is not beautiful nor sophisticated, but it is basic and easy to understand. The operator $ serves to access the columns of a data.frame and R automatically sums the rows of its 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 one ctrl+c at the base you sent via Google Docs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.