0

I have uploaded a csv file, like the following:

datamap <- read.csv(file = "TheWorlds50BestRestaurants2018.csv", header = TRUE, sep = ",")

I want to put that dataset into a data frame. However, I have problems with the following sentence

mimapa <- data.frame(Year =         datamap$Year,Ranking = datamap$Ranking,
Name = datamap$Name, City = datamap$City, Country = datamap$Country,Latitude = datamap$Latitude,Longitude = c(datamap$Longitude))

The error is:

Error in data.frame(Year = datamap$Year, Ranking = datamap$Ranking, Name = c(datamap$Name),  : 
  arguments imply differing number of rows: 0, 50

Please help me with that error, Thank you.

M--
  • 25,431
  • 8
  • 61
  • 93
  • `read.csv()` returns a dataframe. No need to convert it to a dataframe again after reading! – 12b345b6b78 Oct 21 '18 at 02:36
  • The error probably appears because one of `datamap$Year`, `datamap$Ranking`, `datamap$Name`, ... does not exists in the data.frame `datamap`. Note that R is case sensitive. – Nairolf Oct 21 '18 at 03:19
  • Please provide a reproducible example. – Nairolf Oct 21 '18 at 03:21
  • Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Oct 21 '18 at 03:43

0 Answers0