Undefined columns selected - r

I've looked at some answers that were already posted here and was not quite able to find one that would help with my particular situation. I'm new to R so bear with me.
rm(list = ls())
dat=read.csv('C:\\Users\\Casandra\\Downloads\\roaches.csv',as.is=T)
ndata=nrow(dat)
param=read.csv('C:\\Users\\Casandra\\Downloads\\roaches+posterior+after+burnin.csv',as.is=T)
param.med=apply(param,2,mean)
yhat=param.med[1]+param.med[2]*dat$x
png('pred distribution.png')
plot(dat$x,dat$y,xlim=c(0,1),ylim=c(0,1.5),xlab='Covariate x',col='grey',ylab='')
lines(dat$x,yhat,col='red')
nsim=nrow(param)
yhat1=yhat2=matrix(NA,ndata,3)
for (i in 1:ndata){
media=param[,1]+param[,2]*dat$x[i]
yhat1[i,]=quantile(media,c(0.025,0.5,0.975))
tmp=rnorm(nsim,mean=media,sd=sqrt(param[,3]))
yhat2[i,]=quantile(tmp,c(0.025,0.5,0.975))
}
lines(dat$x,yhat1[,1],col='orange',lty=2)
lines(dat$x,yhat1[,3],col='orange',lty=2)
lines(dat$x,yhat2[,1],col='grey',lty=2)
lines(dat$x,yhat2[,3],col='grey',lty=2)
dev.off()
Above is my code and this is the error I am receiving
Error in[.data.frame(param, , 3) : undefined columns selected
The dat data set has 2 columns and the param data set has two as well.
Can anyone point me in the right direction for fixing my code?
Data sets are below:
dat: https://drive.google.com/file/d/0B9MIgQ2O0SHnakRzZ2p2bDhIZ2c/edit?usp=sharing
param: https://drive.google.com/file/d/0B9MIgQ2O0SHnTTVMU0E2TTRDR2M/edit?usp=sharing

Related

TypeError: argmax(): argument 'input' (position 1) must be Tensor, not str

My code was working fine and when I tried to run it today without changing anything I got the following error:
TypeError: argmax(): argument 'input' (position 1) must be Tensor, not str
Would appreciate if help could be provided.
below is the code snippet where I am getting an error. I am using BERT mdoel
start_scores, end_scores = model(torch.tensor([input_ids]), # The tokens representing our input text.
token_type_ids=torch.tensor(
[segment_ids])) # The segment IDs to differentiate question from answer_text
# ======== Reconstruct Answer ========
# Find the tokens with the highest `start` and `end` scores.
answer_start = torch.argmax(start_scores)
answer_end = torch.argmax(end_scores)
In your line of code
start_scores, end_scores = model(torch.tensor([input_ids]),token_type_ids=torch.tensor([segment_ids]))
you have to make it:
start_scores, end_scores = model(torch.tensor([input_ids]),token_type_ids=torch.tensor([segment_ids]), return_dict=False).
It worked for me. I had the same problem.

Keep getting ERROR: with function tabledap

I keep getting a returned "Error:" with my code but have no idea why when the same code works fine with a similar dataset.
Changed the observation variable, changed the time restrictions, searched for similar problems online
library(rerddap)
CalPoly = info("HABs-CalPoly", url= "http://erddap.sccoos.org/erddap/")
CalPoly_Data = tabledap(CalPoly,
fields = c('Ceratium','Cochlodinium', 'Dinophysis_spp', 'Gymnodinium_spp','time'),
'time>=2008-08-15T00:00:00Z', 'time<=2019-05-26T05:35:00Z')
Should return a data table but I just keep getting "Error:"
This similar code does work though and I have no idea why
CalCOFI = info('siocalcofiHydroCasts')
calcofi.df <- tabledap(CalCOFI,
fields = c('cst_cnt', 'date', 'year', 'month', 'julian_date', 'julian_day', 'rpt_line', 'rpt_sta', 'cruz_num', 'intchl', 'intc14', 'time'),
'time>=1984-01-01T00:00:00Z', 'time<=2014-04-17T05:35:00Z')
Resolved the issue!
I initially set the url correctly for the info argument, I didn't realize I had to set the url again for the tabledap argument. I did not realized it the Default is: https://upwell.pfeg.noaa.gov/ erddap/
Five hours later but at least it is resolved!
The code now works:
CalPoly_Data = tabledap(CalPoly, fields = c('Temp','time'),'time>=2008-08-15T07:00:00Z', 'time<=2019-05-26T07:00:00Z', url = "http://erddap.sccoos.org/erddap/")

Need to Print Value of a Variable using Paste in R

I am trying to create a data frame of various error messages based on Data to be cross checked between two dataframes and storing the message in a vector in an iterative manner . I am using the following snippet for this purpose :
> for(j in 1:nrow(MySQL_Data)){ date_mysql=
> paste("MySQL_Data[",j,",1]") date_red= paste("RED_Data[",j,",1]")
> body= c() if(!date_mysql == date_red) {
> body<- append(body,paste("'There is data missing for date",date_mysql,"in",table2)) }else {
> NULL }}
My table2 variable prints as MYSQL_Data[2,1] instead of the actual value of the variable which is a date
Following is the Output :
"'There is data missing for date MySQL_Data[ 2 ,1] in Dream11_UserRegistration"
Can someone help me with the error that I am committing here..
Thanks in Advance !
Your use of paste in the definitions of data_mysql and data_red makes no sense. I’m assuming that what you actually want is this:
data_mysql = MySQL_Data[j, 1]
data_red = RED_Data[j, i]
Furthermore, you’re resetting body in every loop iteration so it will only ever hold a single element.

Getting Error "could not find function "assign<-" inside of colnames()

I'm using assign() to assign some new data frames from some other data frame. I then want to name some of the columns in the new data frame. When I use assign() to create the new data frames it works fine. But when I use the assign() inside of colnames() is gives the error 'Error "could not find function "assign<-".'
Here's my snippet of code(abbreviated of course):
for(i in 1:value) {
assign(Name[i], Old.Data.Frame[Old.Data.Frame$1 == Index[i]]) #I'm going to call this line of code 'New Data Frame' for brevity
for(j in 1:ncol(New Data Frame)) {
colnames(New Data Frame)[j] = as.character(Old.Data.Frame[3,j])
I do all this assign() stuff because the names of the Old Data Frame constantly change and I can create any concrete variables in my code, only the dimentions of the frame stay the same.
The only error in this code is that R cannot "find function assign<- in colnames(...". I'm flustered because assign() had just worked in the line before, any help is appreciated, thanks!
You have a list of variable names in Name, which you assign a value (your code block).
for(i in 1:value) { assign(Name[i], Old.Data.Frame[Old.Data.Frame$1 == Index[i]]) }
Could you then try (note I'm separating this code block for debugging purposes):
for(i in 1:value) { colnames(get(Names[i])) <- as.character(Old.Data.Frame[3,] }
get will retrieve the data (data.frame) assigned to the variable name Names[i] (character)

Invalid number of breaks?

I'm trying to make a confidence interval for practice and I keep getting an error referring to:
an 'invalid number of breaks' at hist.default(boot.dist).
I'm pretty sure the problem is somewhere here.
Any advice or help would be very much appreciated at this point.
b=1000
boot.dist = rep(0,b)
for (i in 1:b) {
boot.sample = sample(ACS$Income, replace = TRUE)
boot.dist[i] = mean(boot.sample)
}
hist(boot.dist)
The problem is that ACS$Income is array of NA.
Example, this code will reproduce error exactly like yours:
boot.dist[1:1000]<-NA
hist(boot.dist )
Error in hist.default(boot.dist) : invalid number of 'breaks'

Resources