get the row sums

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

get the row sums

Changbin Du
> head(en.id.pr)
     valid.gene_id b.pred rf.pred svm.pred
1521    2500151211      0       0        0
366      639679745      0       0        0
1965    2502081603      1       1        1
1420     644148030      1       1        1
1565    2500626489      1       1        1
1816    2501711016      1       1        1


> p.pred <- data.frame(en.id.pr, sum=apply(en.id.pr[,2:4], 1, sum)) # get
the row sum for three variables.
Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument


HI, Dear R community,

I am try use the above codes to get the row sums, but it gave me errors.
CAN someone help me with this?


--
Sincerely,
Changbin
--

Changbin Du
DOE Joint Genome Institute
Bldg 400 Rm 457
2800 Mitchell Dr
Walnut Creet, CA 94598
Phone: 925-927-2856

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: get the row sums

David Winsemius

On May 18, 2010, at 4:32 PM, Changbin Du wrote:

>> head(en.id.pr)
>     valid.gene_id b.pred rf.pred svm.pred
> 1521    2500151211      0       0        0
> 366      639679745      0       0        0
> 1965    2502081603      1       1        1
> 1420     644148030      1       1        1
> 1565    2500626489      1       1        1
> 1816    2501711016      1       1        1
>
>
>> p.pred <- data.frame(en.id.pr, sum=apply(en.id.pr[,2:4], 1, sum)) #  
>> get
> the row sum for three variables.
> Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument
>
>
> HI, Dear R community,
>
> I am try use the above codes to get the row sums, but it gave me  
> errors.
> CAN someone help me with this?

If you look at the results of str(en.id.pr) , I think you will find  
that one or more of those columns is of class character.

(There is also a rowSums function, but if you have character variables  
It's not likely to be of much additional help.)


>
>
> --
> Sincerely,
> Changbin
> --
>
> Changbin Du


David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: get the row sums

Joshua Wiley-2
In reply to this post by Changbin Du
Hello,

Can you run str() on your data and report the results?

str(en.id.pr)

I suspect that one of your variables that you are trying to sum over
is a factor.

HTH,

Josh

2010/5/18 Changbin Du <[hidden email]>:

>> head(en.id.pr)
>     valid.gene_id b.pred rf.pred svm.pred
> 1521    2500151211      0       0        0
> 366      639679745      0       0        0
> 1965    2502081603      1       1        1
> 1420     644148030      1       1        1
> 1565    2500626489      1       1        1
> 1816    2501711016      1       1        1
>
>
>> p.pred <- data.frame(en.id.pr, sum=apply(en.id.pr[,2:4], 1, sum)) # get
> the row sum for three variables.
> Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument
>
>
> HI, Dear R community,
>
> I am try use the above codes to get the row sums, but it gave me errors.
> CAN someone help me with this?
>
>
> --
> Sincerely,
> Changbin
> --
>
> Changbin Du
> DOE Joint Genome Institute
> Bldg 400 Rm 457
> 2800 Mitchell Dr
> Walnut Creet, CA 94598
> Phone: 925-927-2856
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>



--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: get the row sums

Changbin Du
In reply to this post by David Winsemius
Thanks, David!
Yes, I found it just as you said. It works now after change to numeric.


On Tue, May 18, 2010 at 1:53 PM, David Winsemius <[hidden email]>wrote:

>
> On May 18, 2010, at 4:32 PM, Changbin Du wrote:
>
>  head(en.id.pr)
>>>
>>    valid.gene_id b.pred rf.pred svm.pred
>> 1521    2500151211      0       0        0
>> 366      639679745      0       0        0
>> 1965    2502081603      1       1        1
>> 1420     644148030      1       1        1
>> 1565    2500626489      1       1        1
>> 1816    2501711016      1       1        1
>>
>>
>>  p.pred <- data.frame(en.id.pr, sum=apply(en.id.pr[,2:4], 1, sum)) # get
>>>
>> the row sum for three variables.
>> Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument
>>
>>
>> HI, Dear R community,
>>
>> I am try use the above codes to get the row sums, but it gave me errors.
>> CAN someone help me with this?
>>
>
> If you look at the results of str(en.id.pr) , I think you will find that
> one or more of those columns is of class character.
>
> (There is also a rowSums function, but if you have character variables It's
> not likely to be of much additional help.)
>
>
>
>>
>> --
>> Sincerely,
>> Changbin
>> --
>>
>> Changbin Du
>>
>
>
> David Winsemius, MD
> West Hartford, CT
>
>


--
Sincerely,
Changbin
--

Changbin Du
DOE Joint Genome Institute
Bldg 400 Rm 457
2800 Mitchell Dr
Walnut Creet, CA 94598
Phone: 925-927-2856

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.