Numeric data is not numeric.

Hey

Sorry if this is in the wrong thread - wasn't sure where to put it.

I'm also not entirely sure which info to give here. But basically the first table is said not to be numeric, even though it is and it's exactly the same after using as.numeric on it. I'm unsure as to why this is happening and/or how to fix it. I'm using a Macbook running on OS Mojave. See picture below.

Thanks.

You can use the str function to find out what type a variable is.

For example

df <- data.frame(c1 = 1:3, c2 = c(1.2, 1.3, 1.4), c4 = LETTERS[1:3])
str(df)
#> 'data.frame':    3 obs. of  3 variables:
#>  $ c1: int  1 2 3
#>  $ c2: num  1.2 1.3 1.4
#>  $ c4: Factor w/ 3 levels "A","B","C": 1 2 3

Created on 2019-05-08 by the reprex package (v0.2.1)

Note this tells you that c1 and c2 are both numerics (an integer and a floating point are both considered numerics by R), where c4 is a factor.


As a note, it is extremely hard to help debug code and/or error messages when screenshots are posted. Posting screenshots, instead of actual code/error messages, is likely to decrease your chances of getting the help you are looking for in general.

I'd encourage you to ask this kind of question with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

Hi, thanks for the quick reply.
I'm really new to RStudio so I don't understand much from the "reprex" FAQ. Only things I managed to do is the str() and the deparse(). Hope this helps?

