I am trying to make a loop for my dataset 'data1' to check and make a sum of the variable 'hours2015' in case the type of caregiver is the same (string variable= doctor, nurse, physical therapist, etc. So for each type of caregiver I would like to make the sum of total hours worked in 2015. I keep getting a syntax error messages. I can't seem to get the code right. Can anyone help me please? Thanks!
for(i in 1:133) {
totalhours2015[i] <- data1$hours2015[i] + data1$hours2015[i+1]
if {("data1$typecaregiver" [i] == "data1$typecaregiver" [i+1]) }
}
Error: unexpected 'if' in:
"for(i in 1:133){ .
totalhours2015[i] <- newrusthuizendata$uren2015[i] + newrusthuizendata$uren2015[i+1] if"
}
Error: unexpected '}' in "}"
Related
I am trying to change the name of a variable within a loop using select(). This is the code:
sibling_list2 = paste0("Sibling_", unlist(sibling2))
for(s in 2:length(sibling_list2)) {
dbAppendTable(conPrueba, paste0("EW_x", y),
dat %>%
inner_join(child2 %>% filter(relcode == 1) %>%
select(rel_f_person_id = person_id, person_id = sibling_list[s], (sibling_list[s] = Sibling_1), sibling_list),
by = c("person_id", "rel_f_person_id")))
}
However I get the error "Error in select():
! object 'Sibling_1' not found
Run rlang::last_error() to see where the error occurred." even though the object Sibling_1 exists.
The problem seems to be in "(sibling_list[s] = Sibling_1)". If i delete the parentheses I get another error saying "Error: unexpected '=' in:...". I also tried using the functions mutate() and rename(), but they have the same error.
I am stuck on this line of code and keep getting a syntax error. Any help would be appreciated.
Setting up parameter grid to tune the hyperparameters
param_grid = {'k': [10,20,30], 'min_k': [3,6,9],'sim_options': {'name': ['msd', 'cosine'],'user_based': [False]}
Performing 3-fold cross validation to tune the hyperparameters
gs = GridSearchCV(KNNBasic, param_grid, measures=['rmse', 'mae'], cv=3, n_jobs=-1)
Fitting the data
gs.fit(data)
Find the best RMSE score
print(gs.best_score['rmse'])
Find the combination of parameters that gave the best RMSE score
print(gs.best_params['rmse'])
File "", line 5
gs = GridSearchCV(KNNBasic, param_grid, measures=['rmse', 'mae'], cv=3, n_jobs=-1)
^
SyntaxError: invalid syntax
I am writing a script to add one line in a .txt per video while using MPV.
However, I am getting a weird error on line 68 with the for loop.
It merely tells me: no error. If I add an error parameter to file:write(message, error), it gives me another error message, stating: bad argument #2 to 'write' (string expected, got function). Any help would be appreciated.
function on_file_end(event)
if not paused then totaltime = totaltime + os.clock() - lasttime end
local message = (totaltime .. "s, " .. timeloaded .. ", " .. filename)
local lines = {}
local file = io.open(logpath, "r+")
if file_exists(logpath) then
for l in file:lines() do
if not l:find(message, 1, true) then
lines[#lines+1] = 1
file:write(message)
end
end
file:close()
end
end
bad argument #2 to 'write' (string expected, got function)
error is not an "error parameter" it is a global function that allows to raise your own errors in Lua.
See https://www.lua.org/manual/5.4/manual.html#pdf-error
I want to create a for loop when the variable is in a string format.
my code is:
for i in range(1,32):
DEP_RATE = pd.read_sql_query('select DAYNUM,YYYYMM,sum(DEP_RATE) from ASPM.aspm_qtr where LOCID="ABQ" and DAYNUM = i:"{i}" group by YYYYMM',{i:str(i)},rconn)
the error is:
'dict' object has no attribute 'cursor'
I used this code:
for i in range(1,32):
DEP_RATE = pd.read_sql_query('select DAYNUM,YYYYMM,sum(DEP_RATE) from ASPM.aspm_qtr where LOCID="ABQ" and DAYNUM = "i" group by YYYYMM',rconn, params={i:str(i)})
It hasn't error but doesn't work. the problem is:
("Truncated incorrect DOUBLE value: 'i'")
This appears to be a PANDAS question, yes? I believe it's an argument mismatch with the read_sql_query API. The function signature is:
pandas.read_sql_query(sql, con, index_col=None, coerce_float=True, params=None, parse_dates=None, chunksize=None)
Which roughly says that the first two positional arguments are required, and everything else is defaulted or optional.
To make it more obvious, consider putting your core SQL string on a separate line:
sql = 'SELECT daynum, ... AND daynum = :i'
for i in range(1, 32):
DEP_RATE = pd.read_sql_query(sql, {i: str(i)}, rconn)
With this formulation, it's more obvious that your arguments do not match the API: your second argument is off. Perhaps you want (note the additional keyword argument params):
DEP_RATE = pd.read_sql_query(sql, rconn, params={i: str(i)})
I corrected the code. The correct answer is:
DEP_RATE = list(np.zeros((1,1)))*31
for i in range(1,32):
DEP_RATE[i-1] =np.array(pd.read_sql_query('select DAYNUM,YYYYMM,sum(DEP_RATE) from ASPM.aspm_qtr where LOCID="ABQ" and DAYNUM = '+str(i)+' group by YYYYMM;',rconn, params={i:str(i)}))
I've been doing this for a couple of days, and I'm having this problem:
Whenever I try to encode a map into query string, I get the error "syntax error before: chat_id"
form = %{
"chat_id" => 237799109,
"text" => "OMG a message"
}
{status, body} = URI.encode_query(form)
#=> (SyntaxError) lib/elixir.ex:20: syntax error before: chat_id
But as far as I know this is the map syntax, isn't it? As seen here, where this example is presented:
iex> hd = %{"foo" => 1, "bar" => 2}
iex> URI.encode_query(hd)
"bar=2&foo=1
What is happening here?
Full error message:
== Compilation error on file lib/elixir.ex ==
** (SyntaxError) lib/elixir.ex:20: syntax error before: chat_id
(elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.Paral
lelCompiler.spawn_compilers/1
I don't know why you would get the error you listed, but URI.encode_query/1 only returns a single binary argument. You are trying to pattern match it against a tuple.
Can you paste more of the code instead of just those 2 lines?
iex(2)> URI.encode_query(form)
"chat_id=237&text=OMG+a+message"