[英]how can I create a new data frame using exact rows from the old data frame in R Studio?
I need to select the exact rows from the old data frame and create a new one.我需要 select 旧数据框中的确切行并创建一个新的。 I need to choose rows which contain paired numbers (as 11, 22, 33, 44, 55, 66, 77, 88 and 99).我需要选择包含成对数字的行(如 11、22、33、44、55、66、77、88 和 99)。 How can I do this?我怎样才能做到这一点?
I tried using filter:我尝试使用过滤器:
paired1 <- filter(paired1$Var1=='22')
# Error in UseMethod("filter") :
# no applicable method for 'filter' applied to an object of class "logical"
And with:与:
> with (paired1, sum (Freq[Var1 == '11' & '22']))
# Error in Var1 == "11" & "22" :
# operations are possible only for numeric, logical or complex types
For two digit numbers:对于两位数:
paired1[paired1$var1 %in% seq(11, 99, 11),]
We may use我们可能会使用
subset(paired1, !nchar(sub("(\\d)\\1+", "", var1)))
-output -输出
var1
4 99
5 11
7 44
8 777
9 555
paired1 <- data.frame(var1 = c(12, 13, 25, 99, 11, 42, 44, 777, 555, 3))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.