Help with not meaningful for factors?

Hi, I have a line code which confuses me, a few hours ago I typed this:
etiquetas <- paste(names(TTipoInm),
round(TTipoInm/length(No)*100,2), "%")
It cames from a data base, the thing is that at first it appeared an error like this:
Warning message:
In Ops.factor(left, right) : ‘/’ not meaningful for factors

After hours, and somehow, I rewrited it in the same way but now this time, it worked!
I don't know why this happened...
Now I'm trying to make an RMarkdown and I'm running all the codes to make sure everything is fine, and now it's happening again... Can someone explain me, why it works sometimes, and then after a moment it doesn't?

PD: I'm new in this community, sorry If I'm not being clear with my problem :frowning:

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

I'd like to, but how Can I put the database here? Or it's enough if I put all my codelines?

Read the guide and think about your object.
Presumably its called. TTipoInm

No Tipo_de_Inmueble Operacion Provincia Superficie Precio_Venta Fecha Venta Vendedor Satisfaccion
1 Casa Alquiler Barcelona 153.51 1,747,005.43 25/10/2004 Carmen 2.Regular
2 Casa Venta Girona 149.16 1,849,498.82 27/09/2004 Carmen 2.Regular
3 Casa Alquiler Tarragona 171.28 2,107,069.30 12/02/2005 Carmen 2.Regular
4 Casa Alquiler Girona 151.42 1,546,162.61 23/05/2005 Carmen 2.Regular
5 Casa Venta Lleida 161.95 1,801,051.65 02/05/2005 Carmen 2.Regular
6 Casa Venta Tarragona 179.01 1,591,157.40 16/09/2005 Carmen 2.Regular
7 Casa Alquiler Tarragona 162.57 1,485,099.23 20/02/2006 Carmen 2.Regular
8 Casa Venta Lleida 159.8 1,456,010.05 16/05/2006 Carmen 2.Regular
9 Casa Venta Lleida 170.63 2,190,229.96 01/11/2005 Carmen 2.Regular
10 Casa Venta Barcelona 166.38 1,900,232.45 03/07/2006 Carmen 2.Regular
11 Casa Venta Barcelona 181.97 1,797,489.90 25/04/2007 Carmen 2.Regular
12 Casa Alquiler Tarragona 166.89 1,771,878.35 10/11/2006 Carmen 2.Regular
13 Casa Venta Tarragona 165.88 1,855,450.02 16/12/2006 Carmen 2.Regular
14 Local Alquiler Tarragona 68.67 653,034.96 04/08/2004 Carmen 2.Regular
15 Local Alquiler Tarragona 122.16 861,863.44 13/11/2004 Carmen 2.Regular
16 Local Venta Barcelona 74.75 809,612.46 25/08/2004 Carmen 2.Regular
17 Local Alquiler Girona 123.99 1,371,226.52 02/09/2004 Carmen 2.Regular
18 Local Alquiler Tarragona 84.54 936,078.57 01/07/2005 Carmen 2.Regular
19 Local Alquiler Lleida 98.11 953,921.61 30/05/2005 Carmen 2.Regular
20 Local Alquiler Barcelona 107.48 1,219,106.50 04/08/2005 Carmen 2.Regular
21 Local Venta Tarragona 111.35 1,117,403.66 25/03/2006 Carmen 2.Regular
22 Local Venta Girona 109.46 1,110,242.31 21/09/2005 Carmen 2.Regular
23 Local Venta Tarragona 83.7 911,749.56 12/02/2006 Carmen 2.Regular
24 Local Venta Lleida 113.3 1,238,879.89 12/03/2006 Carmen 2.Regular
25 Local Venta Lleida 91.09 775,983.53 18/12/2006 Carmen 2.Regular
26 Local Venta Tarragona 88.42 845,376.73 12/11/2006 Carmen 2.Regular
27 Local Venta Lleida 93.94 906,567.64 01/02/2007 Carmen 2.Regular
28 Local Alquiler Girona 103.59 1,065,951.73 15/01/2007 Carmen 2.Regular
29 Local Venta Tarragona 98.96 833,459.17 04/03/2007 Carmen 2.Regular
30 Local Alquiler Girona 105.51 1,233,659.03 17/02/2007 Carmen 2.Regular
31 Casa Alquiler Barcelona 182.58 1,743,531.52 16/06/2004 Joaquin 2.Regular
32 Casa Venta Girona 181.89 1,733,639.34 21/10/2004 Joaquin 2.Regular
33 Casa Alquiler Tarragona 150.63 1,546,639.34 17/02/2006 Joaquin 2.Regular
34 Casa Venta Barcelona 177.56 1,735,937.38 27/07/2006 Joaquin 2.Regular
35 Casa Venta Lleida 173.98 1,766,086.60 12/07/2006 Joaquin 2.Regular
36 Casa Alquiler Barcelona 162.45 1,436,342.56 28/03/2007 Joaquin 2.Regular
37 Casa Venta Barcelona 142.72 1,390,542.23 11/09/2006 Joaquin 2.Regular
38 Casa Venta Girona 169.41 1,292,566.72 13/11/2006 Joaquin 2.Regular
39 Casa Alquiler Lleida 152.07 1,307,184.98 04/04/2007 Joaquin 2.Regular
40 Casa Venta Lleida 168.42 987,201.32 01/12/2006 Joaquin 2.Regular
41 Casa Alquiler Tarragona 190.88 1,763,305.99 08/03/2007 Joaquin 2.Regular
42 Casa Venta Girona 155.86 1,718,219.79 30/03/2007 Joaquin 2.Regular
43 Local Venta Barcelona 108.42 1,280,446.26 08/01/2005 Joaquin 2.Regular
44 Local Alquiler Barcelona 88.08 938,644.40 19/02/2005 Joaquin 2.Regular
45 Local Venta Lleida 84.84 696,435.57 04/03/2005 Joaquin 2.Regular
46 Local Alquiler Lleida 117.45 1,274,000.57 15/12/2005 Joaquin 2.Regular
47 Local Venta Barcelona 96.98 1,083,602.11 25/07/2005 Joaquin 2.Regular
48 Local Venta Barcelona 103.54 924,602.42 12/01/2006 Joaquin 2.Regular
49 Local Venta Lleida 106.89 929,244.15 18/08/2005 Joaquin 2.Regular
50 Local Alquiler Lleida 112.46 910,980.42 07/09/2006 Joaquin 2.Regular
51 Local Venta Tarragona 89.46 1,315,509.12 09/03/2006 Joaquin 2.Regular
52 Local Venta Lleida 87.63 954,763.59 07/10/2006 Joaquin 2.Regular
53 Local Venta Girona 85.96 843,405.71 07/01/2007 Joaquin 2.Regular
54 Local Alquiler Lleida 95.1 928,155.48 15/03/2007 Joaquin 2.Regular
55 Casa Venta Lleida 180.77 1,972,145.94 09/09/2004 Luisa 2.Regular
56 Casa Alquiler Barcelona 165.53 1,764,865.36 14/09/2004 Luisa 2.Regular
57 Casa Venta Lleida 159.92 1,691,343.38 02/12/2004 Luisa 2.Regular
58 Casa Venta Girona 162.9 1,342,300.14 24/10/2004 Luisa 2.Regular
59 Casa Alquiler Girona 162.48 1,895,514.75 16/06/2005 Luisa 2.Regular
60 Casa Alquiler Barcelona 181.56 938,652.18 03/01/2006 Luisa 2.Regular
61 Casa Alquiler Tarragona 164.02 1,376,645.25 25/10/2005 Luisa 2.Regular
62 Casa Venta Barcelona 157.75 1,232,029.00 06/06/2006 Luisa 2.Regular
63 Casa Alquiler Lleida 179.87 1,553,324.21 16/08/2006 Luisa 2.Regular
64 Casa Venta Girona 175.79 1,572,587.40 23/04/2006 Luisa 2.Regular
65 Casa Alquiler Lleida 170.15 1,829,529.56 08/10/2006 Luisa 2.Regular
66 Casa Venta Lleida 169.24 1,661,436.10 20/11/2006 Luisa 2.Regular
67 Casa Venta Girona 184.84 2,026,445.94 27/12/2006 Luisa 2.Regular
68 Casa Venta Lleida 162.38 1,525,406.62 01/05/2007 Luisa 2.Regular
69 Casa Venta Tarragona 160.64 1,664,117.47 19/01/2007 Luisa 2.Regular
70 Casa Venta Lleida 165.2 1,392,003.19 03/05/2007 Luisa 2.Regular
71 Local Alquiler Barcelona 97.16 894,519.33 28/06/2004 Luisa 2.Regular
72 Local Venta Barcelona 107.99 928,812.83 23/05/2004 Luisa 2.Regular
73 Local Alquiler Barcelona 108.79 858,131.42 09/11/2004 Luisa 2.Regular
74 Local Venta Girona 94.69 943,428.12 04/12/2004 Luisa 2.Regular
75 Local Venta Lleida 101.03 1,164,324.33 10/03/2005 Luisa 2.Regular
76 Local Venta Girona 76.79 907,700.58 27/11/2004 Luisa 2.Regular
77 Local Alquiler Barcelona 100.54 829,299.13 16/12/2004 Luisa 2.Regular
78 Local Alquiler Girona 111.73 1,136,670.39 30/04/2005 Luisa 2.Regular
79 Local Alquiler Tarragona 100.18 957,188.94 07/03/2005 Luisa 2.Regular
80 Local Alquiler Tarragona 104.58 719,844.85 16/05/2005 Luisa 2.Regular
81 Local Venta Tarragona 102.13 1,247,686.93 28/08/2005 Luisa 2.Regular
82 Local Alquiler Tarragona 87.57 675,706.21 05/02/2006 Luisa 2.Regular
83 Local Alquiler Lleida 106.79 961,195.26 12/08/2005 Luisa 2.Regular
84 Local Alquiler Barcelona 112.73 1,052,026.80 17/09/2005 Luisa 2.Regular
85 Local Venta Lleida 108.39 1,002,115.95 09/06/2006 Luisa 2.Regular
86 Local Alquiler Tarragona 89.71 774,266.83 18/05/2006 Luisa 2.Regular
87 Local Venta Girona 114.81 1,230,847.69 26/12/2006 Luisa 2.Regular
88 Local Alquiler Lleida 86.99 747,962.20 03/11/2006 Luisa 2.Regular
89 Local Venta Tarragona 86.48 753,038.17 29/01/2007 Luisa 2.Regular
90 Local Alquiler Girona 81.94 750,125.94 08/03/2007 Luisa 2.Regular
91 Local Venta Tarragona 102.02 977,356.92 14/04/2007 Luisa 2.Regular
92 Casa Alquiler Girona 186.93 2,044,534.82 12/04/2004 Lucia 2.Regular
93 Casa Venta Lleida 171.81 1,515,038.78 15/03/2005 Lucia 2.Regular
94 Casa Venta Girona 154.56 1,344,695.74 12/12/2005 Lucia 2.Regular
95 Casa Venta Barcelona 153 1,214,348.47 30/12/2005 Lucia 2.Regular
96 Casa Venta Girona 175.09 2,082,681.89 14/11/2005 Lucia 2.Regular
97 Casa Venta Lleida 143.09 1,652,795.01 27/12/2005 Lucia 2.Regular
98 Casa Alquiler Girona 171.77 1,913,086.31 23/10/2005 Lucia 2.Regular
99 Casa Alquiler Girona 175.67 2,094,244.06 25/05/2006 Lucia 2.Regular
100 Casa Venta Girona 178.95 1,828,248.49 02/07/2006 Lucia 2.Regular
101 Casa Venta Lleida 170.89 2,148,313.46 05/04/2006 Lucia 2.Regular
102 Casa Venta Lleida 179.74 1,551,170.45 14/12/2006 Lucia 2.Regular
103 Casa Venta Girona 169.27 1,586,220.37 13/04/2007 Lucia 2.Regular
104 Casa Venta Girona 186.43 2,019,635.50 13/01/2007 Lucia 2.Regular
105 Local Venta Tarragona 87.72 874,708.59 26/10/2004 Lucia 2.Regular
106 Local Alquiler Barcelona 82.11 808,343.40 10/12/2004 Lucia 2.Regular
107 Local Venta Lleida 91.61 889,909.25 07/04/2005 Lucia 2.Regular
108 Local Venta Lleida 89.5 895,333.79 03/08/2005 Lucia 2.Regular
109 Local Venta Lleida 105.48 977,865.35 04/09/2005 Lucia 2.Regular
110 Local Alquiler Barcelona 114.92 1,124,489.33 17/02/2006 Lucia 2.Regular
111 Local Venta Tarragona 103.49 1,177,649.04 17/12/2005 Lucia 2.Regular
112 Local Alquiler Tarragona 116.24 1,335,350.76 28/02/2006 Lucia 2.Regular
113 Local Alquiler Girona 108.2 1,066,300.83 01/09/2006 Lucia 2.Regular
114 Local Alquiler Girona 73.07 697,924.64 07/05/2006 Lucia 2.Regular
115 Local Alquiler Girona 121.85 1,291,349.49 21/02/2006 Lucia 2.Regular
116 Local Venta Barcelona 85.84 807,889.02 26/10/2006 Lucia 2.Regular
117 Local Venta Tarragona 83.49 923,256.37 16/11/2006 Lucia 2.Regular
118 Local Venta Girona 127.61 1,481,331.44 30/04/2007 Lucia 2.Regular
119 Local Alquiler Girona 88.04 976,352.38 17/10/2006 Lucia 2.Regular
120 Local Alquiler Barcelona 92.38 1,037,257.48 30/12/2006 Lucia 2.Regular
121 Casa Venta Barcelona 178.21 1,420,299.84 19/01/2005 Pedro 2.Regular
122 Casa Alquiler Girona 157.67 1,811,767.24 23/10/2004 Pedro 2.Regular
123 Casa Venta Lleida 180.85 1,920,160.12 27/09/2004 Pedro 2.Regular
124 Casa Alquiler Barcelona 175.33 1,627,159.11 01/02/2005 Pedro 2.Regular
125 Casa Venta Girona 163.03 1,338,587.81 28/12/2004 Pedro 2.Regular
126 Casa Alquiler Barcelona 182.86 1,535,627.95 13/12/2004 Pedro 2.Regular
127 Casa Venta Lleida 166.02 1,336,821.15 14/01/2005 Pedro 2.Regular
128 Casa Alquiler Girona 169.03 727,693.55 20/06/2005 Pedro 2.Regular
129 Casa Alquiler Barcelona 175.37 1,067,520.09 23/05/2005 Pedro 2.Regular
130 Casa Alquiler Lleida 148.46 1,171,275.75 14/05/2005 Pedro 2.Regular
131 Casa Venta Girona 147.91 1,650,142.59 29/08/2005 Pedro 2.Regular
132 Casa Alquiler Lleida 183.18 1,894,117.09 20/08/2005 Pedro 2.Regular
133 Casa Alquiler Tarragona 150.6 1,560,181.27 05/12/2005 Pedro 2.Regular
134 Casa Venta Barcelona 163.2 1,549,360.28 25/01/2006 Pedro 2.Regular
135 Casa Venta Tarragona 179.7 1,895,430.68 17/07/2005 Pedro 2.Regular
136 Casa Alquiler Barcelona 181.29 2,018,754.72 20/05/2006 Pedro 2.Regular
137 Casa Alquiler Tarragona 163.19 1,289,691.07 15/09/2005 Pedro 2.Regular
138 Casa Venta Tarragona 162.97 1,740,402.26 31/01/2006 Pedro 2.Regular
139 Casa Alquiler Tarragona 171.09 1,529,232.58 18/04/2006 Pedro 2.Regular
140 Casa Alquiler Barcelona 148.51 1,534,713.57 02/05/2006 Pedro 2.Regular
141 Casa Alquiler Girona 163.98 1,464,568.64 31/05/2006 Pedro 2.Regular
142 Casa Alquiler Girona 187.16 2,025,119.05 28/06/2006 Pedro 2.Regular
143 Casa Venta Girona 184.21 2,244,661.19 25/04/2006 Pedro 2.Regular
144 Casa Alquiler Barcelona 163.29 1,518,627.73 29/07/2006 Pedro 2.Regular
145 Casa Venta Girona 194.24 1,485,934.20 04/07/2006 Pedro 2.Regular
146 Casa Venta Tarragona 159.86 1,398,886.70 17/02/2007 Pedro 2.Regular
147 Casa Alquiler Tarragona 182.69 1,600,970.25 29/08/2006 Pedro 2.Regular
148 Casa Alquiler Barcelona 182.38 1,539,112.93 04/03/2007 Pedro 2.Regular
149 Casa Venta Barcelona 162.3 1,467,260.07 13/03/2007 Pedro 2.Regular

