更改列表中R数据帧的变量类型

更改列表中R数据帧的变量类型,r,dataframe,R,Dataframe,我有一个数据帧列表,我需要将每个数据帧中的某个变量转换为因子 例如 myList根据David Arenburg的评论,此解决方案应该可以: TMP <- lapply(myList, function(x) {x[, "B"] <- factor(x[, "B"]) ; x}) ; str(TMP) TMP类似于TMP的东西谢谢!这正是我需要的。 TMP <- setNames(lapply(seq_along(myList), function(x) apply(myL

我有一个数据帧列表,我需要将每个数据帧中的某个变量转换为因子

例如


myList根据David Arenburg的评论,此解决方案应该可以:

TMP <- lapply(myList, function(x) {x[, "B"] <- factor(x[, "B"]) ; x}) ; str(TMP)

TMP类似于
TMP的东西谢谢!这正是我需要的。
 TMP <- setNames(lapply(seq_along(myList), function(x) apply(myList[[x]][c("B")], 2, factor)), names(myList))
TMP <- lapply(myList, function(x) {x[, "B"] <- factor(x[, "B"]) ; x}) ; str(TMP)