Re: [R] excluding NAs in data frame without deleting rows

2009-05-29 Thread Adrián Cortés
use:

sum(x,na.rm=T)

like this:

my.row.sums - apply(my.matrix,1,sum,na.rm=T)

If you want to do across columns then use 2 instead of 1.  Look at ?apply
and ?sum.

Adrian

On Fri, May 29, 2009 at 7:46 AM, Wade Wall wade.w...@gmail.com wrote:

 Hi all,

 I have a binary matrix with NAs included.  Each row and column
 includes at least one NA, so I don't want to omit them.  Is there a
 way to sum across rows and columns, ignoring the NAs but not deleting
 the row or column?  If not, I suppose I can write a loop function, but
 I have learned that it is best to stay away from loops if possible.

 Thanks for any help,

 Wade

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Printing to screen a matrix or data.frame in one chunk (not splitting columns)

2009-05-15 Thread Adrián Cortés
Hello,

I saw this nice trick I want to replicate but I lost the source and I hope
one of you can point me to the solution.  My problem is that I don't know
the correct words to query this.

When I print to screen a matrix or data.frame the columns are split and
printed below the previous ones; even though I have plenty of screen left.

E.g.,

 my_matrix = matrix(runif(30),nrow=3,ncol=10)
 my_matrix
  [,1]  [,2]  [,3]   [,4]  [,5]  [,6]
[,7]
[1,] 0.4979305 0.1155717 0.4484069 0.29986049 0.5427566 0.4324351
0.269171456
[2,] 0.8405987 0.3605237 0.6615507 0.75305248 0.8569482 0.3401004
0.192526423
[3,] 0.5608779 0.3953941 0.9995035 0.03141064 0.7985053 0.4903582
0.000490054
  [,8]  [,9]  [,10]
[1,] 0.1402751 0.2852381 0.98816751
[2,] 0.8337806 0.7322920 0.17505541
[3,] 0.5414113 0.4668012 0.04420137

So there is a way to resize the space for printing so that everything in
printed in one chunk.

Thanks in advance,
Adrian

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Batch importing data with respective naming

2009-04-29 Thread Adrián Cortés
By doing peak - list() you initialize a list and then you are adding the
data objects to the list in the for loop.To access each data object just go:
peaks[[i]]
Where i is in [1,100].  This will return the data object you want.

Adrian

On Tue, Apr 28, 2009 at 11:23 PM, Taylor Hermes trher...@gmail.com wrote:

 It seems that this addition works, but has created just one object
 called 'peak' with all the data from those 100 files.  I'd like each
 file to have a corresponding object containing the data.

 Thanks for your help!


 On Tue, Apr 28, 2009 at 19:43, Zeljko Vrba zv...@ifi.uio.no wrote:
  On Tue, Apr 28, 2009 at 07:09:04PM -1000, Taylor Hermes wrote:
 
  I tried the following:
 
  Add this before for():
 
  peak - list()
 
  for (i in 1:100) {
peak[[i]] - read.table(paste(i,--one--hist.txt, sep=),
 sep=,,
  header=TRUE)
  }
 
 
 

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.