The thing Is that I need to create and show some graphics and explain them, I need to show this in a RMarkdown but that's another thing.
Here's all the data, and then I execute this:

library(readxl)
read_excel("Base2Hojas.xlsx")
##In this part I'm making a base with the data that I showed before
base <- read_excel("Base2Hojas.xlsx")
View(base)
BaseH1 <- read_excel("Base2Hojas.xlsx", sheet="Inmob")
attach(base)
##I Make a table with the information I showed before
TTipoInm <- table(Tipo_de_Inmueble)
TTipoInm <- transform(TTipoInm,
                      Porc= round(prop.table(Freq)*100, 2)))
##Then I save that stuff in a new object
etiquetas <- paste(names(TTipoInm),
                   round(TTipoInm/length(No)*100,2), "%")
##And when I try to execute this, here's the point where appears the error code which I said before
##As I said, when I tried at first, the error became, but after, a few hours later I writted it in the same way and it worked. Why?
pie(TTipoInm, main= "Tipo de Inmueble", col= rainbow(2), clockwise=T,
    labels= etiquetas)
legend= legend("topright", c("Casa", "Local"), cex= 0.8,
               fill= rainbow(length(TTipoInm)))
TProv <- table(Provincia)
piepercent1 <- round(100*TProv/length(No), 2)
pie(TProv, main= "Provincia", col= rainbow(length(TProv)), clockwise= T,
    labels= piepercent1)
