Re: [R] How to check if a value of a variable is in a list

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Wed, 20 Apr 2011 10:41:45 +0200

On 20.04.2011 05:00, Frederik Lang wrote:
> Hi all,
>
>
> I am working with some social network analysis in R and ran into a problem I
> just cannot solve.
>
> Each observation in my data consists of a respondent, some characteristics
> and up to five friends. The problem is that all of these five friends might
> no show up later as a respondent (observation). Therefore I might not have
> characteristics on all the friends listed in the data and I want to restrict
> my data to only those friends that I also have as respondents. The data
> (without characteristics) look like this:
>
> *resp f1 f2 f3 f4 f5*
> ID1 ID5 ID37 ID6 ID2 ID53
> ID2 ID1 ID4 ID17 NA NA
> ...
>
> Now, let's say that "ID37" never appears as a respondent, then I want to
> replace that value with a NA so that it looks like this:
>
> *resp f1 f2 f3 f4 f5*
> ID1 ID5 NA ID6 ID2 ID53
> ID2 ID1 ID4 ID17 NA NA
>
>
> I thought I could check if for each entry, the value goes again in a list of
> the respondents.
>
> How do I do this?

See

?"%in%"

Uwe Ligges

>
> Kind regards,
>
>
> Frederik
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 20 Apr 2011 - 08:43:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Apr 2011 - 09:00:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive