Making one table in R - r

I am learning programming languages for the first time. I am trying to combine tables in R using:
Trip_data <- bind_rows(oct_td, sep_td, aug_td,jul_td, jun_td,may_td)
and I get the following error:
Error in bind_rows():
! Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'symbol'
Run rlang::last_error() to see where the error occurred.
What does that means? and how do I solve it?
I have another set of tables and I managed to combine them just fine, I also ran that yesterday and I did not get an error.

Related

Getting "attempt to apply non-function" to simple filtering function in RStudio

I'm a complete newbie trying to teach myself to code in R. I took an introductory R course, but it doesn't seem to have helped a ton.
I'm trying to create a dataframe from a table I'm accessing via a Snowflake database connection. The connection is working from what I can tell (it shows up in my connections and environment). The entire table is huge, so I'm trying to only capture the rows with a diagnosis matching the list of diagnosis codes I've loaded into the environment. I keep getting an error when using code that a coworker gave me.
I guarantee it's something stupid and simple, but I can't seem to figure it out.
I used the code below and got the following error, which to me says the reference to the local table of diagnosis codes is working. However, something seems to be not working with the reference to the column in the Snowflake table (HISTOLOGY_CD)?
bc_cr_gen <- tbl(snow_con,"REGISTRY_GENERAL") %>%
filter(HISTOLOGY_CD %>% local(BC_Diagnosis_Codes$Histology_Dx_Code), na.rm=TRUE) %>%
collect()
Error in HISTOLOGY_CD %>% c("85003", "85233", "85413", "85243", "85203", :
attempt to apply non-function

Error: object 'skim_without_charts' not found [duplicate]

I got the error message:
Error: object 'x' not found
Or a more complex version like
Error in mean(x) :
error in evaluating the argument 'x' in selecting a method for function 'mean': Error: object 'x' not found
What does this mean?
The error means that R could not find the variable mentioned in the error message.
The easiest way to reproduce the error is to type the name of a variable that doesn't exist. (If you've defined x already, use a different variable name.)
x
## Error: object 'x' not found
The more complex version of the error has the same cause: calling a function when x does not exist.
mean(x)
## Error in mean(x) :
## error in evaluating the argument 'x' in selecting a method for function 'mean': Error: object 'x' not found
Once the variable has been defined, the error will not occur.
x <- 1:5
x
## [1] 1 2 3 4 5
mean(x)
## [1] 3
You can check to see if a variable exists using ls or exists.
ls() # lists all the variables that have been defined
exists("x") # returns TRUE or FALSE, depending upon whether x has been defined.
Errors like this can occur when you are using non-standard evaluation. For example, when using subset, the error will occur if a column name is not present in the data frame to subset.
d <- data.frame(a = rnorm(5))
subset(d, b > 0)
## Error in eval(expr, envir, enclos) : object 'b' not found
The error can also occur if you use custom evaluation.
get("var", "package:stats") #returns the var function
get("var", "package:utils")
## Error in get("var", "package:utils") : object 'var' not found
In the second case, the var function cannot be found when R looks in the utils package's environment because utils is further down the search list than stats.
In more advanced use cases, you may wish to read:
The Scope section of the CRAN manual Intro to R and demo(scoping)
The Non-standard evaluation chapter of Advanced R
While executing multiple lines of code in R, you need to first select all the lines of code and then click on "Run".
This error usually comes up when we don't select our statements and click on "Run".
Let's discuss why an "object not found" error can be thrown in R in addition to explaining what it means. What it means (to many) is obvious: the variable in question, at least according to the R interpreter, has not yet been defined, but if you see your object in your code there can be multiple reasons for why this is happening:
check syntax of your declarations. If you mis-typed even one letter or used upper case instead of lower case in a later calling statement, then it won't match your original declaration and this error will occur.
Are you getting this error in a notebook or markdown document? You may simply need to re-run an earlier cell that has your declarations before running the current cell where you are calling the variable.
Are you trying to knit your R document and the variable works find when you run the cells but not when you knit the cells? If so - then you want to examine the snippet I am providing below for a possible side effect that triggers this error:
{r sourceDataProb1, echo=F, eval=F}
# some code here
The above snippet is from the beginning of an R markdown cell. If eval and echo are both set to False this can trigger an error when you try to knit the document. To clarify. I had a use case where I had left these flags as False because I thought i did not want my code echoed or its results to show in the markdown HTML I was generating. But since the variable was then used in later cells, this caused an error during knitting. Simple trial and error with T/F TRUE/FALSE flags can establish if this is the source of your error when it occurs in knitting an R markdown document from RStudio.
Lastly: did you remove the variable or clear it from memory after declaring it?
rm() removes the variable
hitting the broom icon in the evironment window of RStudio clearls everything in the current working environment
ls() can help you see what is active right now to look for a missing declaration.
exists("x") - as mentioned by another poster, can help you test a specific value in an environment with a very lengthy list of active variables
I had a similar problem with R-studio. When I tried to do my plots, this message was showing up.
Eventually I realised that the reason behind this was that my "window" for the plots was too small, and I had to make it bigger to "fit" all the plots inside!
Hope to help
I'm going to add this on here even though it's not a new question as it comes quite highly in the search results for the error:
As mentioned above, re checking syntax, if you're using dplyr, make sure you have all the %>% pipes at the end of the lines above the error, otherwise the contents of anything like a select statement won't pass down into the next part of the code block.

