1

Please, I need some help I am new in R and I am unable to analyze my data. I used this code:

Paises <- read.csv("~/Desktop/UN/Paises.csv") View(Paises)

```{R}
Datos = read.table("~/Desktop/UN/Paises.csv", header=T, sep="," , dec=".") 
str(Datos)

Then I do not know how to sum all 2010 or all 2020 I tried with colSums but it was not possible. I want to know the total population in 2010 and also know the total in 2010 from different regions or even different countries

enter image description here

Daniela
  • 13
  • 3
  • Hello daniela, please always provide a minimal reproducible example in terms of code (no screenshots), as that makes it easier for people to help you : ) – finnmglas Oct 18 '20 at 22:50
  • Thank you finnmglas – Daniela Oct 18 '20 at 22:59
  • The line `install.packages(usingR)` doesn't make sense. Any package name you wish to install needs to be in quotes, and there is no package of that name on CRAN. – Phil Oct 19 '20 at 00:25

1 Answers1

1

Never use attach. Read Why is it not advisable to use attach() in R, and what should I use instead?

Your title and description of problem (unable to analyse my data) is very vague. You need to tell what exactly you are trying to do. From your code attempt it seems you are trying to sum column 2010. However, from the screenshot I also see that you have spaces in numbers indicating that your columns is of type character (check sapply(datos, class)). We cannot take sum of character values so first turn the column values to numeric.

Datos[-c(1:2)] <- lapply(Datos[-c(1:2)], as.numeric)

Now if you want to sum X2010 column you can do :

sum_2010 <- sum(Datos$X2010, na.rm = TRUE)
sum_2010

and if you want to sum all the numeric columns you can use colSums :

sum_All <- colSums(Datos[-c(1:2)], na.rm = TRUE)
sum_All
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213