gpt4 book ai didi

r - 将包含字符和数字的列分隔为每个类别的两个单独的列

转载 作者:行者123 更新时间:2023-12-05 09:28:26 27 4
gpt4 key购买 nike

<分区>

我想将名为 Demand Per Section 的数据框的第一列分成两个单独的列,分别名为 Units 字符和 Demand 数字值(value)观。

df<-structure(list(`Demand Per Section` = c("80 GM", "125ML", "350 ML", 
"100 GM", "538ML", "75GM", "25GM", "138GM", "138GM", "75GM"),
Formula = c("C10H8", "HNO3", "H2SO4", "C7H6O3", "CH3COOCOCH3",
"C10H8O", "NaOH", "C6H5NHNH2.HCl", "C6H12O6", "CH3COONa"),
`Element Name` = c("Naphthalene", "Nitric acid (concentrated)",
"Sulphuric acid(concentrated)", "2-hydroxybenzoic acid",
"Acetic anhydride", "2-Naphthol", "Sodium Hydroxide", "Phenyl hydrazine hydrochloride",
"Glucose", "Sodium acetate"), `Course Name` = c("Course 1",
"Course 1", "Course 1", "Course 1", "Course 1", "Course 1",
"Course 1", "Course 1", "Course 1", "Course 1"), Department = c("Chemsitry",
"Chemsitry", "Chemsitry", "Chemsitry", "Chemsitry", "Chemsitry",
"Chemsitry", "Chemsitry", "Chemsitry", "Chemsitry")), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))

library(tidyverse)
df %>%
mutate(Unit = str_extract(`Demand Per Section`, "[A-Z]?"),
Demand = str_extract(`Demand Per Section`, "[0-9]?")) %>%
select(`Demand Per Section`,Unit,Demand)

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com