I am having problem with subset function in my code - r

I am trying to run this code in which I need to get subset of my data set but whenever I try running the code I get the error:
Error in subset.default(., select = c("Fluconazole (16 ug/ml)", "Fluconazole (32 ug/ml)", :
argument "subset" is missing, with no default
This is the code I run
df.fluco.hmf <- 'Phenotyping.All.scaled2.txt' %>%
subset(select = c( 'Fluconazole (16 ug/ml)',
'Fluconazole (32 ug/ml)',
'Fluconazole (64 ug/ml)',
'HMF (31.7 mM)',
'HMF (39.6 mM)',
'HMF (47.6 mM)')) %>%
as.data.frame()
and then I get this with the error message:
> df.fluco.hmf <- 'Phenotyping.All.scaled2.txt' %>%
> + subset(select = c( 'Fluconazole (16 ug/ml)',
> + 'Fluconazole (32 ug/ml)',
> + 'Fluconazole (64 ug/ml)',
> + 'HMF (31.7 mM)',
> + 'HMF (39.6 mM)',
> + 'HMF (47.6 mM)')) %>%
> + as.data.frame()
>
> Error in subset.default(., select = c("Fluconazole (16 ug/ml)",
> "Fluconazole (32 ug/ml)", : argument "subset" is missing, with no
> default

Related

I keep getting this dplyr and loadNamespaceerror message when trying to find the value of $1 invested 5 years ago

I'm very new to R, I have never used it before nor used any software programs besides Excel. For my class, we have to find 2 stocks and see how much $1 invested into these companies over the past 5 years will have given us returns. I have written the following code that all of the other students in my class have written. They all are able to get the plots and have the code working fine. But for me, I keep getting error messages. Please give advise me on how to fix it, thank you so much!
install.packages("tidyverse")
install.packages("tidyquant")
library("tidyverse")
library("tidyquant")
stock_names <- c("ENPH", "TEAM")
stocks <- tq_get(stock_names, from ='2017-01-01')
# daily data for the last 5 years
stocks_ret <- stocks %>%
group_by(symbols) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "daily",
col_rename = "ret")
stocks_ret <- stocks_ret %>% mutate(cumret =cumprod(1+ret))
stocks_ret %>% ggplot(aes(date, cumret, color = symbol)) +
geom_line() + ggtitle("Value of $1 invested 5 years ago")
But I keep getting this error message in the R Console
> Error in group_by(., symbols) : object 'stocks' not found
>
> stocks_ret <- stocks_ret %>% mutate(cumret =cumprod(1+ret)) Error
> in mutate(., cumret = cumprod(1 + ret)) :
>
> object 'stocks_ret' not found
>
> stocks_ret %>% ggplot(aes(date, cumret, color = symbol)) +
> geom_line()+ggtitle("Value of $1 invested 5 years ago")
>
> Error in ggplot(., aes(date, cumret, color = symbol)) :
>
> object 'stocks_ret' not found
>
> library("tidyverse")
> library("tidyquant")
>
> stock_names <- c("ENPH", "TEAM")
>
> stocks <- tq_get(stock_names, from ='2017-01-01') # daily data for
> the last 5 years
>
> Error in `dplyr::mutate()`:
>
> Problem while computing `data.. = purrr::map(...)`.
>
> Caused by error in `loadNamespace()`:
>
> there is no package called ‘lava’
>
> Run `rlang::last_error()` to see where the error occurred.

Translating Stata xtmelogit to R glmer (lme4) package

I try to recalculate exactly published Stata code in R. In the first step I exported the same dataset from Stata and Imported it in R. Nevertheless I am fighting with errors in my code.
What am I doing wrong?
Original Stata Code:
xtmelogit redpref1 c.incomedif c.incomedif#c.forpop forpop i.year if (brncntr==1) || country:
My Approach in R was:
dataset <- dataset%>%
filter(brncntr==1) %>%
mutate(c.incomedif = factor(incomedif))%>%
mutate(c.forpop = factor(forpop)) %>%
mutate(i.year = as.integer(year)))
library(lme4)
logit <- glmer(redpref1~ c.incomedif+ i.year|country,family=binomial,rueda4, nAGQ=0L)
summary(logit)
This approach generates an error as follows:
Error in if (ctrl$npt > (2 * n + 1)) warning("Setting npt > 2 * length(par) + 1 is not recommended.") :
missing value where TRUE/FALSE needed
In addition: Warning message:
In (n + 1L) * (n + 2L) : NAs produced by integer overflow
>

Error in mutate_impl(.data, dots) : attempt to use zero-length variable name

I was working in my laptop but and my code run without error. I used the same code and data in my PC but I get this error. I do not know what is the problem! everything was working in my laptop.
I have a .RDA file and when I view(my file) it seems good. I can delete some column and work with data. but when I want to use the
library(dplyr)
df<-df %>% mutate(`6-17` = 1* (AGE > 6 & AGE <= 17), `18-30`= 1*(AGE > 18 & AGE <= 30), `31-40` = 1* (AGE > 31 & AGE <= 40), `+41` = 1* (AGE > 41), )
I get that error!
Make sure you have same version of R and package version on your laptop and PC.
getRversion()
packageVersion("dplyr")

Mutate_impl error in running R code

Trying to run following R code.
> sp_500 <- sp_500 %>%
+
+ mutate(
+ stock.prices = map(ticker.symbol,
+ function(.x) get_stock_prices(.x,
+ return_format = "tibble",
+ from = "2017-01-01",
+ to = "2017-09-21")
+ ),
+ log.returns = map(stock.prices,
+ function(.x) get_log_returns(.x, return_format = "tibble")),
+ mean.log.returns = map_dbl(log.returns, ~ mean(.$Log.Returns)),
+ sd.log.returns = map_dbl(log.returns, ~ sd(.$Log.Returns)),
+ n.trade.days = map_dbl(stock.prices, nrow)
But I keep getting this error:
Warning: BRK.B download failed; trying again.
Error in mutate_impl(.data, dots) :
Evaluation error: BRK.B download failed after two attempts. Error message:
HTTP error 404..
Does anyone have an idea what am I doing wrong?
Best Regards
AnSa
It seems to have a problem downloading specific tickers. I am not a developer but I had the same problem as you do and fixed it by removing these tickers (less than 10). The code for removing them can be found on the same page where this piece of code is taken from and its
sp_500 <- sp_500 %>%
filter(ticker.symbol != "BRK.B")
I hope it helped.
Basically there is something wrong with the BRK.B stock, I'm not sure what it is, but the way to solve it is by eliminating it/them.
There are other stocks that get stuck in the function, this is how I solve it:
sp_500 <- sp_500[c(-72,-86, -82, -163, -268, -460, -392),] %>%
mutate(
stock.prices = map(ticker.symbol,
function(.x) get_stock_prices(.x,
return_format = "tibble",
from = "2007-01-01",
to = "2018-10-23")
),
log.returns = map(stock.prices,
function(.x) get_log_returns(.x, return_format = "tibble")),
mean.log.returns = map_dbl(log.returns, ~ mean(.$Log.Returns)),
sd.log.returns = map_dbl(log.returns, ~ sd(.$Log.Returns)),
n.trade.days = map_dbl(stock.prices, nrow)
)
The [c(-72,-86, -82, -163, -268, -460, -392),] are the stocks that didn't work for me because it display and error, basically find the columns in which you get errors by looking at the stock name and see in which columns they are and eliminate them
Hope it helps

Trinity failed with differential expression analysis test

I tried running the DE test that comes with Trinity after installing everything that's mentioned on their website, but ran into this error.
WARNING: This EdgeR comparison failed...
CMD: R --vanilla -q < Trinity_trans.counts.matrix.diauxic_shift_vs_plateau.EdgeR.Rscript
> library(edgeR)
>
> data = read.table("/usr/local/trinityrnaseq-r2013.02.25/sample_data/test_full_edgeR_pipeline/Trinity_trans.counts.matrix", header=T, row.names=1, com='')
> col_ordering = c(4,1)
> rnaseqMatrix = data[,col_ordering]
> rnaseqMatrix = round(rnaseqMatrix)
> rnaseqMatrix = rnaseqMatrix[rowSums(rnaseqMatrix)>=10,]
> conditions = factor(c(rep("plateau", 1), rep("diauxic_shift", 1)))
>
> exp_study = DGEList(counts=rnaseqMatrix, group=conditions)
Calculating library sizes from column totals.
> exp_study = calcNormFactors(exp_study)
> et = exactTest(exp_study, dispersion=0.1)
Comparison of groups: plateau - diauxic_shift
> tTags = topTags(et,n=NULL)
> write.table(tTags[tTags$table$PValue <= 0.05,], file='Trinity_trans.counts.matrix.diauxic_shift_vs_plateau.edgeR.DE_results', sep=' ', quote=F, row.names=T)
> source("/usr/local/trinityrnaseq-r2013.02.25/Analysis/DifferentialExpression/R/rnaseq_plot_funcs.R")
> pdf("Trinity_trans.counts.matrix.diauxic_shift_vs_plateau.edgeR.DE_results.MA_n_Volcano.pdf")
> result_table = tTags$table
> plot_MA_and_Volcano(result_table$logCPM, result_table$logFC, result_table$FDR)
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
Calls: plot_MA_and_Volcano -> plot_MA -> plot -> plot.default -> xy.coords
Execution halted
Error, cmd: R --vanilla -q < Trinity_trans.counts.matrix.diauxic_shift_vs_plateau.EdgeR.Rscript died with ret (256) at /usr/local/trinityrnaseq-r2013.02.25/util/..//Analysis/DifferentialExpression/run_DE_analysis.pl line 416.

Resources