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

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Apr 20 10:41:45 CEST 2011



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.



More information about the R-help mailing list