deselect matrix columns using subsed and !grepl functions - grepl

I have a single cell RNA sequencing matrix 'dta' with some cells named with KK00 (KK00.xx).
I would like to deselect all these cells.
So I wrote dta.s <-subset(dta, !grepl('KK00',colnames(dta)))
It didn't give error but it seems KK00.xx cells are still there when I check by table(sapply(strsplit(colnames(dta.s), "\\."), function(x) {x[1]})).
Can someone help?
Best

I've solved the problem.
I changed this
dta.s <-subset(dta, !grepl('KK00',colnames(dta)))
to this
dta <- dta[,!grepl('KK00.', colnames(dta))]
Now, it works.

Related

How to use cell value instead of number

Im sorry I dont even know how to correctly phrase this question.
The line of code I need to edit is this;
sheet.getRange(targetcell).setValue('=INDEX(QUERY(IMPORTHTML("http://www.futbin.com/consumables/Position%20Change","table",2),"select Col2"),1)');
However instead of row 1, I want to use the value from cell G1. So, something like this;
sheet.getRange(targetcell).setValue('=INDEX(QUERY(IMPORTHTML("http://www.futbin.com/consumables/Position%20Change","table",2),"select Col2"),G1)');
However, this throws an error.
Could anyone advise how I can use the value in G1 instead of it being fixed?
Thank you.
Try .setFormula instead of .setValue ...
sheet.getRange(targetcell).setFormula('=INDEX(QUERY(IMPORTHTML("http://www.futbin.com/consumables/Position%20Change","table",2),"select Col2"),G1)');
If there were a column G from the table that results from that IMPORTHTML function then you would use this:
sheet.getRange(targetcell).setValue('=INDEX(QUERY(IMPORTHTML("http://www.futbin.com/consumables/Position%20Change","table",2),"select Col7"),1)');
Because G is column 7
However, there is only 3 columns from that IMPORTHTML. You can check this by entering the formular into a Google Sheet:
=IMPORTHTML("http://www.futbin.com/consumables/Position%20Change","table",2)
I suggest playing around with your formula in SHeets and once you've got what you want, go back into AppsScript.

In R package Formattable, how to apply digits and conditional formatting at the same time?

