The type is integer, yet it has a decimal point. Why?











up vote
0
down vote

favorite












When I check the type, it said "integer", but has decimal point. If I change it to numeric, it become integer(no decimal point).
Because I want to do histogram, x must be numeric, but if change to numeric, all data wrong.



> typeof(data$fare_amount)
[1] "integer"
> data$fare_amount
[1] 5.5 6.5 8.0 13.5 5.5 9.5 7.5 8.0 16.0 8.0 5.5 7.0 8.0 5.0 9.5 23.0 5.0 6.0 17.5 12.0 8.5 13.0
[23] 6.5 4.5 52.0 14.5 7.5 4.5 9.0 10.0 15.0 11.5 6.0 12.5 7.5 8.0 6.5 7.5 31.5 10.0 10.0 10.0 4.0 8.5
[45] 24.0 8.5 5.5 14.0 11.0 4.5 9.0 7.5 22.0 8.5 24.0 36.5 15.0 10.5 9.5 17.0 4.5 6.0 6.5 11.5 16.0 6.5
[67] 7.0 20.0 13.5 30.0 8.0 11.0 6.5 11.5 6.5 37.0 5.5 12.5 8.5 58.5 13.5 8.5 9.0 6.0 6.5 9.0 38.0 4.5
[89] 10.0 9.0 44.5 11.0 12.0 4.5 14.5 8.5 32.0 9.5 4.5 6.0 6.5 6.0 31.5 52.0 10.5 12.0 5.5 24.5 7.0 5.5
[111] 16.5 5.0 5.5 6.5 3.5 11.5 13.0 6.0 14.0 3.5
42 Levels: 13.5 16.0 5.5 6.5 7.5 8.0 9.5 12.0 17.5 23.0 5.0 6.0 7.0 10.0 13.0 14.5 4.5 52.0 8.5 9.0 11.5 12.5 ... 3.5
> temp <- as.numeric(data$fare_amount)
> temp
[1] 3 4 6 1 3 7 5 6 2 6 3 13 6 11 7 10 11 12 9 8 19 15 4 17 18 16 5 17 20 14 23 21 12 22 5 6 4 5
[39] 24 14 14 14 28 19 27 19 3 26 25 17 20 5 31 19 27 32 23 29 7 30 17 12 4 21 2 4 13 33 1 34 6 25 4 21 4 35
[77] 3 22 19 36 1 19 20 12 4 20 37 17 14 20 39 25 8 17 16 19 38 7 17 12 4 12 24 18 29 8 3 40 13 3 41 11 3 4
[115] 42 21 15 12 26 42









share|improve this question




















  • 4




    the type is integer, but your variable class is a factor. try as.numeric(as.character(x)) first
    – Zelazny7
    Nov 17 at 14:37










  • @Zelazny7 Yes, it works using as.numeric(as.character(data$fare_amount)), thanks a lot.
    – May Wong
    Nov 17 at 14:42






  • 4




    The bigger thing you should address is why that field is a factor in the first place. How are you reading it in? R thinks there's a character string in the data somewhere and treating it as a factor.
    – Zelazny7
    Nov 17 at 14:56






  • 4




    Check classic pitfalls: single comma decimal separator? decimal separator in your locale? NA coded as some other character? dollar signs? etc etc etc.
    – Henrik
    Nov 17 at 15:01












  • notstatschat.tumblr.com/post/124987394001/stringsasfactors-sigh
    – Ben Bolker
    Nov 17 at 15:14















up vote
0
down vote

favorite












When I check the type, it said "integer", but has decimal point. If I change it to numeric, it become integer(no decimal point).
Because I want to do histogram, x must be numeric, but if change to numeric, all data wrong.



