Estratto del documento

LEZ 2R versione 4.2.1 (2022-06-23) - "Funny-Looking Kid"

Copyright (C) 2022 The R Foundation for Statistical Computing

Platform: x86_64-apple-darwin17.0 (64-bit)

R è un software libero ed è rilasciato SENZA ALCUNA GARANZIA. Siamo ben lieti se potrai redistribuirlo, ma sotto certe condizioni. Scrivi 'license()' o 'licence()' per maggiori dettagli. R è un progetto collaborativo con molti contributi esterni. Scrivi 'contributors()' per maggiori informazioni e 'citation()' per sapere come citare R o i pacchetti nelle pubblicazioni. Scrivi 'demo()' per una dimostrazione, 'help()' per la guida oppure 'help.start()' per la guida nel browser HTML. Scrivi 'q()' per uscire da R.

[R.app GUI 1.79 (8095) x86_64-apple-darwin17.0]

[Workspace restored from /Users/annamaria/.RData]

[History restored from /Users/annamaria/.Rapp.history]

> x <- c(2,5,8,12,18)

> y <- c(42,61,70,100,122)

> plot(x,y)

> pdf("plot.pdf")

> plot(x,y)

> dev.off()

quartz2

> getvd()

Errore in getvd() : non trovo la funzione "getvd"

> getwd()

[1] "/Users/annamaria"

2022-10-24 08:48:22.958 R[23704:2175234] +[NSSavePanel _warmUp] attempted warmup

> xy.lm <- lm(y~x)

> ls()

[1] "cicciobello" "gianmario" "x" "xy.lm" "y"

> xy.lm

Call: lm(formula = y ~ x)

Coefficients:

(Intercept) x

33.423 5.064

> plot(x,y)

> plot(y~x)

> abline(xy.lm)

> pdf("grafico2.pdf")

> abline(xy.lm)

Errore in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet

> dev.off()

quartz2

> getwd()

[1] "/Users/annamaria"

> pdf("grafico2.pdf")

> plot(y~x)

> dev.off()

quartz2

> getwd()

[1] "/Users/annamaria"

> #non riesco a capire come salvare il grafico

> pdf(grafico.pdf)

Errore in is.factor(x) : oggetto 'grafico.pdf' non trovato

> pdf("grafico.pdf")

> plot(x,y)

> plot(y~x)

> abline(xy.lm)

> dev.off()

quartz2

> getwd()

[1] "/Users/annamaria"

> summary(xy.lm)

Call: lm(formula = y ~ x)

Residuals:

  • 1 2 3 4 5
  • -1.551 2.256 -3.936 5.808 -2.577

Coefficients:

Estimate Std. Error t value Pr(>|t|)
(Intercept) 33.4231 3.8974 8.576 0.00333 **
x 5.0641 0.3679 13.763 0.00083 ***

---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 4.596 on 3 degrees of freedom

Multiple R-squared: 0.9844, Adjusted R-squared: 0.9792

F-statistic: 189.4 on 1 and 3 DF, p-value: 0.0008301120

> y

80 60 40

> x

5 10 15

> x[1]

2 5 8 12 18

> x>10

[1] FALSE FALSE FALSE TRUE TRUE

> nomi <-c("Stefano","Mario","Giorgia")

> nomi

[1] "Stefano" "Mario" "Giorgia"

> is character (nomi)

Error: unexpected symbol in "is character"

> is.character(nomi)

[1] TRUE

LEZ 3R versione 4.2.1 (2022-06-23) - "Funny-Looking Kid"

Copyright (C) 2022 The R Foundation for Statistical Computing

Platform: x86_64-apple-darwin17.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.

[R.app GUI 1.79 (8095) x86_64-apple-darwin17.0]

[Workspace restored from /Users/annamaria/.RData]

[History restored from /Users/annamaria/.Rapp.history]

> #pag 24 dispense

