Error in loading "GaltonFamilies" dataframe in R - object not found - r

I am using the following code to get a set of heights sampled from GaltonFamilies
set.seed(1989, sample.kind="Rounding")
library(HistData)
data("GaltonFamilies")
female_heights <- GaltonFamilies%>%
filter(gender == "female") %>%
group_by(family) %>%
sample_n(1) %>%
ungroup() %>%
select(mother, childHeight) %>%
rename(daughter = childHeight)
But then I get the following error:
"Error in eval(lhs, parent, parent) : object 'GaltonFamilies' not found"
Any ideas on what could be going on?

Related

How can I write this SQL in R language

How can I convert this query into R.
Select Location, MAX(cast(Total_deaths as int)) as TotalDeathCount
From PortfolioProject..CovidDeaths
Where continent is not null
Group by Location
order by TotalDeathCount desc
I tried this but keeping getting an error.
library(dplyr)
library(tidyr)
covid_death %>%
drop_na() %>%
select(total_deaths) %>%
summarise(TotalDeathCount = max(total_deaths)) %>%
filter(continent != null)
Error in filter(., continent != null) :
Caused by error in `mask$eval_all_filter()`:
! object 'null' not found
The following should do:
covid_death %>%
drop_na() %>%
group_by(location) %>%
summarise(TotalDeathCount = max(total_deaths)) %>%
arrange(desc(TotalDeathCount))

Error in UseMethod("select") : no applicable method for 'select' applied to an object of class "c('integer', 'numeric')"

I am getting the above error message when I input the following syntax:
y <- mydata_final_distinct %>%
select(Case_ID,starts_with (Effect_)) %>%
pivot_longer(-Case_ID, names_to='symptoms', values_to=adr) %>%
distinct(Case_ID,'symptoms',adr,.keep_all = TRUE) %>%
count(adr) %>%
arrange(desc(n))
Although it is difficult to troubleshoot without having some of your data, I would first make the library explicit in the function calls, as it may be trying to use select from another library.
library(dplyr)
library(tidyr)
y <- mydata_final_distinct %>%
dplyr::select(Case_ID, starts_with (Effect_)) %>%
tidyr::pivot_longer(-Case_ID, names_to = 'symptoms', values_to = adr) %>%
dplyr::distinct(Case_ID, 'symptoms', adr, .keep_all = TRUE) %>%
dplyr::count(adr) %>%
dplyr::arrange(desc(n))

I am getting this error "Error: `n()` must only be used inside dplyr verbs" [duplicate]

The code in which I am getting the error.
numCrimesByLSOA<-crimes %>%
select(LSOA.code, LSOA.name, Crime.type) %>%
group_by(LSOA.code) %>%
summarise(Num.crimes=n())
Try with this as #BenBolker suggested:
#Code
numCrimesByLSOA<-crimes %>%
dplyr::select(LSOA.code, LSOA.name, Crime.type) %>%
dplyr::group_by(LSOA.code) %>%
dplyr::summarise(Num.crimes=n())

Error: in [Seize]->Timeout->[Release]: Expecting a single value: [extent=11]

I'm using R simmer to do a simulation. However, I receive this error message every time when I run it:
Error: 'truck0' at 48.73 in [Seize]->Timeout->[Release]: Expecting a
single value: [extent=11].
What is wrong with this?
This is my R script:
rm(list=ls())
#load packages
library(simmer)
library(simmer.plot)
#create an simulation environment
env <- simmer("Terminal")
env
#create a truck trajectory
truck <- trajectory("Truck path", verbose = TRUE)
truck
#draw model
truck %>%
seize("frontdesk",1) %>%
timeout(function() rnorm(11.27671,3.233562)) %>%
release("frontdesk",1) %>%
seize("gate-in",1) %>%
timeout(function() rnorm(17.54509,9.915719)) %>%
release("gate-in",1) %>%
seize("station",1) %>%
timeout(function() rnorm(12.68418,12.55247)) %>%
release("station",1) %>%
seize("lashing",1) %>%
timeout(function() rnorm(28.87726,21.0809)) %>%
release("lashing",1) %>%
seize("control",1) %>%
timeout(function() rnorm(12.70417,3.711475)) %>%
release("control",1) %>%
seize("frontdesk end",1) %>%
timeout(function()rnorm(11.27671,3.233562)) %>%
release("frontdesk end",1)
env <- lapply(1:100, function(i) {
simmer("Terminal") %>%
add_resource("frontdesk", 2) %>%
add_resource("gate-in", 2) %>%
add_resource("station", 1) %>%
add_resource("lashing", 15) %>%
add_resource("control", 1) %>%
add_resource("frontdesk end", 2) %>%
add_generator(name = "truck" ,
trajectory = truck,
distribution = function() rnorm(1,24.992,36.015)) %>%
run(660) %>%
wrap()
})
As the error indicates, timeout activities expect a single value, and you are providing 11 in this case. Because of this:
timeout(function() rnorm(11.27671,3.233562))
rnorm's first parameter is the number of samples (which is rounded to 11 in this case). What are you trying to do here? If that's supposed to be mean=11.27, sd=3.23, then you need to add
timeout(function() rnorm(1, 11.27671,3.233562))
so that you get a single sample per call, as required. And the same applies for all the other timeouts.
EDIT: Also, I do not recommend using a normal distribution for service times, because a normal distribution may return negative values (that are by default coerced to positive), and thus you may get unexpected results.

(...) is not a length 1 atomic vector error

I am trying to scrape IMDB data, and for one variable I keep getting an error.
Error: Result 28 is not a length 1 atomic vector
library(rvest)
library(purrr)
library(tidyr)
topmovies <- read_html("http://www.imdb.com/chart/top")
links <- topmovies %>%
html_nodes(".titleColumn") %>%
html_nodes("a") %>%
html_attr("href") %>%
xml2::url_absolute("http://imdb.com")
pages <- links %>% map(read_html)
budget <- try(pages %>%
map_chr(. %>%
html_nodes("#titleDetails .txt-block:nth-child(11)") %>%
html_text() %>%
#gsub("\\D", "", .) %>%
extract_numeric()),silent=TRUE)
When I do it with try (as in the code), I get
budget
[1] "Error : cannot convert object to a data frame\n" attr(,"class")
[1] "try-error" attr(,"condition") <Rcpp::exception: cannot convert
object to a data frame>
It would be great if anyone could tell me what is going wrong / why try isn't just skipping that result?
This can happen when you encounter NULL. Try:
map_if(is_empty, ~ NA_character_)
in the pipe chain and see if it works.

Resources