使用dplyr - 我无法确定返回已过滤行的行索引的最佳方式,而不是返回已过滤行的内容.
我可以使用dplyr :: filter()从数据帧中提取行...问题是想要提取已过滤行的索引值并将其添加到符合搜索条件的索引条目列表中.
是否有一种简单的方法可以使用dplyr根据特定条件搜索数据帧并返回找到的每一行的数字索引?下面的代码使用r :: which()将索引行提取到列表中......
requiredPackages <- c("dplyr")
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
ipak(requiredPackages)
if (!file.exists("./week3/data")) {
dir.create("./week3/data")
}
# CSV Download
if (!file.exists("./week3/data/americancommunitySurvey.csv")) {
fileUrl <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv?accessType=DOWNLOAD"
download.file(fileUrl, destfile = "./week3/data/americancommunitySurvey.csv", method = "curl")
}
housingData <- tbl_df(read.csv("./week3/data/americancommunitySurvey.csv"
, stringsAsFactors = TRUE))
Now we have to extract the relevant data
#
# Create a logical vector …Run Code Online (Sandbox Code Playgroud) 我有一组CSV文件.我想打包它们并将数据导出到包含多个工作表的单个Excel文件.我将CSV文件作为一组数据框读入.
我的问题是如何构造命令openxlsx,我可以手动完成,但我有一个列表构造问题.具体来说,如何将数据框添加为命名列表的子组件,然后作为参数传递给write.xlsx()
好的,我首先在磁盘上列出CSV文件并在内存中生成一组数据帧...
# Generate a list of csv files on disk and shorten names...
filePath <- "../02benchmark/results/results_20170330/"
filePattern <- "*.csv"
fileListwithPath = list.files(path = filePath, pattern = filePattern, full.names = TRUE)
fileList = list.files(path = filePath, pattern = filePattern, full.names = FALSE)
datasets <- gsub("*.csv$", "", fileList)
datasets <- gsub("sample_", "S", datasets)
datasets
# Now generate the dataframes for each csv file...
list2env(
lapply(setNames(fileListwithPath, make.names(datasets)),
read.csv), envir = .GlobalEnv)
Run Code Online (Sandbox Code Playgroud)
示例输出:
dput(datasets)
c("S10000_R3.3.2_201703301839", "S10000_T4.3.0_201703301843",
"S20000_R3.3.2_201703301826", "S20000_T4.3.0_201703301832", …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我添加了一个UISearchBar.
我的目的是使UISearch栏"X按钮"(UITextField中的清除按钮)始终可见.
我尝试使用下面的代码尝试使"X按钮"始终可见.但是,它不起作用.如果我设置tf.clearButtonMode = UITextFieldViewModeNever,uitextfield中的清除按钮不显示.我不确定是什么问题?
我真的很感激任何人的帮助.为什么这不起作用?
for (UIView* v in searchBar.subviews)
{
if ( [v isKindOfClass: [UITextField class]] )
{
UITextField *tf = (UITextField *)v;
tf.delegate = self;
tf.clearButtonMode = UITextFieldViewModeAlways;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
如果文本长度等于0,我想始终显示清除按钮
我找到了实现这一目标的方法,但它需要大量的猜测,并且所有的Venn或Euler图表包似乎只允许您将总出现次数放在圆圈内.
数据:
name=c('itm1','itm2','itm3','itm4','itm5','itm6','itm7','itm8','itm9','itm0')
x=c(5,2,3,5,6,7,7,8,9,2)
y=c(6,9,9,7,6,5,2,3,2,4)
z=data.frame(name,x,y)
Run Code Online (Sandbox Code Playgroud)
plot(z$x,z$y,type='n')
text(z$x,z$y,z$name)
Run Code Online (Sandbox Code Playgroud)
par(new=T)
symbols(3,7,circles=2.5,add=T,bg='#34692499',inches=F)
symbols(6,6,circles=1.5,add=T,bg='#64392499',inches=F)
symbols(8,3,circles=2,add=T,bg='#24399499',inches=F)
Run Code Online (Sandbox Code Playgroud)
因此,这是一个非常繁琐的过程,为每个项目提供x和y坐标,然后猜测放置圆圈的位置以及给出它们的半径.
理想情况下,我想使用我最初的数据集,如下所示:
cat1=c('itm2','itm3','itm0')
cat2=c('itm1','itm4','itm5','itm6')
cat3=c('itm6','itm7','itm8','itm9')
Run Code Online (Sandbox Code Playgroud)
然后将点分配到正确的圆圈中.有没有更好的方法呢?
我试图在阴谋中并排获得两个甜甜圈.但是,我只得到一张图片.关于我缺少的任何建议?
library(dplyr)
library(plotly)
df1 <- as.data.frame(matrix(data = c("a","b", "c", 34,28, 29), nrow = 3, ncol = 2))
colnames(df1) <- c("category", "count")
df2 <- as.data.frame(matrix(data = c("Q","F", "G", 29,50, 76), nrow = 3, ncol = 2))
colnames(df2) <- c("group", "count")
p <- subplot(
plot_ly(df1, labels = category, values = count, type = "pie", hole = 0.6, showlegend = TRUE),
plot_ly(df2, labels = group, values = count, type = "pie", hole = 0.6, showlegend = TRUE),
margin = 0.05,
nrows = 2 …Run Code Online (Sandbox Code Playgroud) 我已将以下头文件添加到我的代码中:
#include <FF.au3>
Run Code Online (Sandbox Code Playgroud)
当我尝试访问此库时,出现此错误:
"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\My_Files\Automation scripts\My tests\AutomaticWebpageLogin -1.au3"
D:\My_Files\Automation scripts\My tests\AutomaticWebpageLogin -1.au3 (1) : ==> Error opening the file.:
#include <FF.au3>
Exit code: 1 Time: 0.411`
Run Code Online (Sandbox Code Playgroud)
那是什么意思?