Cell value based on number of digits in another cell - vendor-prefix

If Cell in column A contains 3 digits then cell in Column B should reflect text as "00" and if cell in column A has 2 digits then Cell in Column B should reflect text as "000"

Does this help?
=IF(LEN(A1)=3,"00","000")

If you are indeed speaking of excel cells, then you should take a look into nested if statements.
I will leave the rest up to you as you have not yet shown enough proof that you have attempted to solve this problem.

Related

R: stacking up values from rows of a data frame

I started programming in R yesterday (literally), and I am having the following issue:
-I have a data frame containing R rows, and each row contains N values.
Rows are identified by the first and second field, while the other N-2 are just numerical values or NA.
-Some rows have identical first field and identical second field, something like:
row 1: a,b, third_field, .. ,last_field
row 2: a,b, third_field, .. ,last_field
the rule is that usually the first line will have its fields containing some numbers and some NA, while the second row will contain NA and numbers as well, but differently distributed.
What I am trying to do is to merge the two rows (or records) according to these two rules:
1) if both rows have a NA on a given field, I keep NA
2) if one of the two has a number, I use that value; if both of the rows contain the same value, I keep it also.
How do you do this without looping on each field of each row? (1M rows, tenths of fields, it will finish maybe tomorrow).
I do not know how to better explain my problem. I am sorry for the lengthy explaination, thanks a lot.
EDIT: it is better if I add an example. The following two lines
a,b,NA,NA,NA,1,2 ,NA
a,b,NA,3 ,NA,1,NA,NA
should become
a,b,NA,3 ,NA,1,2 ,NA

Change all cells marked X into cell value shown in column P

I need an easy way to convert all X's in a column into the value shown in a cell.
Basically we want to sell multiple products to a client with a target order value split amongst the relevant products - I have done a CountA formula to show how many columns are not blank. Then I did a simple divide to divide the total value over the columns that are not blank (if there are 2 columns marked X then it would be 10,000 / 2 - assuming the target value is 10k) Now I need to change all the X's into the figure shown in the cell as shown in the pic.
I cant for the life of me think of an easy way of doing it but sureley there is?
Screen shot of sheet
You need 2 sets of columns. Your first set has the X's and the blanks to mark which categories are applicable. The second set has the calculated values for the selected categories.
In the value columns, you can use a formula like the following for the first data row and first category:
=IF(E2 = "x", $D2, 0)
Assuming "D" is your "Dvided total" column, and "E" is your "Dairy & S..." column, and "2" is your first data row.

Remove rows where value is *not* in column on other sheet

I have a LibreOffice Calc file with two sheets. Sheet 2 has just one column A with lots of numbers. In sheet 1, column A of every row also holds a number. I want to remove all rows from sheet 1 that have a value in column A which does not appear anywhere in column A of sheet 2.
Filters don't seem to do the trick, as they don't have a "value must be contained in some column" operator.
Any ideas?
Enter the following formula in cell B1 of Sheet1:
=IF(ISNA(VLOOKUP(A1,Sheet2.A:A,1, 0)),"",A1)
Then drag to fill this formula down column B. This shows empty cells for all rows that do not occur in Sheet2.
To remove the empty rows, sort on column B (Data -> Sort). Then select and delete the empty rows (Edit -> Delete Rows).

Google Sheets - Count number of occurences of word BEFORE comma

I'm trying to count the number of times specific words, names in this case, occurs in a column. However, there may be any number of names in each cell in that column, and I'm only interested in the first one in each.
If there is more than one name in a cell, each of them is separated by a comma, and I'm hoping to use that in some way to ignore the names I don't want. It's very much like this question, the only difference is discarding everything after a comma.
Is there a way to do this in Sheets?
Does this formula work as you want (assuming your list of names is in the range A2:A):
=QUERY({ArrayFormula(IFERROR(LEFT(A2:A,SEARCH(",",A2:A)-1),A2:A)),A2:A},"select Col1, count(Col2) where Col1 <> '' group by Col1 label Col1 'Name'")

extract columns that don't have a header or name in R

I need to extract the columns from a dataset without header names.
I have a ~10000 x 3 data set and I need to plot the first column against the second two.
I know how to do it when the columns have names ~ plot(data$V1, data$V2) but in this case they do not. How do I access each column individually when they do not have names?
Thanks
Why not give them sensible names?
names(data)=c("This","That","Other")
plot(data$This,data$That)
That's a better solution than using the column number, since names are meaningful and if your data changes to have a different number of columns your code may break in several places. Give your data the correct names and as long as you always refer to data$This then your code will work.
I usually select columns by their position in the matrix/data frame.
e.g.
dataset[,4] to select the 4th column.
The 1st number in brackets refers to rows, the second to columns. Here, I didn't use a "1st number" so all rows of column 4 are selected, i.e., the whole column.
This is easy to remember since it stems from matrix calculations. E.g., a 4x3 dimensional matrix has 4 rows and 3 columns. Thus when I want to select the 1st row of the third column, I could do something like matrix[1,3]

Resources