> exp1.df<-read.table("dati/exp1.txt",header=TRUE)

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") : cannot open file 'dati/exp1.txt': No such file or directory

> #pag 30 dispense

> d.df<-read.table("exp.1.csv",header=T,sep=";",dec=",")

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") : cannot open file 'exp.1.csv': No such file or directory

> #non so perché non trova il file :(

> #prima bisogna fare get.wd()

> get.wd()

Error in get.wd() : could not find function "get.wd"

> #senza il punto

> getwd()

[1] "/Users/annamaria"

> d.df<.read.table("exp.1.csv",sep=";",dec=",",header=T,na.strings=c("-","manca"))

Error: object 'd.df' not found

> d.df<-read.table("exp.1.csv",sep=";",dec=",",header=T,na.strings=c("-","manca"))

> d.df

weight group
1 4.17 Ctrl
2 5.58 Ctrl
3 5.18 Ctrl
4 6.11 Ctrl
5 4.50 Ctrl
6 4.61 Ctrl
7 5.17 Ctrl
8 4.53 Ctrl
9 5.33 Ctrl
10 5.14 Ctrl
11 4.81 Trt1
12 4.17 Trt1
13 4.41 Trt1
14 3.59 Trt1
15 5.87 Trt1
16 3.83 Trt1
17 6.03 Trt1
18 4.89 Trt1
19 NA Trt1
20 NA Trt1
21 6.31 Trt2
22 5.12 Trt2
23 5.54 Trt2
24 5.50 Trt2
25 5.37 Trt2
26 5.29 Trt2
27 4.92 Trt2
28 6.15 Trt2
29 5.80 Trt2
30 NA Trt2

> getwd()

[1] "/Users/annamaria/Desktop/R"

> summary(d.df)

weight group
Min. :3.590 Length:30
1st Qu.:4.570 Class :character
Median :5.170 Mode :character
Mean :5.108
3rd Qu.:5.560
Max. :6.310
NA's :3

> ls()

[1] "a" "b" "cicciobello" "d.df" "duplica" "gianmario" "multiplo" "nomi" "x" "xy.lm" "y"

> nomi<-c("franco","stefano","pio","tizio","marco")

> ages<-c(102,26,25,48,19)

> is.character(nomi)

[1] TRUE

> is.numeric(ages)

[1] TRUE

> length(nomi)

[1] 5

> lenght(ages)

Error in lenght(ages) : could not find function "lenght"

> length(ages)

[1] 5

> length(ages)==length(nomi)

[1] TRUE

> rep(1:3,times=5)

