当我尝试获取唯一值时,以下是我得到的结果。
unique( big1.csv[grepl("c1", tolower(big1.csv$Remarks)) &grepl("arm", tolower(big1.csv$Remarks))
&grepl("back", tolower(big1.csv$Remarks))
, ]$New_Remarks)
[1] "c1 noted to back and arms, dose repeated" "c1 noted to back of arms and flanks, dose repeated"
[3] "c1 noted to arms and back, dose repeated" "c1 noted to back and upper arms, dose repeated"
[5] "c1 noted to back of arms, dose repeated" "c1 noted to back and chest, dose repeated"
如何将每个结果分成一行,而不是像这样的行号?还是罗马数字?
[a] "c1 noted to back and arms, dose repeated"
[b] "c1 noted to back of arms and flanks, dose repeated"
[c] "c1 noted to arms and back, dose repeated"
[d] "c1 noted to back and upper arms, dose repeated"
[e] "c1 noted to back of arms, dose repeated"
[f] "c1 noted to back and chest, dose repeated"
答案 0 :(得分:2)
我认为您需要rownames,请参阅此示例:
unique.strings <- c("xxx", "yyy", "zzz")
df <- data.frame(unique.strings)
rownames(df) <- make.unique(letters[1:nrow(df)])
df
# unique.strings
# a xxx
# b yyy
# c zzz
答案 1 :(得分:1)
您可以将unique.strings
与自定义ID
合并到一个数据框中。
unique.strings <- unique( big1.csv[grepl("e1", tolower(big1.csv$Remarks)) &grepl("arm", tolower(big1.csv$Remarks))
&grepl("back", tolower(big1.csv$Remarks))
, ]$New_Remarks)
df <- data.frame(ID = paste0("[", letters[1:length(unique.strings)], "]"), unique.strings)