Entering data in R
Getting help in R
Sometimes, you may need to work
with very few values, hence it will be more time consuming to import from excel
In such cases, just enter those
data in R
x<-c(2,5,4,6,8,2,3,10,3,13)
Similarly, combining different
vectors
a<-c(40,50,41,24,52,48) # entering data
b<-c(10,12,13,19,17,11) # entering data
m<-cbind(a,b) # to
combine 2 vectors to matrix
m
# to check the dataframe
d<-c(.1,.2,.4,.5,.8,.0) # entering data
n<-rbind(a,b,d) # to combined 3 vectors to rows
n #
to check the dataframe
cbind= bind to columns
rbind= bind to rows
Making row and column
e<-c(1,3,3,4,1,2,5,2,5,1,5,15,13,14)
g<-matrix(c(e),nrow=7,ncol=2)
g #
to check the matrix
f<-c(1,3,3,4,1,2,5,2,5,1,5,15,13,14,15,13,17)
h<-matrix(c(f),nr=7,nc=2)
h # to check the matrix, and see the error message displayed
BUT here, cbind will work, but eliminates
exceeded data, try
k<-cbind(e,g,f)
k
Preparing data for R
Well shaped matrix will make your task ease
Good way of data tabulation when you have to compare to mediums
that controls the density
Import data from demodata.xls, sheet 6
read.table('clipboard',header=T)->density.block
attach(density.block)
mean(Medium.A) # mean density for medium A
mean(Medium.B) # mean density for medium B
read.table('clipboard',header=T)->density.stack
density.stack
attach(density.stack)
mean(Density) # this is for all values
mean(Density[Medium=='A']) # mean for medium = A
mean(Density[Medium=='B'])
# mean for medium = B
What you want to perform, search in Google
E.g. Calculating mode in R
Then look at the package name and function name
Install the package (if not installed already)
Then load the package (as did in previous practice)
Then find the command description file in R
Help
(Mode)
or just
?
Mode
The command
to find help about a certain topic, for instance linear model:
help.search('linear
model')
R will then
list the functions that contain this topic.
It is easy
to use the help function to discover the contents of library prackages. Here is
how you find out about contents of the ”stats” library.
library (help=stats)
It will
open a text file with detail of the library. It will give list of the commands
and functions that are included in that library, and their brief
description
And if you
find any command or function you are looking for, look for detail of the
command or function about how to use it, to find how to use just type
help(lm)
or
just
?lm
It will
open new window with some detail of the command or function
The window
will guide you how to use it, and what are the elements that are required for
the command, and some more
Typing help.start() opens a web browser with help
information.
example(lm) will run any examples that are
included in the help page for command lm.
demo(topic) runs demonstration code on
topic lm: type demo() by itself to list all available demos
By default, R’s help system only provides information about
functions that are in the base system and packages that you have loaded
with library
??lm or help.search(lm) will list information related to topic available in
the base system or in any extra installed packages
Crediting R
When we use R for any purpose, it should be cited, and to red
the citation information
citation(package = "base", lib.loc
= NULL, auto = NULL)
Citing any other package
citation(package = "prettyR",
lib.loc = NULL, auto = NULL)
More under construction ......
No comments:
Post a Comment