2017-11-12 10 views
2

Ich habe es mit einem Datensatz zu tun, der eine große Anzahl von Variablen über die Befragung von Personen, die öffentliche Verkehrsmittel benutzen, hat.Plotten von Liker-Variablen in R

Angehängter Datensatz und CSV-Datei. Data Variables

Link zu Daten: https://drive.google.com/open?id=1MvfnwR4IkUyUzSnCuAOL8fxAYiDjBoBi

-Code den Datensatz zu lesen.

Die Elemente sind Likertskala (1-5) mit möglichen Antworten:

df = read.csv("PublicTransportSurvey.csv",sep=";", header = T, stringsAsFactors=TRUE) 
# Display the dataset and obtain overall summary of the dataset 
df <- subset(df, select = -Row_Num) 
View(df) 

Die Variablen können auch als die folgenden zusammengefasst werden stark (1) nicht übereinstimmen, nicht übereinstimmen (2), neutral (3) , stimme zu (3) und stimme voll und ganz zu (5).

Perceived Usefulness and Ease of Use 
PU1: PT information is easily accessible 
PU2: PT infrastructure is easily accessible 
PU3: The maps on PT infrastructure are helpful and clear 
PU4: PT tickets are easy to purchase 
PU5: PT connections in Adelaide are well integrated 
PU6: Waiting times for PT services are reasonable 


Perceived Enjoyment 
ENJ1: The views from PT in Adelaide are scenic 
ENJ2: Fellow passengers on PT in Adelaide are friendly 

Quality 
QU1: PT in Adelaide is reliable 
QU2: PT in Adelaide supports disabled travellers 
QU3: PT in Adelaide offers free wi-fi 
QU4: PT in Adelaide has a low carbon footprint 
QU5: PT in Adelaide is clean 


Safety and Security 
SS1: PT is safe in Adelaide 
SS2: Adelaide PT drivers handle unruly passengers 
SS3: PT shelters in Adelaide are well-lit at night-time 

Use Behaviour 
USE1: I use PT in the mornings only 
USE2: I use PT during off-peak times 
USE3: I use PT only during the evening 
USE4: I use PT during the week 
USE5: I use PT at the weekend 


PT Incentives 
INC1: I use PT to save money 
INC2: I use PT to protect the environment 
INC3: I use PT to exercise more 
INC4: I use PT to experience the city firsthand 

Information Access 
INF1: I access PT timetables and information using a mobile device 
INF2: I access PT timetables and information from a hotel concierge 
INF3: I access PT timetables and information on the platform 
INF4: I access PT timetables and information from a newsagency 
INF5: I access PT timetables and information from other commuters 

Aber, wenn wir das Dataset Variablen Bild, das ich angehängt habe, sehen, enthält es auch einige Werte über 1-5 hinaus.

Ich stecke in diesem Problem aus den letzten 4 Stunden und versuche zu suchen.

Mein ultimatives Ziel ist es, Ausreißer aus den obigen Variablen (über 5) zu entfernen und dann ein Likrt-Diagramm zu plotten. Bitte jemand schlägt mir vor, wie man das löst.

Vielen Dank im Voraus.

Antwort

0

Meine Lösung:

library(likert) 

df <- read.csv2("PublicTransportSurvey.csv") 

df <- df[,12:54] 
df[sapply(df, is.factor)] <- lapply(df[sapply(df, is.factor)], function(x) as.numeric(as.character(x))) 
df[sapply(df, is.character)] <- lapply(df[sapply(df, is.character)], function(x) as.numeric(as.character(x))) 

df <- data.frame(apply(df, 2, function(x) ifelse(x > 5, NA, x))) 
df <- data.frame(lapply(df, function(x) as.factor(x))) 

likert_df <- likert(df) 
plot(likert_df) 

Zunächst einmal habe ich die Spalten entfernt, die keine Variablen likert werden. Dann habe ich die Faktor- und Zeichenspalten in numerische Spalten umgewandelt und alle Werte größer als 5 durch NA ersetzt, da diese vom likert Paket ignoriert werden, soweit ich weiß.

Dann habe ich alle Spalten wieder in Faktoren umgewandelt, weil das von der Likert-Funktion benötigt wird. Der Code erzeugt dieses Bild:

enter image description here

+1

seine korrekte, danke. Aber ich habe es schon getan. Aber deine Lösung ist großartig. –

+0

Sie möchten wahrscheinlich darüber nachdenken, was Sie mit den Daten mit fehlenden oder fehlerhaften Zeilen machen. Ist die ganze Reihe schlecht? Nur diese Frage? – IanK