Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用R操作多个变量(79x1532)?_R_Data Manipulation_Data Wrangling - Fatal编程技术网

如何使用R操作多个变量(79x1532)?

如何使用R操作多个变量(79x1532)?,r,data-manipulation,data-wrangling,R,Data Manipulation,Data Wrangling,我是一个努力学习数据争论的新手。目前,我陷入了79x1532数据帧的数据争论中 我的数据框有79个样本行和1532列—2个样本标识符列,1530个化学浓度列(79x1532),如下所示 wc_sample_conc_df # A tibble: 79 x 1,532 `Sample Name` `Sample Number` `1,2,4-Trichlor… `1,2-Dibromo-3-… `o-Dichlorobenz… `1,3-Dichlorobe… `p-Dichlorobenz

我是一个努力学习数据争论的新手。目前,我陷入了79x1532数据帧的数据争论中

我的数据框有79个样本行和1532列—2个样本标识符列,1530个化学浓度列(79x1532),如下所示

wc_sample_conc_df
# A tibble: 79 x 1,532
   `Sample Name` `Sample Number` `1,2,4-Trichlor… `1,2-Dibromo-3-… `o-Dichlorobenz… `1,3-Dichlorobe… `p-Dichlorobenz… `1,4-Naphthoqui…
   <chr>         <chr>           <chr>            <chr>            <chr>            <chr>            <chr>            <chr>           
 1 CAS 001       A191916         <276             <423             <340             <340             <340             <6.32e+006      
 2 CAS 002       A191917         <276             <423             <340             <340             <340             <6.32e+006      
 3 CAS 003       A191918         <276             <423             <340             <340             <340             <6.32e+006      
 4 CAS 004       A191919         <276             <423             <340             <340             <340             <6.32e+006      
 5 CAS 005       A191920         <276             <423             <340             <340             <340             <6.32e+006      
 6 CAS 006       A191921         <276             <423             <340             <340             <340             <6.32e+006      
 7 CAS 007       A191922         <276             <423             <340             <340             <340             <6.32e+006      
 8 CAS 08        A191923         <276             <423             <340             <340             <340             <6.32e+006      
 9 CAS 009       A191924         <276             <423             <340             <340             <340             <6.32e+006      
10 CAS 010       A191925         <276             <423             <340             <340             <340             <6.32e+006      
# … with 69 more rows, and 1,524 more variables: 
我收到了这个错误信息,不知道如何修复,也不知道从哪里开始

Error in .(.) : could not find function "."
In addition: Warning messages:
1: In stri_replace_first_regex(string, pattern, fix_replacement(replacement),  :
  argument is not an atomic vector; coercing
2: In wc_sample_conc_df %>% mutate(`1,2,4-Trichlorobenzene Concentration` = case_when(grepl("<",  : NAs introduced by coercion
(.)中的
错误:找不到函数“”
此外:警告信息:
1:在stri_replace_first_regex(字符串、模式、修复_replacement(replacement))中:
参数不是原子向量;强制

2:在wc_样品中,浓度df%>%突变(`1,2,4-三氯苯浓度`=case_时(grepl(“我们可以在
之间循环
,其中
任何
子字符串,并且
@akrun已经回答了您的问题。我要补充的是,如果您制作了数据集,您的生活可能会更轻松。在这里,这意味着使用
pivot\u long
来创建包含列的数据框(比如)SampleName、SampleNumber、分析物和浓度,共79x1532行。(创建类似LLQ的SOP方法来标记那些最初有“@Limey感谢您的评论。原始原始数据是从1530种化学物质的GC/MS生成的,并且”谢谢你的回答。我试过使用你的命令,但又出现了一个错误。“~{tmp@JYL对不起,在
的where
行中缺少了一个
。你能再试一次吗非常感谢!它很有效!
Error in .(.) : could not find function "."
In addition: Warning messages:
1: In stri_replace_first_regex(string, pattern, fix_replacement(replacement),  :
  argument is not an atomic vector; coercing
2: In wc_sample_conc_df %>% mutate(`1,2,4-Trichlorobenzene Concentration` = case_when(grepl("<",  : NAs introduced by coercion
> wc_sample_conc_df %>%
+ mutate(across(where(~ any(str_detect(., fixed("<"))), 
+                    ~ {tmp <- as.numeric(str_remove(., fixed("<")))
+                    case_when(str_detect(., fixed("<"))~ tmp/2, TRUE ~ tmp)))

Error: unexpected ')' in:
"                   ~ {tmp <- as.numeric(str_remove(., fixed("<")))
                   case_when(str_detect(., fixed("<"))~ tmp/2, TRUE ~ tmp))"
library(dplyr)
library(stringr)
wc_sample_conc_df %>%
   mutate(across(where(~ any(str_detect(., fixed("<")))), 
         ~ {tmp <- as.numeric(str_remove(., fixed("<")))
            case_when(str_detect(., fixed("<"))~ tmp/2, TRUE ~ tmp)}))