Percent transformation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Percent transformation

Christoph Puschmann
Hello all,

I am having a problem of transforming decimals into percentage. Specifically, I get the following error message:

"Error in UseMethod("round_any") :
  no applicable method for 'round_any' applied to an object of class “data.frame"

My code looks the following:

x <- sp[1:5,2:6]
x = percent(x)

My Data:

SD      D       N       A       SA






1

0.005769231

-0.14230769

0.071153846

0.09615385

-0.030769231

2

-0.057692308

-0.08461538

0.038461538

0.01923077

0.084615385

3

-0.076923077

-0.10384615

0.221153846

-0.04423077

0.003846154

4

-0.167307692

-0.13653846

-0.003846154

0.16153846

0.146153846

5

0.000000000

-0.01923077

0.011538462

0.21923077

-0.2115384

All help would be appreciated. Thank you.

Christoph




        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Percent transformation

Berend Hasselman

> On 14 Mar 2017, at 22:19, Christoph Puschmann <[hidden email]> wrote:
>
> Hello all,
>
> I am having a problem of transforming decimals into percentage. Specifically, I get the following error message:
>
> "Error in UseMethod("round_any") :
>  no applicable method for 'round_any' applied to an object of class “data.frame"
>

Did you read the Posting Guide.
DO NOT post in html.

Your data are mangled.

Your code is incomprehensible.
Reproducible example please.

Where does percent come from?

Berend Hasselman

> My code looks the following:
>
> x <- sp[1:5,2:6]
> x = percent(x)
>
> My Data:
>
> SD      D       N       A       SA
>
>
>
>
>
>
> 1
>
> 0.005769231
>
> -0.14230769
>
> 0.071153846
>
> 0.09615385
>
> -0.030769231
>
> 2
>
> -0.057692308
>
> -0.08461538
>
> 0.038461538
>
> 0.01923077
>
> 0.084615385
>
> 3
>
> -0.076923077
>
> -0.10384615
>
> 0.221153846
>
> -0.04423077
>
> 0.003846154
>
> 4
>
> -0.167307692
>
> -0.13653846
>
> -0.003846154
>
> 0.16153846
>
> 0.146153846
>
> 5
>
> 0.000000000
>
> -0.01923077
>
> 0.011538462
>
> 0.21923077
>
> -0.2115384
>
> All help would be appreciated. Thank you.
>
> Christoph
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Percent transformation

Bert Gunter-2
In reply to this post by Christoph Puschmann
This looks like homework. If so, we don't do homework here. If not,
please read and follow the posting guide. In particular, plain text
email only.  The error message you received seems self explanatory.

-- Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Mar 14, 2017 at 2:19 PM, Christoph Puschmann
<[hidden email]> wrote:

> Hello all,
>
> I am having a problem of transforming decimals into percentage. Specifically, I get the following error message:
>
> "Error in UseMethod("round_any") :
>   no applicable method for 'round_any' applied to an object of class “data.frame"
>
> My code looks the following:
>
> x <- sp[1:5,2:6]
> x = percent(x)
>
> My Data:
>
> SD      D       N       A       SA
>
>
>
>
>
>
> 1
>
> 0.005769231
>
> -0.14230769
>
> 0.071153846
>
> 0.09615385
>
> -0.030769231
>
> 2
>
> -0.057692308
>
> -0.08461538
>
> 0.038461538
>
> 0.01923077
>
> 0.084615385
>
> 3
>
> -0.076923077
>
> -0.10384615
>
> 0.221153846
>
> -0.04423077
>
> 0.003846154
>
> 4
>
> -0.167307692
>
> -0.13653846
>
> -0.003846154
>
> 0.16153846
>
> 0.146153846
>
> 5
>
> 0.000000000
>
> -0.01923077
>
> 0.011538462
>
> 0.21923077
>
> -0.2115384
>
> All help would be appreciated. Thank you.
>
> Christoph
>
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Percent transformation

Jeff Newmiller
In reply to this post by Christoph Puschmann
Your x variable is a data frame. The scales::percent() function does not work on data frames. It might work on the individual columns in the data frame. You probably ought to re-read your preferred introduction to R material on the difference between data frames and the columns in data frames.

