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

From: Frederik Lang <frederiklang_at_gmail.com>
Date: Tue, 19 Apr 2011 23:00:00 -0400


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?

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. Received on Wed 20 Apr 2011 - 06:08:54 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 - 08:50: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