Die Grösse des Plot-Fensters kann mit windows() festgelegt werden. Das Grafikfenster wird mit dev.off() wieder geschlossen.
windows(width=10, height=5)
plot( 1:5 )
dev.off()
Donnerstag, 11. November 2010
Mittwoch, 10. November 2010
Selektieren von Listenelementen
Listenelemente können systematisch mit lapply( list, "[", element ) extrahiert werden.
d.frm <- data.frame( id_name=c("1-Max","2-Maria","3-Steven","4-Jane"))
# split into list
lst <- strsplit( x=as.character(d.frm$id_name), split="-" )
# get first elements out of list
d.frm$id <- as.integer( unlist( lapply( lst, "[", 1) ))
d.frm$name <- unlist( lapply( lst, "[", 2) )
d.frm
id_name name id
1 1-Max Max 1
2 2-Maria Maria 2
3 3-Steven Steven 3
4 4-Jane Jane 4
str(d.frm)
'data.frame': 4 obs. of 3 variables:
$ id_name: Factor w/ 4 levels "1-Max","2-Maria",..: 1 2 3 4
$ name : chr "Max" "Maria" "Steven" "Jane"
$ id : int 1 2 3 4
d.frm <- data.frame( id_name=c("1-Max","2-Maria","3-Steven","4-Jane"))
# split into list
lst <- strsplit( x=as.character(d.frm$id_name), split="-" )
# get first elements out of list
d.frm$id <- as.integer( unlist( lapply( lst, "[", 1) ))
d.frm$name <- unlist( lapply( lst, "[", 2) )
d.frm
id_name name id
1 1-Max Max 1
2 2-Maria Maria 2
3 3-Steven Steven 3
4 4-Jane Jane 4
str(d.frm)
'data.frame': 4 obs. of 3 variables:
$ id_name: Factor w/ 4 levels "1-Max","2-Maria",..: 1 2 3 4
$ name : chr "Max" "Maria" "Steven" "Jane"
$ id : int 1 2 3 4
Abonnieren
Posts (Atom)