str(sportData)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 200 obs. of 7 variables:
leeftijd: num 29 27 13 12 16 20 42 31 35 31 ... gewicht : num 94 74 54 49 75 66 85 93 90 75 ...
lengte : num 166 181 148 150 160 187 172 166 169 164 ... tijd : chr "18" "22.1" "22.7" "24" ...
sport : chr "1" "2.5" "3" "1.5" ... geslacht: chr "V" "M" "M" "V" ...
$ type : chr "voetbal" "basketbal" "voetbal" "zwemmen" ...
deparse(sportData)
[1] "structure(list(leeftijd = c(29, 27, 13, 12, 16, 20, 42, 31, 35, "
[2] "31, 18, 24, 32, 23, 32, 47, 50, 15, 23, 34, 40, 25, 18, 9, 14, "
[3] "30, 23, 27, 42, 21, 17, 38, 35, 20, 46, 22, 43, 25, 10, 34, 11, "
[4] "33, 31, 50, 37, 39, 50, 46, 24, 44, 50, 47, 35, 9, 22, 39, 21, "
[5] "44, 49, 9, 11, 23, 39, 39, 33, 36, 32, 44, 10, 9, 31, 16, 17, "
[6] "14, 40, 47, 22, 30, 26, 28, 12, 20, 21, 18, 41, 33, 40, 16, 14, "
[7] "33, 39, 40, 14, 16, 43, 24, 32, 42, 39, 16, 35, 45, 44, 28, 31, "
[8] "21, 8, 43, 23, 40, 17, 48, 41, 48, 43, 42, 43, 26, 20, 8, 32, "
[9] "42, 18, 34, 46, 18, 43, 37, 8, 35, 41, 28, 33, 27, 36, 12, 30, "
[10] "30, 41, 12, 31, 43, 43, 36, 48, 20, 27, 18, 25, 30, 30, 48, 49, "
[11] "14, 18, 14, 14, 14, 37, 15, 14, 43, 40, 49, 18, 45, 45, 20, 20, "
[12] "21, 27, 24, 37, 46, 28, 44, 16, 10, 18, 8, 44, 18, 39, 23, 11, "
[13] "8, 22, 24, 41, 14, 35, 45, 26, 24, 38, 33, 26, 50, 41, 9), gewicht = c(94, "
[14] "74, 54, 49, 75, 66, 85, 93, 90, 75, 92, 81, 87, 83, 81, 83, 102, "
[15] "54, 88, 100, 90, 71, 78, 46, 59, 99, 78, 100, 99, 83, 75, 111, "
[16] "97, 72, 96, 89, 97, 93, 48, 99, 65, 79, 94, 98, 84, 89, 94, 95, "
[17] "80, 105, 91, 98, 93, 50, 104, 93, 95, 94, 82, 35, 60, 70, 94, "
[18] "101, 99, 78, 67, 74, 45, 34, 82, 76, 75, 75, 83, 92, 85, 86, "
[19] "99, 96, 54, 79, 79, 62, 93, 101, 99, 75, 57, 78, 102, 79, 80, "
[20] "84, 91, 87, 87, 84, 55, 72, 81, 94, 83, 97, 74, 86, 39, 91, 114, "
[21] "79, 75, 96, 78, 78, 100, 97, 80, 82, 74, 34, 90, 65, 63, 86, "
[22] "90, 93, 84, 99, 40, 100, 86, 91, 97, 87, 90, 59, 82, 71, 91, "
[23] "67, 76, 75, 77, 64, 116, 100, 103, 84, 92, 86, 87, 72, 93, 58, "
[24] "87, 60, 55, 68, 72, 75, 64, 79, 92, 113, 98, 101, 100, 92, 87, "
[25] "82, 90, 84, 93, 102, 83, 89, 72, 44, 71, 47, 100, 94, 93, 112, "
[26] "69, 35, 86, 88, 87, 72, 81, 108, 90, 98, 76, 71, 95, 114, 69, "
[27] "50), lengte = c(166, 181, 148, 150, 160, 187, 172, 166, 169, "
[28] "164, 179, 173, 178, 177, 187, 187, 181, 156, 176, 171, 192, 175, "
[29] "168, 134, 153, 196, 170, 176, 193, 159, 165, 196, 169, 180, 185, "
[30] "189, 199, 149, 147, 176, 149, 178, 177, 166, 163, 168, 175, 183, "
[31] "168, 168, 176, 170, 180, 122, 176, 156, 187, 161, 167, 130, 141, "
[32] "186, 173, 165, 196, 182, 176, 182, 146, 129, 162, 179, 169, 170, "
[33] "178, 184, 193, 173, 189, 166, 148, 176, 158, 171, 169, 164, 202, "
[34] "173, 166, 136, 192, 177, 173, 145, 186, 171, 165, 175, 193, 181, "
[35] "185, 162, 196, 178, 167, 178, 130, 193, 172, 164, 172, 194, 167, "
[36] "181, 191, 172, 160, 192, 189, 140, 177, 194, 183, 177, 199, 194, "
[37] "168, 187, 126, 180, 171, 206, 171, 189, 166, 176, 164, 153, 165, "
[38] "143, 180, 159, 184, 160, 178, 184, 180, 182, 186, 176, 163, 180, "
[39] "164, 159, 169, 157, 166, 162, 165, 164, 141, 171, 160, 156, 188, "
[40] "182, 155, 176, 165, 169, 182, 170, 186, 172, 171, 172, 169, 135, "
[41] "175, 136, 175, 182, 187, 146, 154, 123, 167, 185, 164, 153, 168, "
[42] "163, 174, 195, 180, 157, 193, 159, 183, 150), tijd = c("18", "
[43] ""22.1", "22.7", "24", "23.8", "17.9", "24.6", "19.9", "21.3", "
[44] ""22.5", "20.7", "17", "18.9", "21.2", "23.4", "26.6", "34.3", "
[45] ""23.8", "22.4", "24.8", "25.1", "22", "21.7", "31", "23.8", "24", "
[46] ""17.6", "17.3", "26", "18.7", "19.4", "19.2", "29.3", "18.6", "
[47] ""28.1", "25.5", "31.2", "15.4", "25.9", "23.4", "27.2", "22.2", "
[48] ""18.3", "27.6", "19", "27.1", "26.2", "23.8", "15", "21.1", "34.8", "
[49] ""31.8", "22.2", "26.9", "19.5", "23.6", "25.2", "28.3", "23.9", "
[50] ""30.5", "26.3", "22.8", "19.2", "30", "26.6", "23.6", "22.1", "
[51] ""30.3", "25.3", "23.9", "18.6", "19.2", "24.6", "23.3", "22.2", "
[52] ""24.6", "22.1", "23.6", "15.3", "25.1", "35.3", "21.3", "20.6", "
[53] ""20.8", "29.1", "18.2", "25.1", "20.3", "21.8", "20.1", "23.4", "
[54] ""21.7", "26.9", "19.4", "23.2", "17.4", "18.3", "26.6", "20.5", "
[55] ""21.4", "15.6", "25.3", "20.4", "23.2", "14.9", "26.8", "25.1", "
[56] ""19.8", "25.4", "17.5", "21.5", "32.5", "21.8", "28.4", "18.7", "
[57] ""16.5", "24", "15.2", "25.6", "26.4", "12.8", "18.1", "21.2", "
[58] ""18.5", "32.6", "16.6", "20.8", "18", "32.6", "22.3", "29.2", "
[59] ""16", "19.6", "18.8", "22.4", "26.2", "17.4", "18.1", "25.1", "
[60] ""26.9", "22.7", "22", "29.1", "21.1", "27.7", "15.6", "23", "16.2", "
[61] ""14.1", "20.9", "17.9", "27.4", "34.4", "24.7", "11.1", "16.4", "
[62] ""18.3", "28.4", "23", "21.4", "18.9", "32.6", "22.3", "21.6", "
[63] ""26.3", "32.4", "22.1", "25.1", "22.1", "20", "23.2", "18.3", "
[64] ""21.2", "24.4", "24.7", "24.1", "25", "25.4", "22.9", "29.6", "
[65] ""31.4", "16.7", "26.9", "22.5", "30.9", "30", "20.5", "16.4", "
[66] ""20.9", "22.2", "22.1", "26", "12.7", "20", "29.4", "19.7", "17.6", "
[67] ""28.5", "21.8", "26"), sport = c("1", "2.5", "3", "1.5", "4", "
[68] ""2", "3", "2", "4", "2.5", "2", "1.5", "2", "2", "4", "5.5", "
[69] ""4.5", "3", "4.5", "5.5", "1.5", "2.5", "2", "4.5", "2.5", "4.5", "
[70] ""3", "4", "3.5", "3", "2.5", "1", "4", "2.5", "5.5", "2.5", "4", "
[71] ""2", "4", "3.5", "3.5", "3.5", "1.5", "3.5", "3", "4", "3.5", "
[72] ""1.5", "3.5", "2", "4.5", "4", "3", "2", "2.5", "2", "3.5", "3", "
[73] ""2", "4.5", "3.5", "3.5", "3.5", "4.5", "4", "3", "2.5", "4", "
[74] ""2.5", "3", "4", "2.5", "2", "3", "2.5", "2", "3", "3.5", "3.5", "
[75] ""2", "4.5", "3.5", "3", "2.5", "5", "4", "2", "3", "3", "4", "
[76] ""3.5", "2.5", "3.5", "3", "4", "3", "2.5", "1", "2", "3", "1", "
[77] ""4.5", "2", "4", "2", "3", "2.5", "3", "2", "4.5", "3", "5", "
[78] ""2", "0.5", "2", "1.5", "2", "2", "1", "3.5", "1", "3", "1.5", "
[79] ""1.5", "3.5", "2.5", "2.5", "3", "4.5", "2.5", "1.5", "1.5", "
[80] ""2", "3", "4", "2.5", "2", "3", "2", "5.5", "3", "1.5", "3", "
[81] ""1", "4", "2.5", "2", "1.5", "2", "2", "3", "3.5", "3.5", "3.5", "
[82] ""2", "1", "3", "2", "4.5", "1", "1.5", "4", "4", "3.5", "2.5", "
[83] ""4", "2.5", "4", "1.5", "2", "2.5", "3", "3.5", "3", "4", "3", "
[84] ""3.5", "2", "2", "3.5", "3", "1.5", "2.5", "4", "2.5", "3", "3", "
[85] ""3.5", "3", "0", "0", "2", "3", "4", "3", "2.5", "3.5", "3.5", "
[86] ""4", "3"), geslacht = c("V", "M", "M", "V", "V", "V", "M", "V", "
[87] ""V", "M", "M", "M", "M", "M", "V", "V", "V", "M", "V", "V", "V", "
[88] ""M", "M", "V", "V", "M", "V", "V", "M", "M", "V", "M", "M", "V", "
[89] ""V", "M", "M", "M", "V", "V", "V", "M", "V", "M", "V", "V", "V", "
[90] ""V", "V", "M", "V", "M", "M", "V", "M", "M", "V", "V", "M", "V", "
[91] ""V", "V", "M", "M", "V", "M", "M", "V", "M", "V", "M", "V", "M", "
[92] ""M", "M", "M", "V", "M", "M", "V", "M", "V", "M", "M", "V", "V", "
[93] ""V", "V", "M", "V", "M", "M", "M", "M", "M", "V", "V", "M", "M", "
[94] ""M", "V", "V", "V", "V", "M", "M", "V", "V", "V", "M", "M", "M", "
[95] ""V", "M", "M", "M", "V", "V", "M", "V", "V", "M", "V", "M", "V", "
[96] ""V", "M", "M", "V", "V", "V", "V", "M", "V", "V", "M", "M", "V", "
[97] ""V", "V", "M", "M", "V", "M", "V", "V", "V", "M", "V", "V", "M", "
[98] ""M", "V", "V", "M", "V", "V", "M", "M", "M", "M", "V", "V", "M", "
[99] ""M", "V", "V", "V", "V", "V", "M", "V", "M", "M", "V", "M", "V", "
[100] ""V", "M", "M", "V", "V", "M", "V", "M", "M", "V", "M", "M", "M", "
[101] ""V", "V", "M", "V", "V", "V", "V", "M", "V", "V"), type = c("voetbal", "
[102] ""basketbal", "voetbal", "zwemmen", "andere", "tennis", "voetbal", "
[103] ""andere", "voetbal", "basketbal", "voetbal", "voetbal", "andere", "
[104] ""basketbal", "andere", "andere", "andere", "voetbal", "basketbal", "
[105] ""andere", "andere", "andere", "andere", "zwemmen", "basketbal", "
[106] ""voetbal", "voetbal", "voetbal", "voetbal", "tennis", "voetbal", "
[107] ""tennis", "voetbal", "basketbal", "voetbal", "basketbal", "voetbal", "
[108] ""andere", "zwemmen", "basketbal", "voetbal", "zwemmen", "zwemmen", "
[109] ""voetbal", "basketbal", "andere", "voetbal", "zwemmen", "voetbal", "
[110] ""voetbal", "voetbal", "andere", "voetbal", "tennis", "voetbal", "
[111] ""andere", "voetbal", "tennis", "basketbal", "voetbal", "basketbal", "
[112] ""voetbal", "zwemmen", "voetbal", "tennis", "tennis", "tennis", "
[113] ""andere", "basketbal", "andere", "tennis", "zwemmen", "basketbal", "
[114] ""zwemmen", "zwemmen", "voetbal", "andere", "andere", "andere", "
[115] ""basketbal", "zwemmen", "tennis", "basketbal", "basketbal", "basketbal", "
[116] ""tennis", "basketbal", "andere", "voetbal", "zwemmen", "zwemmen", "
[117] ""voetbal", "voetbal", "voetbal", "andere", "voetbal", "voetbal", "
[118] ""zwemmen", "tennis", "voetbal", "andere", "tennis", "zwemmen", "
[119] ""tennis", "tennis", "voetbal", "andere", "andere", "andere", "
[120] ""andere", "tennis", "andere", "zwemmen", "voetbal", "zwemmen", "
[121] ""zwemmen", "tennis", "tennis", "voetbal", "zwemmen", "basketbal", "
[122] ""voetbal", "tennis", "voetbal", "basketbal", "tennis", "basketbal", "
[123] ""voetbal", "tennis", "tennis", "tennis", "zwemmen", "voetbal", "
[124] ""andere", "zwemmen", "voetbal", "andere", "tennis", "andere", "
[125] ""andere", "zwemmen", "voetbal", "voetbal", "basketbal", "basketbal", "
[126] ""voetbal", "zwemmen", "zwemmen", "basketbal", "zwemmen", "andere", "
[127] ""tennis", "tennis", "tennis", "andere", "basketbal", "basketbal", "
[128] ""andere", "voetbal", "andere", "zwemmen", "voetbal", "andere", "
[129] ""voetbal", "tennis", "voetbal", "voetbal", "zwemmen", "tennis", "
[130] ""voetbal", "voetbal", "voetbal", "voetbal", "voetbal", "tennis", "
[131] ""voetbal", "tennis", "basketbal", "andere", "basketbal", "zwemmen", "
[132] ""zwemmen", "tennis", "zwemmen", "voetbal", "basketbal", "tennis", "
[133] ""zwemmen", "andere", "zwemmen", "basketbal", "zwemmen", "zwemmen", "
[134] ""basketbal", "tennis", "zwemmen", "zwemmen", "voetbal", "zwemmen", "
[135] ""tennis")), row.names = c(NA, -200L), class = c("tbl_df", "tbl", "
[136] ""data.frame"))"

I don't understand why "tijd" and "sport" aren't numeric.

They're likely character because of how sportData was created. How did you create the sportData object? Did you read it from a file? If so, could you share the code you used to do that?

Hi,

This looks Dutch to me, and if you're like Denmark you use a comma as decimal separator, not a period as UK/US does. This may be why the floating point numbers were read as characters instead of numbers. You don't show how you created the sportData data frame, but most input functions have a "delimiter" option.

Cheers
Steen

1 Like

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