CSV file from excel

save the attached Excel students file as *.csv:

a) Import the data

b) Get the first row of the data

c) Get all the female students only

d) Get the summary for Average score (grade)

e) Get the names of the rows and columns

How to do it?

Hi, and welcome!

Two preliminaries:

  1. Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers.

  2. Check the homework policy.

This is a process that everyone either has or will go through to learn R. It helps to keep in mind that

  1. Everything in R is an object, meaning it has content and properties that can be acted upon.

  2. Some objects can change other objects, these are functions.

  3. Functions are just what they sound like, school algebra: f(x) = y where f, the function object operates on one or more x argument objects and returns a value object as a result.

R has an endless richness of functions, but sometimes finding the right one can be a challenge. If not mentioned in your lecture notes or the text, try typing into the R command line

help(read.table)

which will lead you to the function for the first step. (Hint: csv stands for comma separated value; also, whenever you use a function, you probably also need to assign the return value to something.)

To see the last row of the built in object mtcars

tail(mtcars,1)
#>             mpg cyl disp  hp drat   wt qsec vs am gear carb
#> Volvo 142E 21.4   4  121 109 4.11 2.78 18.6  1  1    4    2

Created on 2020-04-02 by the reprex package (v0.3.0)

To see only the mpg values in mtcars, there are two ways

mtcars$mpg
#>  [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
#> [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
#> [31] 15.0 21.4
mtcars[1]
#>                      mpg
#> Mazda RX4           21.0
#> Mazda RX4 Wag       21.0
#> Datsun 710          22.8
#> Hornet 4 Drive      21.4
#> Hornet Sportabout   18.7
#> Valiant             18.1
#> Duster 360          14.3
#> Merc 240D           24.4
#> Merc 230            22.8
#> Merc 280            19.2
#> Merc 280C           17.8
#> Merc 450SE          16.4
#> Merc 450SL          17.3
#> Merc 450SLC         15.2
#> Cadillac Fleetwood  10.4
#> Lincoln Continental 10.4
#> Chrysler Imperial   14.7
#> Fiat 128            32.4
#> Honda Civic         30.4
#> Toyota Corolla      33.9
#> Toyota Corona       21.5
#> Dodge Challenger    15.5
#> AMC Javelin         15.2
#> Camaro Z28          13.3
#> Pontiac Firebird    19.2
#> Fiat X1-9           27.3
#> Porsche 914-2       26.0
#> Lotus Europa        30.4
#> Ford Pantera L      15.8
#> Ferrari Dino        19.7
#> Maserati Bora       15.0
#> Volvo 142E          21.4

Created on 2020-04-02 by the reprex package (v0.3.0)

There' a function to provide a summary. Try an obvious function name

obvious(your_object$your_variable)

If you have data in row/col format, what's a reasonable guess for a function to return their names?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.