R use of where to select rows by matching an element from a list

0 votes
I'm trying to utilise R's "where" function in a loop to select a certain row from two datasets based on a matching element, and then plot the two together in a scatterplot. The row names of the two dataframes, as well as the loop, are provided in the code sample below. There are more counties in each dataframe than are listed in "mycounties."

I have used the "where" function in a loop exactly like this before, but this time R is returning the error message that "where" doesn't exist? I know "where" exists! My question is, how do I make R recognize this "where" structure, or is there a better way to pick out the rows I want to plot?
Jun 10, 2022 in Data Analytics by Avinash
• 1,260 points
941 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
There is no location function, as Jeff and the comments have stated. the R version of which.

You don't require which at all in this case, though:

x <- pm

PM$County == MyCountries[i], 2:48

dt$county == mycounties[i], 2:48; y - dt$county

A further if statement in your example is:

In the event that (mat$county[i] percent in percent dt5$county))

dt5[dt5$county == mat$county[i], 2:58] = mat[i,2:58]

}

That is presuming that each mat$county in your dt5$county only has one matching county. You'll receive an error if you don't.
answered Jun 24, 2022 by Sohail
• 3,040 points

edited Mar 5

Related Questions In Data Analytics

0 votes
1 answer

How do I remove an element from a list by index in R?

Use list[index] = NULL The list value will ...READ MORE

answered Oct 31, 2019 in Data Analytics by Cherukuri
• 33,050 points
2,447 views
0 votes
1 answer

How to remove an element from a list in R?

Hi@akhtar, You can remove a value from a ...READ MORE

answered Oct 30, 2020 in Data Analytics by MD
• 95,460 points
4,715 views
0 votes
1 answer

Dynamically select element from a list and work with it - Shiny R

Follow these steps: Import the data into R Check ...READ MORE

answered Dec 5, 2018 in Data Analytics by Maverick
• 10,840 points
3,942 views
0 votes
1 answer
+1 vote
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

answered Apr 14, 2018 in Data Analytics by Sahiti
• 6,370 points
7,432 views
0 votes
2 answers

R function for finding the index of an element in a vector?

The function match works on vectors : x <- sample(1:10) x # ...READ MORE

answered Dec 12, 2020 in Data Analytics by Rajiv
• 8,870 points
56,945 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,570 points
1,183 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
1,454 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
6,025 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
1,368 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP