as.numeric创建悬挂小数

时间:2018-03-05 17:48:04

标签: r

好奇什么导致了这种行为。读取excel文件,其中数字存储为文本。当我转换为数字时,整数会添加一个小数点(即153变为153)。否0,没有,只是一个挂小数。关于如何纠正这个问题的任何想法?

    structure(list(`Nest ID` = c("21Lk", "21Lk", "21Lk", "21Lk", 
"A-Frye"), `Clutch size` = c(NA_character_, NA_character_, NA_character_, 
NA_character_, NA_character_), `hatch size` = c("4", "4", "4", 
"4", "7"), `hatch date` = c("146", "146", "146", "146", "153"
), Date = c("149", "167", "188", "247", "161"), Time = c("900", 
"900", "1200", "1224", "1538"), Cygnets = c("4", "3", NA, NA, 
"7"), detection = c("1", "1", "0", "0", "1"), `Age when found (days)` = 
c("3", 
"3", "3", "3", "8"), `Age at time of observation (days)` = c("3", 
"21", "42", "101", "8"), `prob of complete brood loss` = c("0.5", 
"0.5", "0.5", "0.5", "0.1"), `Predator fish present (1 likely, 2 unknown, 0 
unlikely)` = c("1", 
"1", "1", "1", "1"), `Wetland Area (NWI) (ha)` = c("109.4938966", 
"109.4938966", "109.4938966", "109.4938966", "34.923899399999996"
), Notes = c(NA, NA, "unsure, could have been in the deep veg", 
"unsure, could have been in the deep veg", NA)), .Names = c("Nest ID", 
"Clutch size", "hatch size", "hatch date", "Date", "Time", "Cygnets", 
"detection", "Age when found (days)", "Age at time of observation (days)", 
"prob of complete brood loss", "Predator fish present (1 likely, 2 unknown, 
0 unlikely)", 
"Wetland Area (NWI) (ha)", "Notes"), row.names = c(NA, -5L), class = 
c("tbl_df", 
"tbl", "data.frame"))

以及用于转换/清理的代码

library(tidyverse)

test.2<-test%>%
    rename(NestID=`Nest ID`,
            CS=`Clutch size`,
            HS=`hatch size`,
            HD=`hatch date`,
            DOY=Date,
            Age.firstobs=`Age when found (days)`,
            Age.current=`Age at time of observation (days)`,
            is.broodloss=`prob of complete brood loss`,
            pred.fish=`Predator fish present (1 likely, 2 unknown, 0 unlikely)`,
            WA=`Wetland Area (NWI) (ha)`)%>%
    mutate_at(vars(CS:DOY,Cygnets,Age.firstobs,Age.current,pred.fish),funs(as.numeric))%>%
    mutate_at(vars(detection,is.broodloss,WA),funs(as.numeric))

0 个答案:

没有答案
相关问题