Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)
edited by

From the below syntax, I am importing a dataset and storing that in df:

df <- read.csv ('https://raw.githubusercontent.com/ulklc/covid19- 

timeseries/master/countryReport/raw/rawReport.csv',

            stringsAsFactors = FALSE)

# I did wrong.

df11 <- aggregate(df$confirmed, by=list(df$countryName) subset(df,df$confirmed < df$recovered) , FUN 

== "max"))

Now from within countries, I have to find the dates when the number of recovered has passed confirmation.

The output:

day              countryName        confirmed     recovered 

2020/04/10         Spain              1500          1550

2020/01/19         Italy              862            900

...

Note that the data are examples. are not real values.

1 Answer

0 votes
by (108k points)
edited by

As far as I know that no country has had more recovered than the cases that occurred. This is being proved with the following code:

library(dplyr)

df %>%

  mutate(day=as.Date(day)) %>%

  group_by(countryName) %>%

  filter(confirmed<recovered) %>%

  top_n(1, wt=day)

# A tibble: 0 x 9

Now let us assume that tomorrow, all cases in the country has recovered and no new cases occurred, then:

tomorrow <- read.table(text="

             day countryCode   countryName   region lat lon confirmed recovered death

21379 2020/05/09          US United States Americas  38 -97   1187233   1187234 68566", header=TRUE)

Now I am adding this row to the data frame and execute the code:

df2 <- rbind(df, tomorrow)

df2 %>%

  mutate(day=as.Date(day)) %>%

  group_by(countryName) %>%

  filter(confirmed<recovered) %>%

  top_n(1, wt=day)

#  A tibble: 1 x 9

#  Groups:   countryName [1]

#   day        countryCode countryName   region     lat   lon confirmed recovered death

#   <date>     <chr>       <chr>         <chr>    <dbl> <dbl>     <int>     <int> <int>

# 1 2020-05-09 US          United States Americas    38   -97   1187233   1187234 68566

If you are looking for R certification, then do check out the R programming certification

Browse Categories

...