Ищем функцию / код R Studi для перекрестных ссылок на переменные - PullRequest
0 голосов
/ 27 мая 2019

Буду признателен, если кто-нибудь посоветует мне, как установить связь между двумя переменными.Это может быть очень просто, но я новичок в R. Я не могу прикрепить фотографии того, как выглядит мой набор данных (X2015_11_metropolitan_stop_and_search), но вот dput по двум интересующим меня переменным:

dput(X2015_11_metropolitan_stop_and_search$Object of search)
c("Offensive weapons", "Controlled drugs", "Controlled drugs", "Fireworks", "Controlled drugs", "Stolen goods", "Controlled drugs", "Controlled drugs", "Offensive weapons", "Controlled drugs", "Fireworks", "Controlled drugs", "Controlled drugs", "Evidence of offences under the Act", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Offensive weapons", "Stolen goods", "Controlled drugs", "Controlled drugs", "Offensive weapons", "Offensive weapons", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs" )
dput(X2015_11_metropolitan_stop_and_search$Outcome)
c("Suspect arrested", "Nothing found - no further action", "Suspect arrested", 
"Nothing found - no further action", "Nothing found - no further action", 
"Nothing found - no further action", "Offender given drugs possession warning", 
"Nothing found - no further action", "Offender given drugs possession warning", 
"Nothing found - no further action", "Nothing found - no further action", 
"Suspect arrested", "Suspect arrested", "Offender given drugs possession warning", 
"Suspect arrested", "Suspect arrested", "Nothing found - no further action", 
"Nothing found - no further action", "Suspect arrested", "Nothing found - no further action", 
"Nothing found - no further action", "Suspect arrested", "Suspect arrested", 
"Nothing found - no further action", "Nothing found - no further action", 
"Nothing found - no further action", "Nothing found - no further action", 
"Suspect arrested", "Nothing found - no further action", "Nothing found - no further action", 
"Nothing found - no further action", "Nothing found - no further action", 
"Nothing found - no further action", "Nothing found - no further action", 
"Nothing found - no further action", "Nothing found - no further action", 
"Suspect arrested", "Nothing found - no further action", "Nothing found - no further action", 
"Suspect arrested", "Nothing found - no further action", "Nothing found - no further action", 
"Nothing found - no further action", "Suspect arrested", "Suspect arrested", 
"Nothing found - no further action", "Nothing found - no further action", 
"Nothing found - no further action", "Offender given drugs possession warning", 
"Suspect arrested", "Offender given penalty notice", "Nothing found - no further action")

Существует небольшое количество возможных значений для переменных «Объект поиска» и «Результат».Я хотел бы видеть значение «Объект поиска» для тех отдельных инцидентов, в которых значение «Результат» было «Подозреваемый арестован».Возможно ли это?

Если мне нужно добавить дополнительную информацию, пожалуйста, дайте мне знать.

1 Ответ

0 голосов
/ 27 мая 2019

Вы можете попробовать что-то вроде:

X2015_11_metropolitan_stop_and_search$Object of search[X2015_11_metropolitan_stop_and_search$Outcome == "Suspect arrested"]

, который будет возвращать все значения «Объекта поиска», которые имеют результат «подозреваемый арестован».Общей версией этого будет:

data$column1[data$column2 == "dataValue"]

Также проверьте, какая функция () возвращает индексный номер данных, которые соответствуют параметрам, указанным в функции.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...