Kapitel 63 Suchen nach Variablen
63.1 Lookfor
Das R Paket questionr bietet eine sehr hilfreiche Funktion, den Befehl lookfor.
Mit lookfor(data, “Teil_des_Names_der_Variable”) können wir im data frame data nach Variablen suchen, die “Teil_des_Names_der_Variable” im Variablen-Namen haben.
Erstellen wir zuerst ein paar Daten für ein Beispiel:
library(questionr)
<-rnorm(100, 50,12)
Thats_a_cool_variable <-rnorm(100,50,12)
Thats_a_less_cool_variable <-rnorm(100,40,21)
Thats_an_even_cooler_variable<-rnorm(100, 50,4)
Alter<-cut(Alter, breaks=c(18,30,40,50,60,70,75,80)) # either a numeric vector of two or more unique cut points or a single number (greater than or equal to 2) giving the number of intervals into which x is to be cut
Altersklassen
=rep(0:1,each=50)
Does_R_makes_you_angry=rep(c(1,0),each=50)
Does_R_makes_you_happy
<-data.frame(Thats_an_even_cooler_variable, Thats_a_cool_variable, Thats_a_less_cool_variable, Does_R_makes_you_angry, Does_R_makes_you_happy, Alter, Altersklassen)
datanames(data)
## [1] "Thats_an_even_cooler_variable" "Thats_a_cool_variable"
## [3] "Thats_a_less_cool_variable" "Does_R_makes_you_angry"
## [5] "Does_R_makes_you_happy" "Alter"
## [7] "Altersklassen"
In diesem Beispiel werden wir nichts finden.
# Example that will yield nothing:
lookfor(data, "coll")
## Nothing found. Sorry.
Mit diesem Beispiel werden wir etwas finden.
# Example that will find something:
lookfor(data, "cool")
## pos variable label col_type values
## 1 Thats_an_even_cooler_variable — dbl
## 2 Thats_a_cool_variable — dbl
## 3 Thats_a_less_cool_variable — dbl
Noch ein Beispiel:
lookfor(data, "Alter")
## pos variable label col_type values
## 6 Alter — dbl
## 7 Altersklassen — fct (18,30]
## (30,40]
## (40,50]
## (50,60]
## (60,70]
## (70,75]
## (75,80]
Oder:
lookfor(data, "Alt")
## pos variable label col_type values
## 6 Alter — dbl
## 7 Altersklassen — fct (18,30]
## (30,40]
## (40,50]
## (50,60]
## (60,70]
## (70,75]
## (75,80]
Oder:
lookfor(data, "Alters")
## pos variable label col_type values
## 7 Altersklassen — fct (18,30]
## (30,40]
## (40,50]
## (50,60]
## (60,70]
## (70,75]
## (75,80]
Ihr werdet sehen, vor allem bei grossen Datentabellen ist diese Funktion extrem hilfreich.