legend('bottom', legend= rownames(TProv), bty='n',
       fill= (rainbow(length(TProv))), horiz= TRUE,
       inset= c(0,-0.1), xpd= TRUE, cex= 0.8)
legend= legend("topright", c("Casa", "Local"), cex= 0.8,
               fill= rainbow(length(TTipoInm)))

There's another thing, recently I tried to Markdown this, and I got this error:
Error in pie(TTipoInm, main = "Tipo de Inmueble", col = rainbow(2), clockwise = T, :
'x' values must be positive.
Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> pie
Ejecución interrumpida

Is this too much information? Sorry, I 'm new and I hope it's ok :frowning:

please edit your post. The guide you were linked to twice previously does not say to post markdown tables.
it says to use dput. also you should say what name in your code any data shared represents.

It seems you speak Spanish so maybe the Spanish version of the reprex guide would be easier to understand your fou.

THanks! Haha, I speak spanish, but I'm comfortable with the english, the thing is that I didn't know if the database I uploaded was enough, or too much lmao. Thank you!

Hi, sorry, That's an Excel data base, I show in that way cause It's the only way I found to show the data I work with, I tried to explain more my code execution, is it ok?

I think it's too much but that is not the main problem, if you read the guide you would notice that what you have posted is not in a copy/paste friendly format and it is not clear how it relates to your code.
Please read the guide (in case you haven't notice it is a link so you have to click on it to get the full content) more carefully and try to make a proper minimal reproducible example.

here is a quick way to supply some sample data

Run this and paste the results here
dput(head(BaseH1, 50))

Hmmm but BaseH1 is mentioned only once in the code. Therefore it cant be a contributing part of a chain of object manipulations

Probably the info used is in base, as that gets attached.
I would shy away from attaching with a beginner...

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.