我正在处理数据集,该数据集包含大量关于使用公共交通工具的人员调查的变量。
附加数据集和csv文件。 Data Variables
数据链接:https://drive.google.com/open?id=1MvfnwR4IkUyUzSnCuAOL8fxAYiDjBoBi
读取数据集的代码。
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)
变量也可归纳如下:
项目是李克特量表(1-5),可能有回应:非常不同意(1),不同意(2),中立(3),同意(3)和非常同意(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
但是,如果我们看到我附加的数据集变量图片,它还包含一些超过1-5的值。
我在过去4个小时内陷入了这个问题并尝试搜索。
我的最终目标是从上述变量中删除异常值(大于5),然后绘制一个相似的图。请有人建议我,如何解决这个问题。
先谢谢。
答案 0 :(得分:0)
我的解决方案:
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)
首先,我删除了非Likert变量的列。然后我将因子和字符列转换为数字列,并用NA
替换了大于5的所有值,因为据我所知,likert
包会忽略这些值。
然后我将所有列转换回因子,因为likert函数需要这些因素。代码生成此图像: