R Statistics 9789385516146, 9789389130737

This book will help its readers to learn the first step of R statistics as it will help its readers to sit before the co

152 120 29MB

English Pages 122 [124]

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Cover
Copyright
Preface
Start
Recommend Papers

R Statistics
 9789385516146, 9789389130737

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

R Statistics

R Statistics

D.K. Samual Principal Scientist Indian Institute of Horticultural Research Hessaraghatta Lake Post Bangalore, Karnataka

NEW INDIA PUBLISHING AGENCY New Delhi – 110 034

NEW INDIA PUBLISHING AGENCY 101, Vikas Surya Plaza, CU Block, LSC Market Pitam Pura, New Delhi 110 034, India Phone: + 91 (11)27 34 17 17 Fax: + 91(11) 27 34 16 16 Email: [email protected] Web: www.nipabooks.com Feedback at [email protected] © 2020, Author ISBN 978-93-85516-14-6

eISBN : 978-93-89130-73-7

All rights reserved, no part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise without the prior written permission of the publisher or the copyright holder. This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author/s, editor/s and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The author/s, editor/s and publisher have attempted to trace and acknowledge the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission and acknowledgements to publish in this form have not been taken. If any copyright material has not been acknowledged please write and let us know so we may rectify it, in subsequent reprints. Trademark notice: Presentations, logos (the way they are written/presented), in this book are under the trademarks of the publisher and hence, if copied/resembled the copier will be prosecuted under the law. Composed, Designed and Printed in India Distributed by NIPA GENX Electronic Resources and Solutions Pvt. Ltd. New Delhi

Preface

My aim in writing this short book is to enable an average student like me to graph and chart the data in an understandable and analytically correct manner using R. I have a wild dream, that high school students to Post-Doctoral researchers of all fields will use R and that this book will help them learn the first steps, so I decided not to write extra and not to repeat what was already available on the internet/print. You may feel that the book is fast paced, Yes it is, it is meant to be read sitting before a PC and to enter the commands. Practice makes perfect and the best way to learn R is to work with it and ask questions when you don’t get the results. Very special thanks to the staff of NIPA for agreeing to publish this book in color. Hope this book on R will help you to start on a journey of discovery with R. Good Luck and God Bless, I hope that soon I will be able to see charts based on this book get published in research journals. One request please work on the code and try till you succeed. Don’t give up easily. For comments/suggestions/criticisms, please contact on email: [email protected]. Author

R Statistics vii

Draw any of the above charts in less than a minute! with the included free R code

viii

R Statistics

Draw any of the above charts in less than a minute! with the included free R code

R Statistics 1

R is a software package / language / environment for statistical analysis and graphics. It Reads Any Type of Data *.txt, .csv, .dat, etc.), You can also scrape (collect) data from websites and execute SQL queries It Supports Large Data Sets. Reproducibility. R allows you to add comments to your scripts to make it clear to you and others on what you’re doing as data and analysis are separated in R. As R is fully free you can use the latest version on any / as many computers so you and your student can work on the same version. You can use R on Windows, Mac, Linux, and Unix. Anyone (Including You) Can Contribute Packages to the Community to Improve its Functionality. You can download R from : http://cran.r-project.org. R has a command line interface and that is a huge hurdle for many users, but believe us you will find that using a command line is also easy. However we strongly recommend the R Studio text editor for working with R scripts (http://www.rstudio.com/ide/ download). Note: R and few packages, with R Studio is available in the supplied DVD R Charting in less than 1-minute Ok let us start. Type or even better cut and paste the following text lines in a R > prompt.

2 R Statistics

Please do not include the symbol of R prompt > so Type or cut and paste from x symbol when you type the code. Please type / cut and paste carefully

> x < - c ( 11 3 , 11 7 , 2 3 5 , 2 5 2 , 2 6 3 , 2 7 1 , 2 9 0 , 3 0 0 , 3 2 1 , 340,999) # Now press the , After you press the the R prompt > will reappear >plot(x,type=”l”,col=”blue”,lty=1,lwd=3, xlab=”Plant Samples”, ylab=”Height in Cm”, main=”My first R Plot”) # After the R prompt reappears then type / cut and paste the second line and press the again.

You can type / cut and paste both the lines together and press the once

R Statistics 3

! Don’t include this > symbol when you type the code. Please type / cut and paste carefully. Type like this > x plot(x, type=“l”,col=“blue”,lty=1,lwd=3, xlab=“Plant Samples”,ylab= “Height in Cm”, main=“My first R Plot”) press the again # you can also do like this > x mydata edit(my.data) Code Explained: This command will open up a spreadsheet with the csv file arranged in it; you can do rudimentary editing in it DATA REQUIRED Second R Chart in less than 1-minute Cut and paste the following 3 lines at the R prompt > >my.dat=read.csv(file.choose()) press key now navigate using windows explorer to select the file 6_col_data.csv and select it now type my.dat at the command prompt and press key and R will respond by displaying the 6_col_data.csv with its proper headings. > my.dat Mysore

Hunsur

Madikeri

Dharwad

Hassan

Shimoga

1 607 524 304 699 513 336 2 709 481 432 315 667 609 3 603 801 471 464 468 940 4 955 479 908 151 425 404 5 364 784 257 105 455 581 6 641 951 733 915 396 688 7 891 936 332 880 968 236 8 641 951 915 396 688 545 Type the attach command so the data can be assessed by their column names > attach(my.dat)

R Statistics 9

Now type the command > boxplot(my.dat,col=rainbow(6)) You will get the graph in the graphic window

Save the graph / copy, it as earlier discussed

10

R Statistics

To see the data structure visually type the command, as you have already read the 6_col_data.csv file you need not read it again, R will keep in memory the data file and the variable my.dat and you can recycle it. However they are given so that you can randomly create any graph at any time. my.data