我想分解字符串作爲列使用stringr包。字符向量列表的混合數據幀到統一的數據幀
> df <- dput(head(facs,3))
structure(list(geo_accession = structure(1:3, .Names = c("V2",
"V3", "V4"), .Label = c("GSM1494875", "GSM1494877", "GSM1494879",
"GSM1494881", "GSM1494883", "GSM1494885", "GSM1494887", "GSM1494889",
"GSM1494891", "GSM1494893", "GSM1494895", "GSM1494897", "GSM1494899",
"GSM1494901", "GSM1494903", "GSM1494906", "GSM1494908", "GSM1494910",
"GSM1494912", "GSM1494914", "GSM1494917", "GSM1494919", "GSM1494921",
"GSM1494923"), class = "factor"), title = structure(1:3, .Names = c("V2",
"V3", "V4"), .Label = c("2818 - Akt treated TIL - repeat 1 - mAdbID:125971",
"2818 - Akt treated TIL - repeat 2 - mAdbID:125972", "2818 - Akt treated TIL - repeat 3 - mAdbID:125973",
"2818 - Akt treated TIL - repeat 4 - mAdbID:125974", "2818 - Untreated TIL - repeat 1 - mAdbID:125975",
"2818 - Untreated TIL - repeat 2 - mAdbID:125976", "2818 - Untreated TIL - repeat 3 - mAdbID:125977",
"2818 - Untreated TIL - repeat 4 - mAdbID:125978", "3289 - Akt treated TIL - repeat 1 - mAdbID:125979",
"3289 - Akt treated TIL - repeat 2 - mAdbID:125980", "3289 - Akt treated TIL - repeat 3 - mAdbID:125981",
"3289 - Akt treated TIL - repeat 4 - mAdbID:125982", "3289 - Untreated TIL - repeat 1 - mAdbID:125983",
"3289 - Untreated TIL - repeat 2 - mAdbID:125984", "3289 - Untreated TIL - repeat 3 - mAdbID:125985",
"3289 - Untreated TIL - repeat 4 - mAdbID:125986", "3784 - Akt treated TIL - repeat 1 - mAdbID:125987",
"3784 - Akt treated TIL - repeat 2 - mAdbID:125988", "3784 - Akt treated TIL - repeat 3 - mAdbID:125989",
"3784 - Akt treated TIL - repeat 4 - mAdbID:125990", "3784 - Untreated TIL - repeat 1 - mAdbID:125991",
"3784 - Untreated TIL - repeat 2 - mAdbID:125992", "3784 - Untreated TIL - repeat 3 - mAdbID:125993",
"3784 - Untreated TIL - repeat 4 - mAdbID:125994"), class = "factor")), .Names = c("geo_accession",
"title"), row.names = c("GSM1494875", "GSM1494877", "GSM1494879"
), class = "data.frame")
現在它是一個2列數據框。
> sapply(df, class)
geo_accession title
"factor" "factor"
如果我使用str_split_fixed
,
> df$title = str_split_fixed(df[,"title"], " - ", 4)
> df
geo_accession title.1 title.2 title.3 title.4
GSM1494875 GSM1494875 2818 Akt treated TIL repeat 1 mAdbID:125971
GSM1494877 GSM1494877 2818 Akt treated TIL repeat 2 mAdbID:125972
> sapply(df, class)
geo_accession title
"factor" "matrix"
我想看到的是一個5列數據幀,而不是2列混合數據幀(因子,矩陣)。
> df
geo_accession title1 title2 title3 title4
GSM1494875 GSM1494875 2818 Akt treated TIL repeat 1 mAdbID:125971
GSM1494877 GSM1494877 2818 Akt treated TIL repeat 2 mAdbID:125972
> sapply(df, class)
geo_accession title.1 title.2 title.3 title.4
"factor" "factor" "factor" "factor" "factor"
我不知道如何清理混合數據幀。我如何將其轉換爲5列數據框?
見'tidyr :: separate' –
請提供可重複的例子 –
請使用'dput'可重複的共享數據按照R標籤描述的方式 –