Displaying 3 results from an estimated 3 matches for "mainmat".
2011 Aug 29
3
Basic question about re-writing for loop as a function
Hello-
Sorry to ask a basic question, but I've spent many hours on this now
and seem to be missing something.
I have a loop that looks like this:
mainmat=data.frame(matrix(data=0, ncol=92, nrow=length(predata$Words_MH)))
for(i in 1:length(predata$Words_MH)){
for(j in 1:92){
mainmat[i,j]=ifelse(j %in%
as.numeric(unlist(strsplit(predata$Words_MH[i], split=","))), 1, 0)
}
}
What it's doing is creating a matrix with...
2010 Jan 29
7
Simple question on replace a matrix row
Hello, I have a matrix mat1 of dim [1,8] and mat2 of dim[30,8], I want to
replace the first row of mat2 with mat1, this is what I do:
mat2[1,]<-mat1 but it transforms mat2 in a list I don't understand, I want
it to stay a matrix...
-----
Anna Lippel
--
View this message in context: http://n4.nabble.com/Simple-question-on-replace-a-matrix-row-tp1427857p1427857.html
Sent from the R help
2007 Aug 21
1
Random Sampling from a Matrix
...first two columns are indicator variables taking the value of either 0 or 1. Let us call the first two columns Y1 and Y2.
I need to randomly sample 1000 rows with all the associated columns, in other words my new matrix should be of size 1000 X 20. I realize that using this command
newmat <- mainmat[sample(1000,replace=F),]
achieves this. However, I would like to make sure that both Y1 and Y2 have more or less an equal amount of 0's and 1's. At present when I sample, I get cases where sometimes all my Y2's are 0. Is there any way to accomodate this problem.
Thanks in advance.
Re...