> typeof(data$fare_amount)
[1] "integer"
> data$fare_amount
[1] 5.5 6.5 8.0 13.5 5.5 9.5 7.5 8.0 16.0 8.0 5.5 7.0 8.0 5.0 9.5 23.0 5.0 6.0 17.5 12.0 8.5 13.0
[23] 6.5 4.5 52.0 14.5 7.5 4.5 9.0 10.0 15.0 11.5 6.0 12.5 7.5 8.0 6.5 7.5 31.5 10.0 10.0 10.0 4.0 8.5
[45] 24.0 8.5 5.5 14.0 11.0 4.5 9.0 7.5 22.0 8.5 24.0 36.5 15.0 10.5 9.5 17.0 4.5 6.0 6.5 11.5 16.0 6.5
[67] 7.0 20.0 13.5 30.0 8.0 11.0 6.5 11.5 6.5 37.0 5.5 12.5 8.5 58.5 13.5 8.5 9.0 6.0 6.5 9.0 38.0 4.5
[89] 10.0 9.0 44.5 11.0 12.0 4.5 14.5 8.5 32.0 9.5 4.5 6.0 6.5 6.0 31.5 52.0 10.5 12.0 5.5 24.5 7.0 5.5
[111] 16.5 5.0 5.5 6.5 3.5 11.5 13.0 6.0 14.0 3.5
42 Levels: 13.5 16.0 5.5 6.5 7.5 8.0 9.5 12.0 17.5 23.0 5.0 6.0 7.0 10.0 13.0 14.5 4.5 52.0 8.5 9.0 11.5 12.5 ... 3.5
> temp <- as.numeric(data$fare_amount)
> temp
[1] 3 4 6 1 3 7 5 6 2 6 3 13 6 11 7 10 11 12 9 8 19 15 4 17 18 16 5 17 20 14 23 21 12 22 5 6 4 5
[39] 24 14 14 14 28 19 27 19 3 26 25 17 20 5 31 19 27 32 23 29 7 30 17 12 4 21 2 4 13 33 1 34 6 25 4 21 4 35
[77] 3 22 19 36 1 19 20 12 4 20 37 17 14 20 39 25 8 17 16 19 38 7 17 12 4 12 24 18 29 8 3 40 13 3 41 11 3 4
[115] 42 21 15 12 26 42









share|improve this question




















  • 4




    the type is integer, but your variable class is a factor. try as.numeric(as.character(x)) first
    – Zelazny7
    Nov 17 at 14:37










  • @Zelazny7 Yes, it works using as.numeric(as.character(data$fare_amount)), thanks a lot.
    – May Wong
    Nov 17 at 14:42






  • 4




    The bigger thing you should address is why that field is a factor in the first place. How are you reading it in? R thinks there's a character string in the data somewhere and treating it as a factor.
    – Zelazny7
    Nov 17 at 14:56






  • 4




    Check classic pitfalls: single comma decimal separator? decimal separator in your locale? NA coded as some other character? dollar signs? etc etc etc.
    – Henrik
    Nov 17 at 15:01












  • notstatschat.tumblr.com/post/124987394001/stringsasfactors-sigh
    – Ben Bolker
    Nov 17 at 15:14













up vote
0
down vote

favorite









up vote
0
down vote

favorite











When I check the type, it said "integer", but has decimal point. If I change it to numeric, it become integer(no decimal point).
Because I want to do histogram, x must be numeric, but if change to numeric, all data wrong.



