Hi all, I want to create a new matrix based on a previous matrix. You see, If my "data" matrix accomplises this: if(rowSums(data[i,])>16|rowSums(data[i,])<28) data[i,]= data[i,] # if sum of rows is more than 16 and less 28 I conservate the row #but How I say if else "remove" the line (I tried this) but doesn´t works...I´m really a asn else if(data[i,]=data[-i,]) } You see imagine my data matrix is 10x4 and only 3 rows passes the condition...the resulting matrix will be 3x4 I tried also to save the new matrix as csv like this write.csv(data, file = "input1.csv") How should I proceed to save as a txt? Many thanks I really like this problems but I feel my mind is restricted to more easy things¡¡¡jajaj [[alternative HTML version deleted]]
Hi I know that putting write(f,file="bar.txt") it should work but the txt cannot be openned well I don ´t know exactly why. My mai doubt is how to make this I want to create a new matrix based on a previous matrix. You see, If my "data" matrix accomplises this: if(rowSums(data[i,])>16|rowSums(data[i,])<28) data[i,]= data[i,] # if sum of rows is more than 16 and less 28 I conservate the row #but How I say if else "remove" the line (I tried this) but doesn´t works...I´m really a asn else if(data[i,]=data[-i,]) } You see imagine my data matrix is 10x4 and only 3 rows passes the condition...the resulting matrix will be 3x4 2011/7/1 Trying To learn again <tryingtolearnagain@gmail.com>> Hi all, > > I want to create a new matrix based on a previous matrix. > > You see, If my "data" matrix accomplises this: > > if(rowSums(data[i,])>16|rowSums(data[i,])<28) > data[i,]= data[i,] > > # if sum of rows is more than 16 and less 28 I conservate the row > #but How I say if else "remove" the line (I tried this) but doesn´t > works...I´m really a asn > > else if(data[i,]=data[-i,]) > } > > You see imagine my data matrix is 10x4 and only 3 rows passes the > condition...the resulting matrix will be 3x4 > > I tried also to save the new matrix as csv like this > > write.csv(data, file = "input1.csv") > > How should I proceed to save as a txt? > > Many thanks I really like this problems but I feel my mind is restricted to > more easy things¡¡¡jajaj > >[[alternative HTML version deleted]]
On Jul 1, 2011, at 12:14 PM, Trying To learn again wrote:> Hi all, > > I want to create a new matrix based on a previous matrix. > > You see, If my "data" matrix accomplises this: > > if(rowSums(data[i,])>16|rowSums(data[i,])<28) > data[i,]= data[i,]'if' is not the right command.> # if sum of rows is more than 16 and less 28 I conservate the row > #but How I say if else "remove" the line (I tried this) but doesn?t > works...I?m really a asnUse logical indexing. (Using 'dat' because 'data' is bad practice as an object name.) dat2 <- dat[ rowSums(dat) >16 | rowSums(dat) < 28 , ]> > else if(data[i,]=data[-i,])The i- else construct only works on scalars. If you give them vectors they only use the first value and then they warn. You can use ifelse on vectors.> > You see imagine my data matrix is 10x4 and only 3 rows passes the > condition...the resulting matrix will be 3x4 > > I tried also to save the new matrix as csv like this > > write.csv(data, file = "input1.csv") > > How should I proceed to save as a txt? > > Many thanks I really like this problems but I feel my mind is > restricted to > more easy things???jajaj > > [[alternative HTML version deleted]]If you are "trying to learn" then try to learn to post in plain text. -- David Winsemius, MD West Hartford, CT