0

I'm working a social network project where middle school students report their friends along with several qualities about themselves. I'm using R for analyses, and I'm trying to create a new variable that represents friends scores on social values.

So, let's say I have the following data:

enter image description here

I'd like to create a function that adds a new column labeled "FRIEND_VALUES" based on the ID Number mentioned in the FRIEND column. So the function would need to pull the VALUE for the ID based on what is listed in the FRIEND column. The final product would look like this:

Processed Data

In this scinareo, "ID" and "FRIEND" both represent ID numbers. The value of "FRIEND_VALUE" = the number of "VALUES" for the FRIEND ID. So, for ID 1, FRIEND = 2. The FRIEND_VALUE column should = the number under VALUE for ID 2 (which is 1.3).

**Note: I apologize for the images. I'm new to stackoverflow and need some practice.

boosterh
  • 1
  • 2
  • 1
    You seem to have posted the same image twice. But rather than posting images, see how to create a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This would be a good question for you to practice on. – MrFlick Mar 12 '20 at 20:19
  • Your reproducible example also needs to show/tell us what mathematical operation is performed on VALUES and FRIEND to derive FRIEND_VALUES. – Josh Mar 12 '20 at 20:34
  • 1
    You can lookup : `df["FRIEND VALUE"] <- df[df$FRIEND,"VALUE"]` – HubertL Mar 12 '20 at 20:43
  • Ah, thank you both for the help. The FRIEND_VALUES = VALUES for the ID listed under FRIEND. So the "2" under FRIEND means I need the "VALUES" for ID 2 (which = 1.3) to be populated in FRIEND_VALUES. I need to do this for ~213 cases – boosterh Mar 12 '20 at 20:50

0 Answers0