What causes this? rdplot Error in R: Error in seq.default(x_min, c, jump_l) : invalid '(to - from)/by'

I am trying to use some very simple data in rdplot but I keep getting the error: Error in seq.default(x_min, c, jump_l) : invalid '(to - from)/by' I found this response from a diffrent post on Stack Overflow but can seem to apply the fix to the rdplot function. does anyone know how can this be fixed?
The actual code I am using is:
library(rdrobust)
rdplot(y = dt$treated, x = dt$score)
Reproducibility:
Here is a sample of my data, as I've said it is fairly common data. So far I have found a couple of things:
There are multiple subsets of the observations that seem to cause problems
Changing the nbins or binselect arguments from their default will fix the problem
The first time you get an error is on the set 1:1463, however using only observations 2:1464 is OK.
The recent rdrobust version 1.0.1 should take care of this error.

R error "can't combine <character> and <double>?

I'm having an issue with a dataset that my team and I are working on. When trying to mutate a few variables into a new variable (named EU) here, this error pops up saying:
[Error: Problem with 'mutate()` input `EU`.
x Can't combine `...` <character> and `..2` <double>.]
I should note that my team and I all get this issue, but not always in the same part of the script. We've all updated our software to match and it still seems to happen.
Does anyone know how to fix this?? Thank you for any suggestions! We are learning as we go :)

R imbalance package Error in Ops.data.frame(dataset[, classAttr], minorityClass) ‘==’ only defined for equally-sized data frames

So whenever I try to use some imbalance function on my dataset I get this error:
Error in Ops.data.frame(dataset[, classAttr], minorityClass) :
‘==’ only defined for equally-sized data frames
This is my code:
dset <- read_csv("C:/Users/Downloads/streaming.csv") %>% select(-X1)
head(dset, 10)
imbalanceRatio(dset, classAttr = "cont_subs")
The task is a binary classification of whether the user continues his subscription to the service or not, with the "cont_subs" column containing only "Yes" or "No"
There was a similar question where the fix was adding classAtr to the function but adding classAtr to the function for me causes this error. So far I wasnt able to find someone getting the same error using the same package.
If I remove the classAtr from the imbalanceRatio func I get
Error: Can't subset columns that don't exist.
x The column `Class` doesn't exist.
Run `rlang::last_error()` to see where the error occurred.
I'm new to R so excuse me if there's something obvious I'm missing.

Resources