Try

scales::percent( sp[[ 1 ]] )

Do beware that that function converts your numbers into character strings, unlike Excel. It is often more practical to simply multiply by 100 and forego the percent sign.
--
Sent from my phone. Please excuse my brevity.

On March 14, 2017 2:19:59 PM PDT, Christoph Puschmann <[hidden email]> wrote:

>Hello all,
>
>I am having a problem of transforming decimals into percentage.
>Specifically, I get the following error message:
>
>"Error in UseMethod("round_any") :
>no applicable method for 'round_any' applied to an object of class
>“data.frame"
>
>My code looks the following:
>
>x <- sp[1:5,2:6]
>x = percent(x)
>
>My Data:
>
>SD      D       N       A       SA
>
>
>
>
>
>
>1
>
>0.005769231
>
>-0.14230769
>
>0.071153846
>
>0.09615385
>
>-0.030769231
>
>2
>
>-0.057692308
>
>-0.08461538
>
>0.038461538
>
>0.01923077
>
>0.084615385
>
>3
>
>-0.076923077
>
>-0.10384615
>
>0.221153846
>
>-0.04423077
>
>0.003846154
>
>4
>
>-0.167307692
>
>-0.13653846
>
>-0.003846154
>
>0.16153846
>
>0.146153846
>
>5
>
>0.000000000
>
>-0.01923077
>
>0.011538462
>
>0.21923077
>
>-0.2115384
>
>All help would be appreciated. Thank you.
>
>Christoph
>
>
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Percent transformation

Christoph Puschmann
Dear All,

Thank you for helping me out.

First, I am sorry for adding a HTML element. I was not aware of it. I simply copy and pasted the output of mat_data from R studio.

Second, no it is not homework. It was part of a side project at work.

Third, thank you Jeff. Your comment was really productive. I discovered two alternatives:
1) mat_data = as.matrix(sapply(x[,2:ncol(x)], percent))
2) mat_data = as.matrix(sapply(x[,2:ncol(x)], as.numeric)*100)
    mat_data = round(mat_data,1)

Regards,

Christoph

> On 15 Mar 2017, at 5:32 pm, Jeff Newmiller <[hidden email]> wrote:
>
> Your x variable is a data frame. The scales::percent() function does not work on data frames. It might work on the individual columns in the data frame. You probably ought to re-read your preferred introduction to R material on the difference between data frames and the columns in data frames.
>
> Try
>
> scales::percent( sp[[ 1 ]] )
>
> Do beware that that function converts your numbers into character strings, unlike Excel. It is often more practical to simply multiply by 100 and forego the percent sign.
> --
> Sent from my phone. Please excuse my brevity.
>
> On March 14, 2017 2:19:59 PM PDT, Christoph Puschmann <[hidden email]> wrote:
>> Hello all,
>>
>> I am having a problem of transforming decimals into percentage.
>> Specifically, I get the following error message:
>>
>> "Error in UseMethod("round_any") :
>> no applicable method for 'round_any' applied to an object of class
>> “data.frame"
>>
>> My code looks the following:
>>
>> x <- sp[1:5,2:6]
>> x = percent(x)
>>
>> My Data:
>>
>> SD      D       N       A       SA
>>
>>
>>
>>
>>
>>
>> 1
>>
>> 0.005769231
>>
>> -0.14230769
>>
>> 0.071153846
>>
>> 0.09615385
>>
>> -0.030769231
>>
>> 2
>>
>> -0.057692308
>>
>> -0.08461538
>>
>> 0.038461538
>>
>> 0.01923077
>>
>> 0.084615385
>>
>> 3
>>
>> -0.076923077
>>
>> -0.10384615
>>
>> 0.221153846
>>
>> -0.04423077
>>
>> 0.003846154
>>
>> 4
>>
>> -0.167307692
>>
>> -0.13653846
>>
>> -0.003846154
>>
>> 0.16153846
>>
>> 0.146153846
>>
>> 5
>>
>> 0.000000000
>>
>> -0.01923077
>>
>> 0.011538462
>>
>> 0.21923077
>>
>> -0.2115384
>>
>> All help would be appreciated. Thank you.
>>
>> Christoph
>>
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Loading...