####
#These are more or less the commands I showed at the beamer
#The files I use (csv) are in the ftp in the share/datasets/pommedeterre.org folder
pat=read.csv('patat_consumption.csv') #import a csv in a dataframe called pat
colnames(pat) #show the names of the vectors in the data frame
pat[,2] #print a column
pat[2,] #print a row
ind=pat$Indice.de.rendement #create a new vector with one element of the data table
plot(ind) #plot the element with the most comfortable graph, in this case histogram
diseases=cbind(pat[,20:25]) #form a small subset out of the columns of the diseases
plot(diseases) #plot the diseases, all columns against all others.
sunflowerplot(diseases) #plot different
###add labels
names=pat[,2] #create a vector with the names of the potatoes
twodiseases=cbind(pat[,20:21]) #create a subset of two diseases
sunflowerplot(twodiseases) #plot two diseases one against the other
text(twodiseases,labels=names,pos=3) #add labels of which potato we are talking about
### to install maps:
install.packages('maps')
library(maps)
map('state')
### to make more complex stuff by coding a bit:
par(mfrow=c(4,4)) # create a empty sheet with 4 by 4 plots (in total 16)
for (i in 1:16){ # with the i variable going 1 to 16
plot(ind,pad[,i],main=paste(colnames(pad)[,1])) # plot the indice the rendiment against the column "i" of the dataframe
}
############
#Small reference of the commands used
############
x=c(1,2,3) # define x as a vector with 1,2,3 as elements
help(c) # display help for the c command
length(c) # display the length of the c element
m=cbind(c1,c2) # create a matrix with the two vectors c1 and c2 as columns
y=t(x) # define y as the transposition (transform a row into column) of x
m=as.matrix(c) # translate the content of c in a matrix m
m[,1] # display the 1st column of the m matrix
m[2,] # display the 2nd row of the m matrix
m[1:3,c(2,4)] # display the 1 to 3 row, by the 2 and 4 column
plot(c) # create a plot with the elements in c
plot(x,y) # draw a scatter graph with the x and y of the elements
boxplot(x,y) # draw a box plot with x and y as coordinates of the elements..
c=read.csv('file.csv') # import the comma separated values from file.csv in c
colname(c)[2] # display the name of the 2nd column of c
m=as.matrix(c) # translate the content of c in a matrix m
####
R - Martino
install
sudo apt-get install r-base
use from command line
declare variables: var = 1
as list of numbers/strings.... : var = c(1,3, 4, 5)
in a list you can have many different elements:
- vector: 1 dimension
- matrix: 3 dimensions
- dataframe
- ...
create a matrix:
var = c(1,3, 4, 5) --> 1st column
var2 = c(32, 34, 55)
matr = cbind(var, var2) -> shows table
cvs format (comma separated values)
ID, name, values of the table
pat = read/cvs(path to cvs)
colnames(pat) -> you see the names of potatos
help()
when there are missing values, it produces 'NA' (not available)