When you start R session, It starts in a working directory,. You can manually change it going in File menu. or by the code
>setwd("D:/Rsession")
then, you can get the path by command
> getwd()
[1] "D:/Rsession"
You can assign values to object by <- or -> sign,
>x<-rnorm(50)
>rnorm(100)->y
if you tried the opposite, you will get error message
> y->rnorm(50)
Error in rnorm(50) <- y :
target of assignment expands to non-language object
the objects in your current working directory can be listed by
>objects()
> ls()
[1] "x" "y"
to remove the objects
> rm(x)
> ls()
[1] "y"
to remove all the objects
> rm(list=ls())
> ls()
character(0)
to know the column names of table
> names(xy)
[1] "Rep" "Genotype" "top" "root" "Control"
to know more information about variables
> ls.str()
xy : 'data.frame': 224 obs. of 5 variables:
$ Rep : int 1 1 1 1 1 1 1 1 1 1 ...
$ Genotype: Factor w/ 28 levels "M1M3","M1S1",..: 10 11 8 9 12 13 14 17 15 16 ...
$ top : num 0.65 0.77 0.77 0.73 0.69 0.72 0.56 0.69 0.65 0.86 ...
$ root : num 0.48 0.32 0.25 0.31 0.33 0.34 0.28 0.37 0.4 0.3 ...
$ Control : int 0 0 0 0 0 0 0 0 0 0 ...
y : num [1:50] -1.824965 -0.400061 -1.241349 2.017474 -0.000123 ...
to access the variable of dataframe
> xy$Rep
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
[38] 2 2 2 2 2 2 2 2 2 2 2
notice that Rep will not give anything here
> Rep
Error: object "Rep" not found
to make it accessible
> attach(xy)
> Rep
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
[38] 2 2 2 2 2 2 2 2 2 2 2
to make inaccessible again
> detach()
> Rep
Error: object "Rep" not found
to quit a program
>q() #or
>quit()
all for today
0 comments:
Post a Comment