如何将R中列表中的数据帧的字符更改为数字?
我想将列表数据框中的字符向量转换为数字向量。我附上了一个例子。最后的数据看起来像我的列表,我直接导入到 R 中,并且我想将其中的字符转换为数字...
set.seed(94756)
mat1 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat1 <- as.data.frame(mat1)
mat1$V2 <- as.character(mat1$V2)
mat2 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat2 <- as.data.frame(mat2)
mat2$V2 <- as.character(mat2$V2)
mat3 <- matrix(sample(seq(-1,100, 0.11), 50,replace = TRUE),ncol = 5)
mat3 <- as.data.frame(mat2)
mat3$V2 <- as.character(mat3$V2)
data <- list(mat1, mat2, mat3)
提前致谢!
I would like to convert a character vector within a dataframe of a list into a numeric one. I have an example attached. Data at the end looks like my list I import directly into R and in which I want to convert character into numeric...
set.seed(94756)
mat1 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat1 <- as.data.frame(mat1)
mat1$V2 <- as.character(mat1$V2)
mat2 <- matrix(sample(seq(-1,100, 0.11),50, replace = TRUE),ncol = 5)
mat2 <- as.data.frame(mat2)
mat2$V2 <- as.character(mat2$V2)
mat3 <- matrix(sample(seq(-1,100, 0.11), 50,replace = TRUE),ncol = 5)
mat3 <- as.data.frame(mat2)
mat3$V2 <- as.character(mat3$V2)
data <- list(mat1, mat2, mat3)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
type.convert
也可以更改list
中的列类型(假设data.frame
中的这些列没有任何非数字元素在其中)-输出
type.convert
can change column types inlist
as well (assuming those columns within thedata.frame
doesn't have any non-numeric element in it)-output