0
我有一個下一個任務如何申請規模規則很多列在新的數據集
a = data.frame(a= c(1,2,3,4,5,6)) # dataset
range01 <- function(x){(x-min(a$a))/(max(a$a)-min(a$a))} # rule for scale
b = data.frame(a = 6) # newdaset
lapply(b$a, range01) # we can apply range01 for this dataset because we use min(a$a) in the rule
但我怎麼可以把這個當我有很多列在我的數據集?像下面
a = data.frame(a= c(1,2,3,4,5,6))
b = data.frame(b= c(1,2,3,3,2,1))
c = data.frame(c= c(6,2,4,4,5,6))
df = cbind(a,b,c)
df
new = data.frame(a = 1, b = 2, c = 3)
我當然可以制定規則,爲每個變量
range01a <- function(x){(x-min(df$a))/(max(df$a)-min(df$a))}
但它很長的路要走。如何使它方便?