> typeof(data$fare_amount)
[1] "integer"
> data$fare_amount
[1] 5.5 6.5 8.0 13.5 5.5 9.5 7.5 8.0 16.0 8.0 5.5 7.0 8.0 5.0 9.5 23.0 5.0 6.0 17.5 12.0 8.5 13.0
[23] 6.5 4.5 52.0 14.5 7.5 4.5 9.0 10.0 15.0 11.5 6.0 12.5 7.5 8.0 6.5 7.5 31.5 10.0 10.0 10.0 4.0 8.5
[45] 24.0 8.5 5.5 14.0 11.0 4.5 9.0 7.5 22.0 8.5 24.0 36.5 15.0 10.5 9.5 17.0 4.5 6.0 6.5 11.5 16.0 6.5
[67] 7.0 20.0 13.5 30.0 8.0 11.0 6.5 11.5 6.5 37.0 5.5 12.5 8.5 58.5 13.5 8.5 9.0 6.0 6.5 9.0 38.0 4.5
[89] 10.0 9.0 44.5 11.0 12.0 4.5 14.5 8.5 32.0 9.5 4.5 6.0 6.5 6.0 31.5 52.0 10.5 12.0 5.5 24.5 7.0 5.5
[111] 16.5 5.0 5.5 6.5 3.5 11.5 13.0 6.0 14.0 3.5
42 Levels: 13.5 16.0 5.5 6.5 7.5 8.0 9.5 12.0 17.5 23.0 5.0 6.0 7.0 10.0 13.0 14.5 4.5 52.0 8.5 9.0 11.5 12.5 ... 3.5
> temp <- as.numeric(data$fare_amount)
> temp
[1] 3 4 6 1 3 7 5 6 2 6 3 13 6 11 7 10 11 12 9 8 19 15 4 17 18 16 5 17 20 14 23 21 12 22 5 6 4 5
[39] 24 14 14 14 28 19 27 19 3 26 25 17 20 5 31 19 27 32 23 29 7 30 17 12 4 21 2 4 13 33 1 34 6 25 4 21 4 35
[77] 3 22 19 36 1 19 20 12 4 20 37 17 14 20 39 25 8 17 16 19 38 7 17 12 4 12 24 18 29 8 3 40 13 3 41 11 3 4
[115] 42 21 15 12 26 42









share|improve this question















When I check the type, it said "integer", but has decimal point. If I change it to numeric, it become integer(no decimal point).
Because I want to do histogram, x must be numeric, but if change to numeric, all data wrong.



> typeof(data$fare_amount)
[1] "integer"
> data$fare_amount
[1] 5.5 6.5 8.0 13.5 5.5 9.5 7.5 8.0 16.0 8.0 5.5 7.0 8.0 5.0 9.5 23.0 5.0 6.0 17.5 12.0 8.5 13.0
[23] 6.5 4.5 52.0 14.5 7.5 4.5 9.0 10.0 15.0 11.5 6.0 12.5 7.5 8.0 6.5 7.5 31.5 10.0 10.0 10.0 4.0 8.5
[45] 24.0 8.5 5.5 14.0 11.0 4.5 9.0 7.5 22.0 8.5 24.0 36.5 15.0 10.5 9.5 17.0 4.5 6.0 6.5 11.5 16.0 6.5
[67] 7.0 20.0 13.5 30.0 8.0 11.0 6.5 11.5 6.5 37.0 5.5 12.5 8.5 58.5 13.5 8.5 9.0 6.0 6.5 9.0 38.0 4.5
[89] 10.0 9.0 44.5 11.0 12.0 4.5 14.5 8.5 32.0 9.5 4.5 6.0 6.5 6.0 31.5 52.0 10.5 12.0 5.5 24.5 7.0 5.5
[111] 16.5 5.0 5.5 6.5 3.5 11.5 13.0 6.0 14.0 3.5
42 Levels: 13.5 16.0 5.5 6.5 7.5 8.0 9.5 12.0 17.5 23.0 5.0 6.0 7.0 10.0 13.0 14.5 4.5 52.0 8.5 9.0 11.5 12.5 ... 3.5
> temp <- as.numeric(data$fare_amount)
> temp
[1] 3 4 6 1 3 7 5 6 2 6 3 13 6 11 7 10 11 12 9 8 19 15 4 17 18 16 5 17 20 14 23 21 12 22 5 6 4 5
[39] 24 14 14 14 28 19 27 19 3 26 25 17 20 5 31 19 27 32 23 29 7 30 17 12 4 21 2 4 13 33 1 34 6 25 4 21 4 35
[77] 3 22 19 36 1 19 20 12 4 20 37 17 14 20 39 25 8 17 16 19 38 7 17 12 4 12 24 18 29 8 3 40 13 3 41 11 3 4
[115] 42 21 15 12 26 42






