0

I have been using this code multiple times, it worked two weeks ago as usual, but now, when I run the first line, R does not change the dataset I don't know why. As soon as I remove the pipe operator the dataset changes but I can't filter by region.

Covid19 <- read.csv("COVID19Cases_geoRegion.csv") %>%
    filter(geoRegion == "CH")

Cases    <- xts(Covid19[,3], order.by = as.Date(Covid19[,2]))

I also tried as follows but sill the same problem.

Covid19 <- read.csv("https://www.covid19.admin.ch/api/data/20220216-i4f5f0q1/sources/COVID19Hosp_geoRegion.csv") %>%
 filter(geoRegion == "CH")
Hospital    <- xts(Covid19[,3], order.by = as.Date(Covid19[,2]))

I try to install again the package dplyr and also I tried with magrittr but it is not working, does anyone know how to solve this problem?

Anoushiravan R
  • 21,622
  • 3
  • 18
  • 41

1 Answers1

0

Seems you are not getting any error. This can happen (?) if read operation fails and r is stuck. Tested what you shared.

Worked fine for me. though first i read the data in a seaprate df and then applied filters etc.

Covid19 <- read.csv("https://www.covid19.admin.ch/api/data/20220216-i4f5f0q1/sources/COVID19Hosp_geoRegion.csv")

Then

Covid19_CH <- Covid19%>%
  filter(geoRegion == "CH")

Can check full data:

Covid19%>%group_by(geoRegion)%>%
  summarise(N=n())

yields

# A tibble: 29 x 2
   geoRegion     N
   <chr>     <int>
 1 AG          724
 2 AI          724
 3 AR          724
 4 BE          724
 5 BL          724
 6 BS          724
 7 CH          724
 8 CHFL        724
 9 FL          724
10 FR          724
# ... with 19 more rows

surprising all GeoRegions has 724 records. Is that expected?

rest with xts is also working. You can test. perhaps site was down! or you cna download teh csv file and read it locally (if that's an option)

anuanand
  • 400
  • 1
  • 9
  • Look, the first time I do it, it works, but then when I try to import another data in the same way. It gets stuck and the new dataset appears as "NULL" Because I am importing first cases, then hospitalizations, then deaths, etc. The first time I tried with cases, It works, but as soon as I tried to do it with the second or other it gets stucks, today I got this error. *Error in Covid19a %>% Covid19a <- Covid19a %>% : could not find function "%>%<-* – Sebastian Merizalde Mar 31 '22 at 18:46