how to select all but certain rows in matrix in r? [closed] - r

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Is there an easy way to do this in r with a matrix, similar to negative indexing for data.frames?
for example, I can remove the n-th row of the matrix mat as follows:
mat = rbind(mat[1:(n-1),],mat[(n+1):nrow(mat)])
but are there faster and/or simpler ways to do this?
-Paul

Negative indexing works for matrices, i.e. mat[-n,]

Related

How is it possible to add 15 to every figure in a column, in a tibble? [duplicate]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I’m new to R and I’m trying to add 15 to every figure in my dataset for a specific column and was wondering how it’s possible to this. Any help would be much appreciated, thanks.
Asssuming you have a data.frame df with a column col that you want to increase:
df$col <- df$col + 15
No loop required, the fundamental objects in R are vectors.

generate all possible k-mers from a vector and also remaining in r [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Suppose we have a vector [1:10] of players, I want to generate all possible roommates for these playes (not combn(10, 2))
Can you help me?
Thank you
You can iterate over combn(with different ks)
x= 1:10
lapply(1:length(x), function(k) combn(x,k))

Create new column from two column with logic in R? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
Looking for other way than ifelse.
How to create NewColumn like this:
As displayed in your picture, you want to paste together two columns. Assuming your dataframe is called df, you can do:
df$NewColumn <- paste(df$Column2,"",df$Column1)
Which will get you the outcome in the picture.

Create a random matrix with full rank [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For one of my projects I would like to create several random matrices, which have full rank. Does anybody know a quick way to do this in R or has an idea how to proceed?
You are overwhelmingly likely to get a full-rank matrix if you generate a matrix with iid elements, with no additional constraints:
library(Matrix)
set.seed(101)
r <- replicate(1000,rankMatrix(matrix(rnorm(10000),100)))
table(r) ## all values are equal to 100
(Someone who spent more time on the math might be able to prove that the set of reduced-rank matrices within this space of matrices actually has measure 0 ...)

How do I normalize and denormalize data in R? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have data that contains 14 columns of predictors and 1 column of solution variable(y).
I wanted to know if there are any inbuilt functions to normalize and denormalize data in R.
Thank you.
normDataWithin of package {Rmisc} can be used: http://www.inside-r.org/packages/cran/Rmisc/docs/normDataWithin
Else following methods can be used:
(variable-mean)/sd . Following code can be used for a data.frame:
mydata$myNormalizedVar<-(mydata$myvar-mean(mydata$myvar))/sd(myvar)
log (log10), log2, and square root (sqrt)
Normal quantile normalization or normal quantile transformation. Try:
quantNorm = function(x){qnorm(rank(x,ties.method = "average")/(length(x)+1))}
hist(quantNorm(1:10000),100)

Resources