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

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 :)

Related

Making one table in 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.

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

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.

dplyr rename command with spaces

I have tried multiple variations of the rename function in dplyr.
I have a data frame called from a database called alldata, and a column within the data frame named WindDirection:N. I am trying to rename it as Wind Direction. I understand creating variable names containing spaces is not a good practice, but I want it to be named as such to improve readability for a selectInput list in shiny, and even if I settle for renaming it WindDirection I am getting all of the same error messages.
I have tried:
rename(alldata, Wind Direction = WindDirection:N)
which gives the error message:
Error: unexpected symbol in "rename(alldata, Wind Direction"
rename(alldata, `Wind Direction` = `WindDirection:N`)
which does not give an error message, but also does not rename the variable
rename(alldata, "Wind Direction" = "WindDirection:N")
which gives the error message:
Error: Arguments to rename must be unquoted variable names. Arguments Wind Direction are not.
I then tried the same 3 combinations of the reverse order (because I know that is how plyr works even though I do not call it to be used using the library command earlier in my code) putting the old variable first and the new variable 2nd with similar error messages.
I then tried to specify the package as I have 1 example below and tried all 6 combinations again.
dplyr::rename(alldata, `Wind Direction` = `WindDirection:N`)
to similar error messages as the first time.
I have used the following thread as an attempt to do this myself.
Replacement for "rename" in dplyr
as agenis pointed out, my mistake was not redefining the dataframe after renaming the variable.
So where I had
dplyr::rename(alldata,Wind Direction=WindDirection:N)
I should have
alldata <- dplyr::rename(alldata,Wind Direction=WindDirection:N)

R Language: Error in read.table(file.path(data.dir, file_name1)) : no lines available in input

I am having a hard time coding in R language. What I am trying to do is read large amount of data in to one data frame, and make pretty pictures.
This is what I have:
# assign data
file_name1<-"data1_txt"
file_name2<-"data2_txt"
data.dir<-"/...../Documents/R programing Language/"
for(i in 1:length(1)){
newData1<-read.table(file.path(data.dir, file_name1))
#Replace negative numbers with NA
xx <- which(datavalues<0)
datavalues[xx] <- NA
newData2<-read.table(file.path(data.dir,file_name2))
}
Error I have is:
Error in read.table(file.path(data.dir, file_name1)) :
no lines available in input
I am trying to figure out by myself, but I am very new to R language, and I don't have enough knowledge of functions in R. Please explain what this error means and advice on my coding.
Thank you very much,
Uka
Similar situation was solved here with similar question (I know this post is quite old). Recently I got such error parsing several files... The reason was some files were empty which makes sense of error message.
Anyway, just make sure your input will not be empty using try ou trycatch as suggested on mentioned link.

Resources