Is there any R function for finding the element in a vector which is perpendicular to the plain? - vector

Is there any r function for finding the element in a vector?
I have a problem in finding r of the vector which is perpendicular to the plain
my concept is not clear.

Related

is there any r function for finding the element in a vector?

Is there any r function for finding the element in a vector?
I have tried solving the question but getting problem in the vector concept regarding R.
You can use match if you want the first one and which if you want to get all positions. A nice example for your problem is: https://statisticsglobe.com/r-find-index-of-element-in-vector

Laplace expansion for determinants with r

I have a 21*21 matrix. I would like to use R in order to apply laplace extension along the first row so to display only the last step for the calculation of the determinant (2x2 matrix).
Unluckily, despite my best efforts, I can't figure out how this could be done.
To be clearer I provide an example with a 3x3 matrix
e.g. r <- matrix(c(1:9),3,3)
My aim is to find an expansion along the first row, so to obtain the three cofactors. These cofactors should be visualized so to distinguish the three minor matrices, the multiplying corresponding element of the matrix, and the signs of the permutation.
TO have a visual you can take a look to the first example in (http://en.wikipedia.org/wiki/Laplace_expansion)
Any suggestions? Thank you

dist function with large number of points

I am using the dist {stats} function to calculate the distance between points, my problem is that I have 24469 points, and the output for the dist function gives me a vector with 18705786 length, instead of the matrix. I tried already to export as.matrix, but the file is 2 large.
How can I have access to what points corresponds each distance?
For example which(distance<=700) gives me the position in the vector, but how can I get the info to what points this distance corresponds to?
There are asome things you could try, also depending on what you need exactly:
Calculate the distances in a loop, and only keep those that match the criterium. Especially when the number of matches is much smaller than the total size of the distance matrix, this saves a lot of RAM usage. This loop is probably very slow if it is implemented in pure R, that is alos why dist does not use R but I believe C to perform the calculations. This could mean that you get your results, but have to wait a while. Alternatively, the excellent Rcpp package would allow you to write this down in C/C++, making it much much faster probably.
Start using packages like bigmemory in storing the distance matrix. You then build it in a loop and store it iteratively in the bigmemory object (I have not worked with bigmemory before, so I don't know the exact details). Then after building the matrix, you can access it to extract your desired results. Effectively, all tricks to handle large data in R apply to this bullet. See e.g. R SO posts on big data.
Some interesting links (found googling for r distance matrix for large vector):
Efficient (memory-wise) function for repeated distance matrix calculations AND chunking of extra large distance matrices
(lucky you!) http://stevemosher.wordpress.com/2012/04/08/using-bigmemory-for-a-distance-matrix/

areaint in Matlab vs. areaPolygon or areapl in R

I am getting two different sets of values when I try to calculate the polygon area in Matlab vs. R. In Matlab, I used areaint (with the reference ellipsoid set to WGS84). In R, I tried both geosphere::areaPolygon on lat-lon or splancs::areapl on grid-converted Euclidean coordinates. The R results agree with each other, but not with the Matlab calculation. The two sets are on average 25% different (Matlab lower). What am I missing?
Apparently, the result from Matlab came from an incorrectly formatted input matrix: areaint() requires (lat,lon), whereas the R input was correctly formatted as (lon,lat). This holds true for any of the previously mentioned R functions.
See also:
http://r-sig-geo.2731867.n2.nabble.com/template/NamlServlet.jtp?macro=reply&node=7581419

Finding full QR decomposition from reduced QR

What's the best way to find additional orthonormal columns of Q? I have computed the reduced QR decomposition already, but need the full QR decomposition.
I assume there is a standard approach to this, but I've been having trouble finding it.
You might wonder why I need the full Q matrix. I'm using it to apply a constraint matrix for "natural" splines to a truncated power series basis expansion. I'm doing this in Java, but am looking for a language-independent answer.
Successively add columns to Q in the following way:
Pick a vector not already in the span of Q
Orthogonalize it with respect to the columns of Q
Add the orthogonalized vector as a new column of Q.
Add a row of zeros to the bottom of R
For reference, see these illustrative albeit mathematical lecture notes
Just in case, the process of "orthogonalization" of a new vector is an old technique called the Gram-Schmidt process, and there is a variant which is numerically stable.

Resources