这个问题可能与此问题有关。
不幸的是,那里给出的解决方案不适用于我的数据。
我有以下矢量示例:
example<-c("ChildrenChildren", "Clothing and shoesClothing and shoes","Education, health and beautyEducation, health and beauty", "Leisure activities, travelingLeisure activities, traveling","LoansLoans","Loans and financial servicesLoans and financial services" ,"Personal transfersPersonal transfers" ,"Savings and investmentsSavings and investments","TransportationTransportation","Utility servicesUtility services")
Run Code Online (Sandbox Code Playgroud)
我当然希望没有重复的相同字符串,即:
> result
[1] "Children" "Clothing and shoes" "Education, health and beauty"
Run Code Online (Sandbox Code Playgroud)
那可能吗?
也许是一个简单的问题,如何生成矢量的组合.我有下一个矢量.
> x<-1:5
> x
[1] 1 2 3 4 5
Run Code Online (Sandbox Code Playgroud)
所以,我要的是所有这些的组合,但该序列不能包含在组合相同数量和ab==ba,abc==bca==cab即:
permut<-c(1:5,12,13,14,15,23,24,25,34,...,123,124,125,134,135,...,1234,1235,...)
permut
[1] 1 2 3 4 5 12 13 14 15 23 24 25 34 ... 123 124 125 134 135 ... 1234 1235
Run Code Online (Sandbox Code Playgroud)
我认为这个功能expand.grid()很有用,但我不知道它是如何使用的.
我不是使用lapply,apply等的专家.所以,我所拥有的是下一个列表
my_list
[[1]]
[1] "40.394081 -3.7083041"
[[2]]
[1] "40.3960251 -3.7116921"
[[3]]
[1] "40.3938449 -3.7071731"
[[4]]
[1] "40.3935099 -3.7121505"
Run Code Online (Sandbox Code Playgroud)
我想在as.numeric每个入口处使用该功能my_list.我的意思是,将列表的每个入口转换为数字,但保留列表的结构.
谢谢.
我有一个看起来像的矢量
> inecodes
[1] "01001" "01002" "01049" "01003" "01006" "01037" "01008" "01004" "01009" "01010" "01011"
[12] "01013" "01014" "01016" "01017" "01021" "01022" "01023" "01046" "01056" "01901" "01027"
[23] "01019" "01020" "01028" "01030" "01031" "01032" "01902" "01033" "01036" "01058" "01034"
[34] "01039" "01041" "01042" "01043" "01044" "01047" "01051" "01052" "01053" "01054" "01055"
Run Code Online (Sandbox Code Playgroud)
我想从这个向量中删除这些"数字":
>pob
[1] "01001-Alegría-Dulantzi" "01002-Amurrio"
[3] "01049-Añana" "01003-Aramaio"
[5] "01006-Armiñón" "01037-Arraia-Maeztu"
[7] "01008-Arratzua-Ubarrundia" "01004-Artziniega"
[9] "01009-Asparrena" "01010-Ayala/Aiara"
[11] "01011-Baños de Ebro/Mañueta" "01013-Barrundia"
[13] "01014-Berantevilla" "01016-Bernedo"
[15] "01017-Campezo/Kanpezu" "01021-Elburgo/Burgelu"
[17] …Run Code Online (Sandbox Code Playgroud) 我有以下数据样本
X <- c("11/12/2016", "12/12/2016", "13/12/2016","14/12/2016","15/12/2016","16/12/2016", "17/12/2016")
Y <- c("11/12/2016", "13/12/2016", "14/12/2016", "18/12/2016")
Run Code Online (Sandbox Code Playgroud)
我想要的输出是这样的
X Y
11/12/2016 11/12/2016
12/12/2016 NA
13/12/2016 13/12/2016
14/12/2016 14/12/2016
15/12/2016 NA
16/12/2016 NA
17/12/2016 NA
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码,但没有得到所需的输出
> X <- as.Date(data$X)
> Y <- as.Date(data$Y)
> Z <- NA
> for (i in 1:length(X)) {
+ if(X[i] == Y){
+ Z <- Y}
+ else NA }
Run Code Online (Sandbox Code Playgroud)