1

I am looking for a code to use in RStudio that will identify values from column B if the value in the same row in column A is less than x.

Specifically, if a value in column N_LOG is greater than 0.67, then I would like to know what the value is from the ACTIVITY_ACTION_ID column. The output can be a list or a table. Below is a picture of what my data looks like.

Snip of my data, called eLINK

Thank you for your help.

UPDATE: I got an solution from a friend at work if anyone else is looking at this post in the future and needs the answer. Either of the lines below would work.

head( with(eLINK_Sediment, eLINK_Sediment[0.67 < N_LOG,"ACTIVITY_ACTION_ID"]) )

head( subset(eLINK_Sediment, 0.67 < N_LOG, ACTIVITY_ACTION_ID) )

So for example,

head( with(filename, filename[value of interest < column to compare to value,"data from column you want"]) )

Emily
  • 11
  • 1
  • 3
  • try `df <- read.csv("Absolute_path_of_your_csv/your_csv.csv"); df_new <- df[df$N_LOG < 0.67, "ACTIVITY_ACTION_ID"]; head(df_new)`. Note that the issue is not related to 'rstudio' but `r` so in future you might need to tag your question with `r` and certainly [this link](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) will help you get more responses. – Prem Dec 20 '17 at 06:28

1 Answers1

1

You could add another column to your data which based on an ifelse statement which lists the variable you are interested in listing if your criteria is met.

e.g.

data_$NEW_COLUMN_NAME <- ifelse( data_$N_LOG > 0.67, ACTIVITY_ACTION_ID, " ")

Ifelse is handy because it creates an if statement in 1 line of code and it can handle vectors, unlike normal if statements.

JamesR
  • 613
  • 8
  • 15