I have the object TABLE_LIST which is a list that has tables (I can't provide the contents for privacy policies, sorry).
I first created the object TABLE_LIST (It is a list of data.frames 2x12)
TABLE_LIST=lapply(1:4, function(x) data.frame(rbind(total.ratio4[[x]][-(1)], total.ratio2[[x]][-(1)]), row.names=row))
The following code gives me red and green font colors based on the value on the cell, and it works like a charm:
formattable(TABLE_LIST[[1]], list(area(,-(c(5,10)))~formatter("span", style=x~style(color=ifelse(x>1,"red","green"))),area(,(c(5,10)))~formatter("span", style=x~style(color=ifelse(x>1,"green","red")))))
However, I need COLOR AND comma separated numbers. My failed attempt is:
formattable(TABLE_LIST[[1]], list(area(,-(c(5,10)))~formatter("span", style=x~style(color=ifelse(x>1,"red","green"))),area(,(c(5,10)))~formatter("span", style=x~style(color=ifelse(x>1,"green","red"),digits(x,2))),
area(1:2,1:10)~formatter("span",x~ style(digits(x,2)))))
This code works well, but erases the formatting of the color. I do not know what else to do.
I have to mention I cannot change the original data.frame without messing everything up. So I gotta make the changes on table_list or formattable. Thank you.
I think I solved it. So I will share this small knowledge to people who may have the same problems as me:
formattable(TABLE_LIST[[1]],
list(
area(,-(c(5,10)))~formatter("span",
style=x~style(color=ifelse(x>1,"red","green")),
x~style(digits(x,4))),
area(,(c(5,10)))~formatter("span",
style=x~style(color=ifelse(x>1,"green","red")),
x~style(digits(x,4)))))
Basically, inside the same formatter, on the level of style, add a comma and x~style.

How to use a conditional array formula in Google Sheets?

I want my spreadsheet user to be able to choose between two different options for an array formula. I have tried to put it in an IF statement but I can't get it to work. I do not want to cut and paste it down the column because I want it to be applies when a new row is added. I don't really know what I'm doing but I've been fiddling with it for a couple of hours now. Here is the code I currently have:
=IF($B$6="alternating days",ARRAYFORMULA(IF(ISBLANK(indirect("OVERVIEW!$A" & row())),IF($C2:C="l","l","d"),IF($C2:C="l","d","l"))),IF($B$6="weekdays/weekends",ARRAYFORMULA(IF(ISBLANK(indirect("OVERVIEW!$A" & row())),IF($C2:C="l","l","d"),IF(OR(WEEKDAY
(indirect("OVERVIEW!$A" & row()))=1,WEEKDAY(indirect("OVERVIEW!$A" & row()))=7),"l","d"))),"none"))
It's a long formula so please scroll along.
I attempted to have the ARRAYFORMULA at the beginning but it wouldn't let me reference just $B$6.
Thanks for any help you can provide.
I recommend something like this:
=ARRAYFORMULA(IF($B$6="alternating days",if(isodd(row(indirect("C4:C"&counta(OVERVIEW!A3:A)+3))),"l","d"),IF($B$6="weekdays/weekends",ARRAYFORMULA(IF(WEEKDAY(OVERVIEW!A3:A)=1,"d",if(WEEKDAY(OVERVIEW!A3:A)=7,"d","l"))))))
If the days are alternating, use odd rows to alternate the letter, otherwise just combine 2 IF statements to determine if it is a weekday or not.

Hide SSRS chart based on multivalue parameter

Good Afternoon,
I have a multivalue parameter where if the last value in the array has the value "Reentry", it should always display the report. However, if the last value in the array is not "Reentry" it should hide the chart because it doesn't apply to the other choice. The choices are Corrections, Reentry and All. I applied the following expression to the visibility option of the target chart.
=IIf((Parameters!Division.Value(Parameters!Division.Count-1)="Reentry"), True, False)
This is showing the report for all cases, even when I select only Corrections which is the value that appears in a textbox where I placed this expression, being the last value in the array.
=Parameters!Division.Value(Parameters!Division.Count-1)
I have tried all kinds of other ways to get this to work and I have been stuck for a day. I think this approach is the easiest but it is always showing the chart, no matter what is selected. Any thoughts? This shouldn't be so difficult...thanks in advance!
Try using this expression:
=IIF(
Array.IndexOf(Parameters!Division.Value,"Reentry")=
Parameters!Division.Count-1,True,False
)
Let me know if this helps.

(SSRS) if cell contains specific text then divide another cell by a number say 2

I'm having trouble trying to divide a cell by (A NUMBER) only if another cell contains specific text and if the cell contains another text i want it to be divide by a different number in SSRS
This is what i have but it is not working.
=IIF(Fields!PARTNO_LOT.Value=("A1001"),Fields!LOCSTOCK.Value/200)
I have added a example but in excel just to show my intent in SSRS.
If the above answer doesn't work, try this:
=Switch(
Fields!PARTNO_LOT.Value="A1001",Fields!LOCSTOCK.Value/200,
Fields!PARTNO_LOT.Value="A1002",Fields!LOCSTOCK.Value/285,
Fields!PARTNO_LOT.Value="A1003",Fields!LOCSTOCK.Value/89
)
Let me know if this helps.
If I understand correctly, you are trying to execute multiple conditions. You can use nested IIF statements:
=IIF(Fields!PARTNO_LOT.Value=("A1001"),Fields!LOCSTOCK.Value/200,
IIF(Fields!PARTNO_LOT.Value=("A1002"),Fields!LOCSTOCK.Value/285, Fields!LOCSTOCK.Value/89))
If your values are only few, this would work. If they are more than 2-3, I would look into creating a function. Reference: https://msdn.microsoft.com/en-us/library/ms156028.aspx