0

For my project purpose, I need to directly take the data (excel sheet) from a website into R working platform. How can it be performed, please do help me out. This can be considered as an url for time being "https://www.contextures.com/tablesamples/sampledatahockey.zip"

neilfws
  • 32,751
  • 5
  • 50
  • 63
GSL
  • 1
  • 1
    Does this thread help you ? https://stackoverflow.com/questions/3053833/using-r-to-download-zipped-data-file-extract-and-import-data – Julien Jul 06 '22 at 05:54

1 Answers1

2

You can try:

library(readxl)

download.file("https://www.contextures.com/tablesamples/sampledatahockey.zip",
              destfile = "sampledatahockey.zip")
unzip("sampledatahockey.zip")
read_excel("sampledatahockey.xlsx", sheet = "PlayerData", skip = 2)

Output is:

# A tibble: 96 × 15                                                                                                                                                                                             
      ID Team  Country NameF    NameL     Weight Height DOB                 Hometown    Prov  Pos       Age HeightFt  HtIn   BMI
   <dbl> <chr> <chr>   <chr>    <chr>      <dbl> <chr>  <dttm>              <chr>       <chr> <chr>   <dbl>    <dbl> <dbl> <dbl>
 1     1 Women Canada  Meghan   Agosta       148 5'7    1987-02-12 00:00:00 Ruthven     Ont.  Forward    34     5.58    67    23
 2     2 Women Canada  Rebecca  Johnston     148 5'9    1989-09-24 00:00:00 Sudbury     Ont.  Forward    32     5.75    69    22
 3     3 Women Canada  Laura    Stacey       156 5'10   1994-05-05 00:00:00 Kleinburg   Ont.  Forward    27     5.83    70    22
 4     4 Women Canada  Jennifer Wakefield    172 5'10   1989-06-15 00:00:00 Pickering   Ont.  Forward    32     5.83    70    25
 5     5 Women Canada  Jillian  Saulnier     144 5'5    1992-03-07 00:00:00 Halifax     N.S.  Forward    29     5.42    65    24
 6     6 Women Canada  Mélodie  Daoust       159 5'6    1992-01-07 00:00:00 Valleyfield Que.  Forward    29     5.5     66    26
 7     7 Women Canada  Bailey   Bram         150 5'8    1990-09-05 00:00:00 St. Anne    Man.  Forward    31     5.67    68    23
 8     8 Women Canada  Brianne  Jenner       156 5'9    1991-05-04 00:00:00 Oakville    Ont.  Forward    30     5.75    69    23
 9     9 Women Canada  Sarah    Nurse        140 5'8    1995-01-04 00:00:00 Hamilton    Ont.  Forward    26     5.67    68    21
10    10 Women Canada  Haley    Irwin        170 5'7    1988-06-06 00:00:00 Thunder Bay Ont.  Forward    33     5.58    67    27
# … with 86 more rows
Stephan
  • 2,056
  • 1
  • 9
  • 20