How do I retrieve data for a specific date in r? - r

Let's say if I want to retrieve the closing price for a cryptocurrency on 2022-09-01. I am sure my code is not correct.
BTC.todays_price <- BTC.charts$close %>% filter(BTC.charts$date = '2022-09-01')
Thanks in advance!

Try the following to conditionally select:
BTC.charts[BTC.charts$date == '2022-09-01', ]$close

Related

Creating a loop to read from rows in R

I need to read data from each row of a column and replace it in a link for my web-scrapper project, however, I am not able to iterate over the rows, here is my code:
topic <- read.csv("C:/Users/Downloads/amazon-healing-crystals-keywords.csv", header = TRUE)
for (page_topic in names(topic)) {
print(topic[page_topic])
link <- paste0("https://www.amazon.com/s?k=",
page_topic,
"&crid=3KTKLIKI4L0DQ&sprefix=",
page_topic,
"%2Caps%2C160&ref=nb_sb_noss")
}
Your help would be greatly appreciated. Thank you!

mongolite filtering with dynamic array in r shiny

I have a select input with multiple options and my Mongo query
Here is the array if elements:
c<- c("elen","shallen")
query1 <- paste0('{"client": {"$in"["',c,'"]}')
#sales info is the data base
salesinfo$find(fields = '{"store":true,"_id":false}',query = query1)
Error: Invalid JSON object: {"client": [ elen ]}{"client": [ shallen ]}
this isn't working please help me please remember that it is a dynamic array and the values will change
After extensive research i found a way to solve the issue and i hope my solution will help out guys like me.
q1=paste(shQuote(c, type="cmd"), collapse=", ")
this step is to ensure you print out the array as a string and then use the query
query =paste0('{"store":{"$in":[',q1,']}}')
and the next step would be incorporating it to the query
salesinfo$find(fields = '{"store":true,"_id":false}',query = query)

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.

If inside of double loop

Inside of double loop I create subset of data for each combination of Tv stations with months which is done by loops. For example I have monthsnumbers 7,8,9 and stations A,B,C. It happens that for Month 9 there is no station C.
Then subset is empty and function throws and error of no possible aggregation.
So as you can see I tried to use if statement that if there are 0 rows don't continue with the code but go on to the next loop.
But I still get the same error fck. message
can you please navigate me ?
for (Mesic in monthnumbers){
for (Stanica in TVstations){
Client<-data[data$month ==Mesic & data$Channel_group1 ==Stanica & data$Brand == brand, ]
if (nrow(Client)!=0)
###some code
Client_AGG<-aggregate(formula= Client$BUYING_GRPs ~ Client$Brand,data= Client,FUN = sum)
###some code
}
}
}
Like Gregor commented, there is likely a better way of going about this.
But a quick patch might be to put the error check before the Client<- line because that's where it's looking for a channel that doesn't exist. Check if data$Channel_group1 == Stanica even exists before trying to get data from it.
Another option using for loops is to cycle through what you know is there with something like this:
subsetindex <- unique(data[ ,c('month','Channel_group1')])
for(i in 1:nrow(subsetindex)){
Client<-data[data$month ==subsetindex[i,'month'] & data$Channel_group1 ==subsetindex[i,'Channel_group1'] & data$Brand == brand, ]
#other code
}

A simple clarification on informatica mapping logic

I have to work on transformation
Can anyone help me on writing a query for the below transformation
Source Column name (from lookup)
Source table (local_usr_tbl)
Lookup_1:(rpt_user_tbl)
INPUT CON_NUM,ML_SYMBL
MATCH CONDITION NBR = CON_NUM AND SYMBL = ML_SYMBL1
Output SYMBL
TRANSFORMATION LOGIC::
IIF(ISNULL(SYMBL), IIF(ISNULL(SYMBL1), ML_SYMBL1, SYMBL1), SYMBL )
Target Column name ML_SYMBL1(rpt_remote_table)
Please explain me how to make this transofrmation.I have all the other columns as direct move.Please help me out
This query might help you in testing :
select rpt_remote_table.ML_SYMBL1,local_usr_tbl.ML_SYMBL from local_usr_tbl, rpt_remote_table where local_usr_tbl.SYMBL is null and local_usr_tbl.SYMBL1 is null

Resources