I have column D:D with names and column G:G has the same names but with numbers at the end so if D1 matches any cell in G for example G4 I need the data from H4. This is what I have so far
=IF(REGEXMATCH(D2,G2),H2,"")
I also tried
=IF(REGEXMATCH(D2:D,G2:G),H2:H,"")
[screenshot of sheet]
In K2 try
=ArrayFormula(if(len(D2:D), iferror(vlookup(regexreplace(D2:D, "(\s\(\d+\))",), G2:H, 2, 0)),))
and see if that works?
Related
can someone tell me what formula can represent the following statement :
If in Cell A1 there's value A or B or C or D then Value X must Show up in cell B1
If in Cell A1 there's value E or F or G or H then Value Y must Show up in cell B1
Thanks a ton!
I have tried REGEXMATCH function, but I wasn't able to mesh all the variables.
Try:
=IFS(REGEXMATCH(A1,"A|B|C|D"),"X",REGEXMATCH(A1,"E|F|G|H"),"Y",1,)
I have two sheets, Sheet A containing a truth table like such:
A B C D E
Foo T F F T F
Bar T F F F F
Sheet B contains another table:
A B C D E
T F F T F
I need to add a column to table A counting how many cells match the corresponding cell in sheet B, as such:
Foo T F F T F 2
Bar T F F F F 1
Best I could come up with for the first count cell was
=COUNTIF(B2:F2,B2:F2=INDIRECT("sheet-b!A2:E2"))
but this gives me 0 even though it should be 2.
Edit:
I was able to come up with this, which correctly counts the number of differing cells:
=SUM(ARRAYFORMULA(IF(B2:F2=INDIRECT("sheet-b!A2:E2"),1,0)))
The next thing I want is to add an AND statement, and count the cell if it matches or if the sheet-b cell is F:
=SUM(ARRAYFORMULA(IF(AND("F"=INDIRECT("sheet-b!A2:E2"),B5:F5=INDIRECT("sheet-b!A2:E2")),1,0)))
However it doesn't seem like i can use an AND statement in this formula. Even the following gives a sum of zero:
=SUM(ARRAYFORMULA(IF(AND(TRUE,B2:F2=INDIRECT("sheet-b!A2:E2")),1,0)))
how come?
Edit2: Link to example spreadsheet
how do I get the count of non-matching cells in a row between two sheets
=ARRAYFORMULA(IF(LEN(A2:A),
MMULT(IF(B2:F='sheet-b'!A2:E2, 0, 1), TRANSPOSE(COLUMN(B2:F2)^0)), ))
try:
=ARRAYFORMULA(IF(A1:A<>"", COUNTIFS(TRIM(
TRANSPOSE(QUERY(TRANSPOSE(Sheet2!J1:N),,999^99))),
TRANSPOSE(QUERY(TRANSPOSE(B1:F) ,,999^99))), ))
Formula to compare B3 in sheet 1 to column A in sheet 2 (Defined Range Name - COUNTY). If they match then subtract the value of A3 from D2 OR compare C3 in sheet 1 to column A in sheet 2 (Defined Range Name - COUNTY). If they match then add the value of A3 to D2. This is what I have now and it is not adding or subtracting. It just carries down the previous total.
=IFERROR(SUMIFS(OR(VLOOKUP($B3,COUNTY),D2-$A3,OR(VLOOKUP($C3,COUNTY),D2+$A3))),D2)
You can do this by using MATCH combined with an ISERROR function.
In cell D3, write the following formula:
=D2 - IF(ISERROR(MATCH(B3,COUNTY,0)),0,A3) + IF(ISERROR(MATCH(C3,COUNTY,0)),0,A3)
You can copy this down in column D.
The way this works is that it starts with D2, then subtracts, using an IF/ISERROR:
By 0 (defined in formula), if U2 (cell B3) isn't in the range COUNTY because ISERROR would return TRUE
By 4 (cell A3), if U2 (cell B3) is in the range COUNTY, because ISERROR would return FALSE
The second part of the formula works the same way, but with an addition instead.
You can check references for the functions used here:
ISERROR
MATCH
you were close, but all your formulas after IFERROR are all wrong/incomplete. paste this into D3 cell and drag down:
=IF(REGEXMATCH(B3, TEXTJOIN("|", 1, County)), D2-A3,
IF(REGEXMATCH(C3, TEXTJOIN("|", 1, County)), D2+A3, D2))
using 3 columns 100k down column "a:a"= part desc with part number y400cc(webpage title) cell "b1"=old part number y400cc "c1"=new part number wpy400cc.
*****Find cell b2 in column a and replace with cell c2 ?***
I am not Sure I understood your question fully. But here is my proposal:
Column A contains some text (Example: CELL A2 = "xx456yy")
Column B contains a part number which may or may not be found in A (Example CELL B2 = "456")
Column C contains the new part number (Example: CELL C2 = "900")
Column D to have the following formula, which will replace the Column B text found in Column A, with Column C text:
=IF(IFERROR(FIND(B2,A2),1)<>1,REPLACE(A2,FIND(B2,A2),LEN(B2),C2),"")
I am fairly new to R so please go easy on me if this is a stupid question.
I have a dataframe called foo:
< head(foo)
Old.Clone.Name New.Clone.Name File
1 A Aa A_mask_MF_final_IS2_SAEE7-1_02.nrrd
2 B Bb B_mask_MF_final_IS2ViaIS2h_SADQ15-1_02.nrrd
3 C Cc C_mask_MF_final_IS2ViaIS2h_SAEC16-1_02.nrrd
4 D Dd D_mask_MF_final_IS2ViaIS2h_SAEJ6-1_02.nrrd
5 E Ee F_mask_MF_final_IS2_SAED9-1_02.nrrd
6 F Ff F_mask_MF_final_IS2ViaIS2h_SAGP3-1_02.nrrd
I want to extract codes from the File column that match the regular expression (S[A-Z]{3}[0-9]{1,2}-[0-9]_02), to give me:
SAEE7-1_02
SADQ15-1_02
SAEC16-1_02
SAEJ6-1_02
SAED9-1_02
SAGP3-1_02
I then want to use these codes to search another directory for other files that contain the same code.
I fail, however, at the first hurdle and cannot extract the codes from that column of the data frame.
I have tried:
library('stringr')
str_extract(foo[3],regex("(S[A-Z]{3}[0-9]{1,2}-[0-9]_02)", ignore_case = TRUE))
but this just returns [1] NA.
Am I simply missing something obvious? I look forward to cracking this with a bit of help from the community.
Hello if you are reading the data as a table file then foo[3] is a list and str_extract does not accept lists, only strings, then you should use lapply to extract the match of every element.
lapply(foo[3], function(x) str_extract(x, "[sS][a-zA-Z]{3}[0-9]{1,2}-[0-9]_02"))
Result:
[1] "SAEE7-1_02" "SADQ15-1_02" "SAEC16-1_02" "SAEJ6-1_02" "SAED9-1_02"
[6] "SAGP3-1_02"
str_extract(foo[3],"(?i)S[A-Z]{3}[0-9]{1,2}-[0-9]_02")
seems to work. Somehow, my R gave me
"Error in check_pattern(pattern, string) : could not find function "regex""
when using your original expression.
The following code will repeat what you asked (just copy and paste to your R console):
library(stringr)
foo = scan(what='')
Old.Clone.Name New.Clone.Name File
A Aa A_mask_MF_final_IS2_SAEE7-1_02.nrrd
B Bb B_mask_MF_final_IS2ViaIS2h_SADQ15-1_02.nrrd
C Cc C_mask_MF_final_IS2ViaIS2h_SAEC16-1_02.nrrd
D Dd D_mask_MF_final_IS2ViaIS2h_SAEJ6-1_02.nrrd
E Ee F_mask_MF_final_IS2_SAED9-1_02.nrrd
F Ff F_mask_MF_final_IS2ViaIS2h_SAGP3-1_02.nrrd
foo = matrix(foo,ncol=3,byrow=T)
colnames(foo)=foo[1,]
foo = foo[-1,]
foo
str_extract(foo[,3],regex("(S[A-Z]{3}[0-9]{1,2}-[0-9]_02)", ignore_case = T))
The reason you get NULL is hidden: R stores entries by column, hence foo[3] is the 3rd row and 1st column of foo matrix/data frame. To quote the third column, you may need to use foo[,3]. or foo<-data.frame(foo); foo[[3]].