ASJ
December 11, 2019, 9:37am
1
Hi,
I keep getting, "object 'sexe' not found", when trying to call the variable 'sexe' from my dataset.
names_fr <- readr::read_delim(my_url05, "\t") %>% filter(my_url05, sexe == 2, !is.na(preusuel), annais != "XXXX", preusuel !="_PRENOMS_RARES") %>% complete(preusuel, annais) %>% mutate(nombre = ifelse(is.na(nombre), 0, nombre), sexe = ifelse(is.na(sexe), 2, sexe)) %>% select(-sexe)
Im still quite new to R, so the problem might lay in the way data are loading.
Im asked to load data from an url:
my_url05 <- "https://perso.telecom-paristech.fr/eagan/class/igr204/data/nat1900- 2017.tsv"
names_fr <- readr::read_delim(my_url05, "\t")
An object called "my_url05" are created, holding the url.
Also a spec_tbl_df are created:
`` names_fr`
A tibble: 1 x 1
https://perso.telecom-paristech.fr/eagan/class/igr204/data/nat1900-
1 2017.tsv `
When i load the data "manually", by downloading the dataset myself an placing it in an object, it does contain the variable called "sexe".
R is the latest version and packages are updated.
What else might be the problem?
Thank you
FJCC
December 11, 2019, 1:43pm
2
It seems the read_delim() function is working and I see a problem with the next step.
readr::read_delim(my_url05, "\t") %>%
filter(my_url05, sexe == 2, !is.na(preusuel), annais != "XXXX", preusuel !="_PRENOMS_RARES")
The %>% operator takes the object on its left side and passes it as the first argument to the function on its right side. The code above the same as
filter(readr::read_delim(my_url05, "\t"), my_url05, sexe == 2, !is.na(preusuel), annais != "XXXX", preusuel !="_PRENOMS_RARES")
What you want is
readr::read_delim(my_url05, "\t") %>% filter(sexe == 2, !is.na(preusuel), annais != "XXXX", preusuel !="_PRENOMS_RARES")
so that the data frame returned by read_delim becomes the first argument of the filter function.
1 Like
ASJ
December 11, 2019, 4:34pm
3
Thank you. Same solution was suggested in Stack Overflow. It didn't result in any changes. I fear that the cause is found in some blop in a package or other because the code I've copied was made by the professor. I guess those can be wrong too.
The URL you are showing doesn't seem to be a valid one, it returns "404 Not Found" error, so, to help us help you, could you please prepare a repr oducible ex ample (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
system
Closed
January 1, 2020, 4:46pm
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.