[1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

> #rep=repetition; ripete 5 volte i numeri da 1 a 3

> rep(nomi,5)

[1] "franco" "stefano" "pio" "tizio" "marco" "franco" "stefano" "pio" "tizio" "marco" "franco" "stefano" "pio" "tizio" "marco" "franco" "stefano" "pio" "tizio" "marco" "franco" "stefano" "pio" "tizio" "marco"

> rep(1:3,times=c(2,3,5))

[1] 1 1 2 2 2 3 3 3 3 3

> seq(from=0,to=10;by=0.5)

Error: unexpected ';' in "seq(from=0,to=10;"

> seq(from=0,to=10,by=0.5)

[1] 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0

> runif(10,0,100)

[1] 56.852431 6.551566 57.144372 37.893096 69.491947 53.603919 55.792000 79.287607 54.302435 29.218517

> #il comando runif serve per estrarre numeri casuali, in questo caso 10 numeri casuali compresi tra 0 e 100

> #ora importiamo un file coi dati scritti in modo scorretto

> exp2.df<-read.table("exp2-2.csv",header=T,sep=";",dec=",",h=T)

Error in read.table("exp2-2.csv", header = T, sep = ";", dec = ",", h = T) : unused argument (h = T)

> exp2.df<-read.table("exp2-2.csv",sep=";",dec=",",header=T)

> exp.2

Error: object 'exp.2' not found

> exp2

Error: object 'exp2' not found

> exp2.df

Ctrl Trt1 Trt2
1 4.17 4.81 6.31
2 5.58 4.17 5.12
3 5.18 4.41 5.54
4 6.11 3.59 5.50
5 4.50 5.87 5.37
6 4.61 3.83 5.29
7 5.17 6.03 4.92
8 4.53 4.89 6.15
9 5.33 NA 5.80
10 5.14 NA NA

> summary(exp2.df)

Ctrl Trt1 Trt2
Min. :4.170 Min. :3.590 Min. :4.920
1st Qu.:4.550 1st Qu.:4.085 1st Qu.:5.290
Median :5.155 Median :4.610 Median :5.500
Mean :5.032 Mean :4.700 Mean :5.556
3rd Qu.:5.293 3rd Qu.:5.135 3rd Qu.:5.800
Max. :6.110 Max. :6.030 Max. :6.310
NA's :2 NA's :1

> exp2.df$Ctrl

[1] 4.17 5.58 5.18 6.11 4.50 4.61 5.17 4.53 5.33 5.14

> exp2.df$Trt1

[1] 4.81 4.17 4.41 3.59 5.87 3.83 6.03 4.89 NA NA

> exp2.df$Trt2

[1] 6.31 5.12 5.54 5.50 5.37 5.29 4.92 6.15 5.80 NA

> peso<-c(exp2.df$Ctrl,exp2.df$Trt1,exp2.df$Trt2)

> peso

[1] 4.17 5.58 5.18 6.11 4.50 4.61 5.17 4.53 5.33 5.14 4.81 4.17 4.41 3.59 5.87 3.83 6.03 4.89 NA NA 6.31 5.12 5.54 5.50 5.37 5.29 4.92 6.15 5.80 NA

> gruppo<-rep(c("Ctrl","Trt1","Trt2"),each=10)

> gruppo

[1] "Ctrl" "Ctrl" "Ctrl" "Ctrl" "Ctrl" "Ctrl" "Ctrl" "Ctrl" "Ctrl" "Ctrl" "Trt1" "Trt1" "Trt1" "Trt1" "Trt1" "Trt1" "Trt1" "Trt1" "Trt1" "Trt1" "Trt2" "Trt2" "Trt2" "Trt2" "Trt2" "Trt2" "Trt2" "Trt2" "Trt2" "Trt2"

> newexp2.df<-data.frame(peso,gruppo)

> newexp2.df

peso gruppo
1 4.17 Ctrl
2 5.58 Ctrl
3 5.18 Ctrl
4 6.11 Ctrl
5 4.50 Ctrl
6 4.61 Ctrl
7 5.17 Ctrl
8 4.53 Ctrl
9 5.33 Ctrl
10 5.14 Ctrl
11 4.81 Trt1
12 4.17 Trt1
13 4.41 Trt1
14 3.59 Trt1
15 5.87 Trt1
16 3.83 Trt1
17 6.03 Trt1
18 4.89 Trt1
19 NA Trt1
20 NA Trt1
21 6.31 Trt2
22 5.12 Trt2
23 5.54 Trt2
24 5.50 Trt2
25 5.37 Trt2
26 5.29 Trt2
27 4.92 Trt2
28 6.15 Trt2
29 5.80 Trt2
30 NA Trt2

> #con questi comandi abbiamo riordinato correttamente i dati

> #estrarre elementi dai vettori:

> nomi

[1] "franco" "stefano" "pio" "tizio" "marco"

> nomi[2]

[1] "stefano"

> nomi[4]

[1] "tizio"

> nomi[1]

[1] "franco"

> ages[1]

[1] 102

> ages[1]<-103

> ages[1]

[1] 103

> ages[1:3]

[1] 103 26 25

> nomi[1:3]

[1] "franco" "stefano" "pio"

> ages[3:1]

[1] 25 26 103

> nomi[3:1]

[1] "pio" "stefano" "franco"

> ages

[1] 103 26 25 48 19

> ages[2,4]

Error in ages[2, 4] : incorrect number of dimensions

> ages[c(2,4)]

[1] 26 48

> ages[ages<30]

[1] 26 25 19

LEZ 4R versione 4.2.1 (2022-06-23) - "Funny-Looking Kid"

Copyright (C) 2022 The R Foundation for Statistical Computing

Platform: x86_64-apple-darwin17.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.

[R.app GUI 1.79 (8095) x86_64-apple-darwin17.0]

[Workspace restored from /Users/annamaria/.RData]

[History restored from /Users/annamaria/.Rapp.history]

starting httpd help server ... done

> ages()

Error in ages() : could not find function "ages"

> ages

Error: object 'ages' not found

> nommi

Error: object 'nommi' not found

> nomi

[1] "Stefano" "Mario" "Giorgia"

> ages<-(102,26,25,48,19)

Error: unexpected ',' in "ages<-(102,"

> ages<-c(102,26,25,48,19)

> ages<30

[1] FALSE TRUE TRUE FALSE TRUE

> #ages<30 è un vettore logico

> ages [ages<30]

[1] 26 25 19

> #ho estratto le età minori di 30

> natalità<-c(8.4,9.4,9.6,8.5,8.0,8.1,8.5)

> mortalità<-c(11.3,9.4,9.3,11.4,11.6,10.8,10.6)

> nomiregione<-c("piemonte","lombardia","veneto","emilia","toscana","umbria","marche")

> natatlità

Error: object 'natatlità' not found

> natalità

[1] 8.4 9.4 9.6 8.5 8.0 8.1 8.5

> mortalità

[1] 11.3 9.4 9.3 11.4 11.6 10.8 10.6

> nomiregione

[1] "piemonte" "lombardia" "veneto" "emilia" "toscana" "umbria" "marche"

> is.numeric(natalità)

[1] TRUE

> is.numeric(nomiregione)

[1] FALSE

> is.character(nomiregione)

[1] TRUE

> lenght(natalità)

Error in lenght(natalità) : could not find function "lenght"

> length(natalità)

[1] 7

> nomiregione[3]

[1] "veneto"

> nomiregione[5]

[1] "toscana"

> mortalità[3]

[1] 9.3

> names(natalità)<-nomiregione

> names(mortalità)<-nomiregione

> natalità

piemonte lombardia veneto emilia toscana umbria marche

8.4 9.4 9.6 8.5 8.0 8.1 8.5

> mortalità

piemonte lombardia veneto emilia toscana umbria marche

11.3 9.4 9.3 11.4 11.6 10.8 10.6

> mortalità["veneto"]

veneto

9.3

> natalità["marche"]

marche

8.5

> #per sapere se la regione sta invecchiando

> crescita<-natalità-mortalità

> crescita["lombardia"]

lombardia

0

> crescita[emilia]

Error: object 'emilia' not found

> crescita["emilia"]

emilia

-2.9

> crescita

piemonte lombardia veneto emilia toscana umbria marche

-2.9 0.0 0.3 -2.9 -3.6 -2.7 -2.1

> #vettori indicizzati da stringhe

> crescita[5]

toscana

-3.6

> #posso usare sia il vettore numerico che il vettore indicato da stringhe

> #per importare il file spostare il file nella working directory, per sapere qual è la working directory usare il comando getwd()

> getwd()

[1] "/Users/annamaria"

2022-11-08 22:21:12.659 R[49242:4904122] +[NSSavePanel _warmUp] attempted warmup

> getwd()

[1] "/Users/annamaria/Desktop/R"

> d.df <- read.table("exp1.txt", h=T)

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") : cannot open file 'exp1.txt': No such file or directory

> d.df

Error: object 'd.df' not found

> d.df <- read.table("exp.1.csv", h=T)

> d.df

weight.group

1 4,17;Ctrl

2 5,58;Ctrl

3 5,18;Ctrl

4 6,11;Ctrl

5 4,5;Ctrl

6 4,61;Ctrl

7 5,17;Ctrl

8 4,53;Ctrl

9 5,33;Ctrl

10 5,14;Ctrl

11 4,81;Trt1

12 4,17;Trt1

13 4,41;Trt1

14 3,59;Trt1

15 5,87;Trt1

16 3,83;Trt1

17 6,03;Trt1

18 4,89;Trt1

19 -;Trt1

20 -;Trt1

21 6,31;Trt2

22 5,12;Trt2

23 5,54;Trt2

24 5,5;Trt2

25 5,37;Trt2

26 5,29;Trt2

27 4,92;Trt2

28 6,15;Trt2

29 5,8;Trt2

30 manca;Trt2

> grammi<-c(60,45,54)

> grammi

[1] 60 45 54

> names(grammi)<-c("Ctrl","Trt1","Trt2")

> grammi

Ctrl Trt1 Trt2

60 45 54

> d.df$grammidieta<-grammi[d.df$group]

Error in `$<-.data.frame`(`*tmp*`, grammidieta, value = numeric(0)) : replacement has 0 rows, data has 30

> d.df$grammidieta <- grammi[d.df$group]

Error in `$<-.data.frame`(`*tmp*`, grammidieta, value = numeric(0)) : replacement has 0 rows, data has 30

> d.df<-read.table("exp.1",h=T)

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") : cannot open file 'exp.1': No such file or directory

> getwd()

[1] "/Users/annamaria/Desktop/R"

> d.df<-read.table("exp.1-2.csv",h=T)

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") : cannot open file 'exp.1-2.csv': No such file or directory

> d.df<-read.table("exp1-2.csv",h=T)

> d.df

weight.group

1 4,17;Ctrl

2 5,58;Ctrl

3 5,18;Ctrl

4 6,11;Ctrl

5 4,5;Ctrl

6 4,61;Ctrl

7 5,17;Ctrl

8 4,53;Ctrl

9 5,33;Ctrl

10 5,14;Ctrl

11 4,81;Trt1

12 4,17;Trt1

13 4,41;Trt1

14 3,59;Trt1

15 5,87;Trt1

16 3,83;Trt1

17 6,03;Trt1

18 4,89;Trt1

19 6,31;Trt2

20 5,12;Trt2

21 5,54;Trt2

22 5,5;Trt2

23 5,37;Trt2

24 5,29;Trt2

25 4,92;Trt2

26 6,15;Trt2

27 5,8;Trt2

28 ;

> d.df$grammidieta<-grammi[d.df$group]

Error in `$<-.data.frame`(`*tm

Anteprima
Vedrai una selezione di 20 pagine su 96
Corso di informatica su R per le biotec. + simulazioni esame Pag. 1 Corso di informatica su R per le biotec. + simulazioni esame Pag. 2
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 6
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 11
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 16
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 21
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 26
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 31
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 36
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 41
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 46
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 51
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 56
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 61
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 66
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 71
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 76
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 81
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 86
Anteprima di 20 pagg. su 96.
Scarica il documento per vederlo tutto.
Corso di informatica su R per le biotec. + simulazioni esame Pag. 91
1 su 96
D/illustrazione/soddisfatti o rimborsati
Acquista con carta o PayPal
Scarica i documenti tutte le volte che vuoi
Dettagli
SSD
Scienze matematiche e informatiche INF/01 Informatica

I contenuti di questa pagina costituiscono rielaborazioni personali del Publisher annamariamannazzu di informazioni apprese con la frequenza delle lezioni di Informatica applicata alle biotecnologie e studio autonomo di eventuali libri di riferimento in preparazione dell'esame finale o della tesi. Non devono intendersi come materiale ufficiale dell'università Università degli Studi di Parma o del prof Marchettoni Leonardo.
Appunti correlati Invia appunti e guadagna

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community