Entering edit mode
11.1 years ago
robjohn7000
▴
110
Hi,
I have a data frame (selData) on which I'm using a for loop to collect the first 100 rownames and data into a samller data frame (exprs100.row) as follows:
data frame eaxmple:
hr0 hr6 hr24 hr48 hr72 hr80
1 0 0.9879942 0.9833003 0.9737801 0.9737969 0.9587732
2 0 0.9928526 0.9860887 0.9812401 0.9840965 0.9737232
3 0 0.9956888 1.0116334 1.0155620 1.0247329 1.0252338
for loop:
for(i in 0:99){
indx = rank(modF) == nrow(selData) - i
exprs.row = selDataMatrix_ave.log.ratio[indx,]
exprs100.row[[i]] <- exprs.row[i]
}
The statement that I have problem with is :
exprs100.row[[i]] <- exprs.row[i]
Could someone please help with the correct way of writing it. Thanks
A brief introduction to “apply” in R
please read
?'['
and read a basic introduction to R first. R is different from many other programming languages. As a rule of thumb in R you don't need to use for loops almost anywhere, but instead vectorized functions, sub setting, orapply
. Using loops is clumsy and extremely slow compared to other options.In addition to all other comments: R is 1 indexed