I am trying to remove the duplicates of a master dataset with respect to a column, using "assign" does not work, the piece of the code is the following
varlist <- unique(Master_Data$Composite)
for (var in varlist){
assign(paste("Data_",var,sep=""),filter(paste("Data_",var,sep=""), !is.na(paste("Data_",var,sep=""))$Composite.T.))
}
The error I am getting is:
Error in UseMethod("filter_") :
no applicable method for 'filter_' applied to an object of class "character"
This is done relatively easy in SAS Macro, but I am sure R has features of it. Perhaps this has already been answered, I searched but couldn't find working solutions.
Thanks alot in advance,
M.
Related
I ran five models using the "gmnl" package in R. I would like to summarize all the models in one table using "mtable". However, I saw the message error below.
"Error in UseMethod("getSummary") : no applicable method for 'getSummary' applied to an object of class "gmnl""
The code to get the table is:
tablemod1 <- mtable("HCONT"=model.1_hcont, "HCT"=model.1_hct, "HBR"=model.1_hbr, "HCTBR"=model.1_hctbr, "NH"=model.1_nh,
signif.symbols = c("***"=0.01, "**"=0.05, "*"=0.1),
summary.stats = c("N", "Log-likelihood", "AIC", "BIC"))
summary(tablemod1).
I wonder if anyone knows how to fix that issue or recommends other ways to get models
side-by-side in one table.
Thank you,
Arsene
I am new to SparkR, so please forgive if my question is very basic.
I work on databricks and try to get all unique dates of a column of a SparkDataFrame.
When I run:
uniquedays <- SparkR::distinct(df$datadate)
I get the error message:
unable to find an inherited method for function ‘distinct’ for signature ‘"Column"’
On Stack Overflow, I found out that this usually means
(If I run isS4(df), it returns TRUE):
That is the type of message you will get when attempting to apply an S4 generic function to an object of a class for which no defined S4 method exists
I also tried to run
uniquedays <- SparkR::unique(df$datadate)
where I get the error message:
unique() applies only to vectors
It feels like, I am missing something basic here.
Thank you for your help!
Try this:
library(magrittr)
uniquedays <- SparkR::select(df, df$datadate) %>% SparkR::distinct()
library(mice)
md.pattern(dat1)
temp<-mice(dat1, m = 5, seed = 101)
dat1 <- complete(temp, 2)
Error in UseMethod("complete_") :
no applicable method for 'complete_' applied to an object of class "mids"
Hi, I'm trying to impute missing values using mice package.
But I got the above error message.
The first time I imputed missing data it worked, but when I tried again it didn't. I've tried a lot with different options (changing seed, deleting existing data or "temp" variable)
Sometimes it worked but other times it didn't.
What is the problem and solution?
Thanks in advance.
I think the problem here is that you should rather be using some other libraries in your program which have a function named "complete". Just typing "complete" in help menu gave me 2 other libraries (tidyr,RCurl) which have the function in the same name. As simon suggested, I tried using "mice::complete". It works for me.
Try this:
dat1<-mice::complete(temp,2)
mice 3.7.5 redefines the complete() function as the S3 complete.mids() method for the generic tidyr::complete().
Assuming that mice is attached, you should no longer see no applicable method for 'complete_' applied to an object of class "mids".
I am using quanteda to create a text corpus and trying to attach metadata, but I keep getting an error. I have used this code before on another dataset, but for some reason it's not working with my current dataset. The code is:
dfm.ineq1 <- corpus(df.ineq$speech,
docnames=df.ineq$speechID,
docvars=select(party))
The error I get is:
Error in select_(.data, .dots = lazyeval::lazy_dots(...)) : object
'party' not found
I also tried to put party in quotes and got this error:
Error in UseMethod("select_") : no applicable method for 'select_'
applied to an object of class "character"
The party column is pretty straight forward. The values are:
"Democratic" "Republican" "N/A" "Independent"
Any ideas on what might be going wrong?
An even easier way: use the fact that the corpus constructor method is defined for data.frame objects.
dfm.ineq1 <- corpus(df.ineq, text_field = "speech")
This will automatically load the text field in speech correctly, and include speechID and party as docvars.
I realized I forgot to put the dataframe in the select parenthesis!
dfm.ineq1 <- corpus(df.ineq$speech,
docnames=df.ineq$speechID,
docvars=select(df.ineq, party))
I am fairly new to R, so my apologies if this question is a bit silly.
I am calling a function in an external package ('mmlcr', although I don't think that is directly relevant to my problem), and one of the required inputs (data) is a data.frame. I compose the data.frame from various data using the following approach (simplified for illustration):
#id, Time, and value are vectors created elsewhere in the code.
myData = data.frame(a=id, b=Time, c=value)
out <- mmlcr( input1, input2, data=myData, input4)
Which throws the error:
Error in is.data.frame(data) : object 'myData' not found
The debugger indicates that this error is thrown during the mmlcr() call.
I then added a print(ls()) immediately prior to the mmlcr() call, and the output confirmed that "myData" was in my function workspace; further is.data.frame(myData) returned TRUE. So it seems that "myData" is successfully being created, but for some reason it is not passing into the mmlcr() function properly. (Commenting this line causes no error to be thrown, so I'm pretty sure this is the problematic line).
However, when I put the exact same code in a script (i.e., not within a function block), no such error is thrown and the output is as expected. Thus, I assume there is some scoping issue that arises.
I have tried both assignment approaches:
myData = data.frame(a=id, b=Time, c=value)
myData <- data.frame(a=id, b=Time, c=value)
and both give me the same error. I admit that I don't fully understand the scope model in R (I've read about the differences between = and <- and I think I get it, but I'm not sure).
Any advice you can offer would be appreciated.
MMLCR is now deprecated and you should search for some alternatives. Without looking too much into it, I sleuthed through an old repo and found the culprit:
m <- eval(m, data)
in the function mmlcr.default. There are a lot of reasons why this is bad, but scoping is the big one. R has this issue with the subset.data.frame function, see my old SO question. Rather than modify the source code, I would find a way to do your function with a subroutine using a for, repeat, or while loop.