[R] read.table or read.csv without row index?
dwinsemius at comcast.net
Wed May 5 21:56:37 CEST 2010
On May 5, 2010, at 3:49 PM, JiHO wrote:
>> I tried as.matrix but it did not help.
> as.matrix() won't work because a matrix requires everything in it to
> be of the same type (number, character, logical etc.). You do not have
> only numbers in your data.frame, so it will convert everything to
> character strings. If you try as.matrix(temp[,-1]) it should work
> (assuming you only have characters in the first column, otherwise
> remove all non-numeric columns).
> But what you really want is to circumvent the fact that, on a
> data.frame, mean works column-wise. In fact, when you call mean() on a
> data.frame() it calls mean.data.frame(), which code you can see by
> typing its name at the prompt:
> function (x, ...)
> sapply(x, mean, ...)
> <environment: namespace:base>
> And indeed, it uses sapply() to apply the function mean to each
> column. You could have tried:
> but this returns and error because it needs a numeric vector and does
> not automatically convert your data.frame into it. So you need:
mean( data.matrix(temp)[ 2 , 2:3] )
> or more simply
> I hope that helped. Sincerely,
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help