我正在寻找R的dplyr中的mutate_if()
。例如,如何选择Int64
列并将其转换为Float?
using DataFrames
df = DataFrame(A = [72, 38, 54],
B = [1, 2, 3],
C = ["red", "blue", "green"])
# convert integer columns to decimal columns without selecting them by name
df
答案 0 :(得分:2)
是的。该代码将具有任何整数类型(例如Int64
,Int32
)的列转换为Float64
。
for col in findall(x -> x <:Integer, eltypes(df))
df[!, col] = Float64.(df2[!, col])
end