disp(A)
1. 4. 5.
9. 13. 11.
46. 29. 11.
-->clear A(3,3)
!--error 276
Missing operator, comma, or semicolon.
I want to delete 11
The clear command is used to remove entire variables, see the documentation. If you could clear the 3,3 field it would result in a malformed matrix:
1. 4. 5.
9. 13. 11.
46. 29.
I don't know of a way this is possible.
What is it that you want? Do you want to set certain fields to be ignored. You could just set it to NaN (Not a Number) and check if it is nan later in your code with isnan:
A = rand(3,3)
A(3,3)= %nan
disp(A)
non_nans_indices = find(~isnan(A))
disp(A(non_nans_indices))
In a regular matrix you can not delete just one element, as stated in the above answer: you have to delete a full row or a full column. However in a sparse matrix you can. A sparse matrix stores only the non-zero elements of the matrix. So if your data doesn't contain valid elements with 0 value, you can "delete" any element by setting it to 0 and then converting the matrix into sparse form with the sparse command:
A=rand(3,3);
disp(A,"original matrix:");
A(3,3)=0;
disp(A,"element is nulled out:");
A=sparse(A);
disp(A,"sparse matrix:");
This way you doesn't store the 0 values of tha matrix which may save memory or storage space. If you want to convert back, you can use the full command: the "missing" elements are representeted with zeros again:
B=full(A);
disp(B,"full form:");
But I think, that for missing or invalid values it's better to use %nan as advised above too: it's easier to deal with, more consistent, and you can have zeros in the matrix as valid data.
Related
I have a column of store IDs which all have leading zeroes. I.E. 0017 shows rather than 17, 0876 shows rather than 876.
All Store IDs are 4 digits long with these leading zeroes. Is there a way to remove these leading zeroes and therefore leave me with 17 and 876 (as per above).
I imagine this would involve a REGEXP statement but I haven't been able to successfully create one yet.
Create a calculated field using this formula REGEXP_REPLACE(Store ID, r'^\D*0*', '').
Working example here.
I am trying to do some calculations where I divide two vectors. Sometimes I encounter a division by zero, which cannot take place. Instead of attempting this division, I would like to store an empty element in the output.
The question is: how do I do this? Can vectors have empty fields? Can a structure be the solution to my problem or what else should I use?
No, there must be something in the memory slot. Simply store a NaN or INT_MIN for integer values.
I need an R-code to delete certain percentage of numbers in a vector and replace the deleted numbers with another number....
e.g
consider this random number,
x=rnorm(100,1,3)
I want to delete 25% of the generated numbers and replace the deleted numbers by deleted number+29
Please, I need somebody to help me with this. Thanks.
For example :
x[seq_len(length(x)*0.25)] <- 29
This will replace in front of x. You can randomize the result using sample(x).
Another option is to use x as a base for generation :
c(sample(x,size = length(x)*0.75) ,rep(29, length(x)*0.25))
I have a spreadsheet called "MTM Lookup", this is downloaded from a specific site, in column D of this spreadsheet are values, but these values have a formula attached to them. The formula rounds these values to 0. The formulas don't round on a specific cell. They look like this =ROUND(35370.6708773751,0) or =ROUND(48368.0427161566,0). I need the values to come through with all the decimals or rounded to 10 decimals but cannot get this to happen, I can remove the formula and leave the value but it is rounded to zero. Please could anyone assist with some simple vba to either remove the =round(,0) or replace the 0 to 10 ie round(x,10).
I don't see any problem in the formula you provided.
When I put
=ROUND(35370.6708773751,0)
to a cell, I correctly see 35371 in the cell.
There are, however, two things in play here.
Formula
Cell Format
For example, when I enter the following value to the cell:
=ROUND(35370.6708773751,10)
I do see 35370.67088 as a result (after rounding to 10 places, cell format rounds it again to 5 decimal places)
I don't know why entering the value without any formula shows you 0, but this leads me to the same suspscion, i. e. that the problem is in the cell format.
You can check it by right clicking on the cell > Format Cells (in office 2010 at least) or programatically, using the following, for example:
sheets("MTM Lookup").range("A:1").numberformat = "0.0000000000"
Hope that it helps.
I am using the tabular() function to produce tables in r (tables library).
I want to compute CI's from the data in the output (let mytable be the output from tabular()). Simple enough I thought, except when I go to call a value from the matrix, I get the error Error in mytable[1, i] - 1 : non-numeric argument to binary operator. I thought this was odd, as when I call up a particular cell of the matrix (where as.matrix returned true for mytable), for example mytable[1, i] for some i, I get an interger. I then do the as.list for mytable and get true also, so I am not sure what this means. I guess the tabular() function stores the results as a special kind of matrix.
I am only trying to pull out the mean,sdev, and n, which I am able to just by typing the cell location, for example mytable[1, i] would return an 86. However, when I try to call up the value in qt(.975,df=(mytable[1,i]-1)) for example, I get the error above. Not sure really how to approach this except to manually enter the values into another matrix (which I would like to avoid). Or, if I can compute CI's directly in the tabular() function that would work also. Cheers.
I shall quote for you the Value section of the documentation on the function ?tabular:
An object of S3 class "tabular". This is a matrix of mode list, whose
entries are computed summary values, with the following attributes:
rowLabels - A matrix of labels for the rows. This will have the same
number of rows as the main matrix, but may have multiple columns for
different nested levels of labels. If a label covers multiple rows, it
is entered in the first row, and NA is used to fill following rows.
colLabels - Like rowLabels, but labelling the columns.
table - The original table expression being displayed. A list of the
original format specifications are attached as a "fmtlist" attribute.
formats - A matrix of the same shape as the main result, containing NA
for default formatting, or an index into the format list.
As the documentation says, each element of the matrix is a list. If your tabular object is called tab type tab[1,1] and you should see a list containing one of your table values. If I wanted to modify that value, I would probably do something like:
tab[1,1]$term <- value
just like you would modify values in any other list.
Type attributes(tab) and you'll see the items listed above, containing a lot of the formatting information and row/col headers.