r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 at 15:11









user2722968

2,5991635




2,5991635










asked Nov 17 at 14:34









May Wong

1215




1215








  • 4




    the type is integer, but your variable class is a factor. try as.numeric(as.character(x)) first
    – Zelazny7
    Nov 17 at 14:37










  • @Zelazny7 Yes, it works using as.numeric(as.character(data$fare_amount)), thanks a lot.
    – May Wong
    Nov 17 at 14:42






  • 4




    The bigger thing you should address is why that field is a factor in the first place. How are you reading it in? R thinks there's a character string in the data somewhere and treating it as a factor.
    – Zelazny7
    Nov 17 at 14:56






  • 4




    Check classic pitfalls: single comma decimal separator? decimal separator in your locale? NA coded as some other character? dollar signs? etc etc etc.
    – Henrik
    Nov 17 at 15:01












  • notstatschat.tumblr.com/post/124987394001/stringsasfactors-sigh
    – Ben Bolker
    Nov 17 at 15:14














  • 4




    the type is integer, but your variable class is a factor. try as.numeric(as.character(x)) first
    – Zelazny7
    Nov 17 at 14:37










  • @Zelazny7 Yes, it works using as.numeric(as.character(data$fare_amount)), thanks a lot.
    – May Wong
    Nov 17 at 14:42






  • 4




    The bigger thing you should address is why that field is a factor in the first place. How are you reading it in? R thinks there's a character string in the data somewhere and treating it as a factor.
    – Zelazny7
    Nov 17 at 14:56






  • 4




    Check classic pitfalls: single comma decimal separator? decimal separator in your locale? NA coded as some other character? dollar signs? etc etc etc.
    – Henrik
    Nov 17 at 15:01












  • notstatschat.tumblr.com/post/124987394001/stringsasfactors-sigh
    – Ben Bolker
    Nov 17 at 15:14








4




4




the type is integer, but your variable class is a factor. try as.numeric(as.character(x)) first
– Zelazny7
Nov 17 at 14:37




the type is integer, but your variable class is a factor. try as.numeric(as.character(x)) first
– Zelazny7
Nov 17 at 14:37












@Zelazny7 Yes, it works using as.numeric(as.character(data$fare_amount)), thanks a lot.
– May Wong
Nov 17 at 14:42




@Zelazny7 Yes, it works using as.numeric(as.character(data$fare_amount)), thanks a lot.
– May Wong
Nov 17 at 14:42




4




4




The bigger thing you should address is why that field is a factor in the first place. How are you reading it in? R thinks there's a character string in the data somewhere and treating it as a factor.
– Zelazny7
Nov 17 at 14:56




The bigger thing you should address is why that field is a factor in the first place. How are you reading it in? R thinks there's a character string in the data somewhere and treating it as a factor.
– Zelazny7
Nov 17 at 14:56




4




4




Check classic pitfalls: single comma decimal separator? decimal separator in your locale? NA coded as some other character? dollar signs? etc etc etc.
– Henrik
Nov 17 at 15:01






Check classic pitfalls: single comma decimal separator? decimal separator in your locale? NA coded as some other character? dollar signs? etc etc etc.
– Henrik
Nov 17 at 15:01














notstatschat.tumblr.com/post/124987394001/stringsasfactors-sigh
– Ben Bolker
Nov 17 at 15:14




notstatschat.tumblr.com/post/124987394001/stringsasfactors-sigh
– Ben Bolker
Nov 17 at 15:14

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53352201%2fthe-type-is-integer-yet-it-has-a-decimal-point-why%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53352201%2fthe-type-is-integer-yet-it-has-a-decimal-point-why%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin