我有一个list()数据帧.我想申请dplyr的filter()于所有的人.
到目前为止我尝试过的示例代码...
require(dplyr)
list.DFs <- list(df1,df2)
lapply(
X = list.DFS,
FUN = filter(Gold.fish.count=="Total")
)
Run Code Online (Sandbox Code Playgroud)
但是这给出了一个错误:Object 'Gold.fish.count' not found.
我正在 ggplot2 中制作图表,但ggsave()没有达到我的预期。
require(ggplot2)
require(showtext)
showtext_auto()
hedFont <- "Pragati Narrow"
font_add_google(
name = hedFont,
family = hedFont,
regular.wt = 400,
bold.wt = 700
)
chart <- ggplot(
data = cars,
aes(
x = speed,
y = dist
)
) +
geom_point() +
labs(
title = "Here is a title",
subtitle = "Subtitle here"
) +
theme(
plot.title = element_text(
size = 20,
family = hedFont,
face = "bold"
),
axis.title = element_text(
face = "bold"
)
)
ggsave( …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作甜甜圈图表.
唯一的问题是它们看起来像这样......
这是我的代码
ggplot(
diamonds,
aes(
x = cut,
fill = color
)
) +
geom_bar(
position = 'fill',
stat = 'bin'
) +
scale_y_continuous(
labels = percent_format()
) +
facet_grid(clarity ~ cut) +
coord_polar(theta = 'y')
Run Code Online (Sandbox Code Playgroud)
如何将我的图表从奇怪的馅饼变成宽度相同的圆圈?
这是我的Plunker:https://plnkr.co/edit/rBGQyOpi9lS0QtnCUq4L
我想要console.log()在每个textarea标签中输入的内容.键入一个textarea触发printStuff()函数:
$scope.printStuff= function(customize,item){
console.log(customize[item.index].data);
};
Run Code Online (Sandbox Code Playgroud)
当我开始输入任何内容时textarea,我收到此错误:
angular.js:14290 TypeError: Cannot read property 'data' of undefined
at b.$scope.printStuff (index.html:31)
at fn (eval at compile (angular.js:15118), <anonymous>:4:299)
at b.$eval (angular.js:17922)
at angular.js:25653
at Object.<anonymous> (angular.js:28429)
at q (angular.js:325)
at Object.$$writeModelToScope (angular.js:28427)
at angular.js:28420
at g (angular.js:28339)
at f (angular.js:28322)
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
更新了MannFromReno的答案
我仍然得到错误.这是我的Plunker:https://plnkr.co/edit/WwC3kNiTQzaQfjp40h2a
这是我的代码:
int main() {
static int test = 0;
const int anotherInt = 1;
test = anotherInt > test ? test++ : 0;
if (anotherInt > test)
test++;
else
test = 0;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我构建它时产生的警告:
int main() {
static int test = 0;
const int anotherInt = 1;
test = anotherInt > test ? test++ : 0;
if (anotherInt > test)
test++;
else
test = 0;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么 C++ 给我一个关于三元运算的警告,而不是正则if..else语句?
我有两个桌子。
表a看起来像这样-第一行是列名,都包含字符:
id | tractce | someString
1 | "0011900" | "Label here"
Run Code Online (Sandbox Code Playgroud)
表b:
id | tractFIPS
1 | "0011900"
Run Code Online (Sandbox Code Playgroud)
如何转换a.tractce为外键列引用b.id?
因此,它是:
id | tractce | someString
1 | 1 | "Label here"
Run Code Online (Sandbox Code Playgroud) 这是我的以逗号分隔形式的 Google 表格:
ROW, TITLE
1, "Green eggs and ham"
2, "War and peace"
3, "Good Burger: The Movie: The Book"
Run Code Online (Sandbox Code Playgroud)
我必须在浏览器中输入什么 URL 才能以 JSON 或 XML 格式获取这些数据?
我有一个名为的数据框df:
City,State,Price,Dogs
Portland,OR,75,1
Portland,OR,100,3
San Diego,CA,12,4
San Diego,CA,23,5
...
Run Code Online (Sandbox Code Playgroud)
我使用dplyr的summarise和group_by功能......
df.median <- summarise(
group_by(
df,
State,
City
),
MEDIAN_PRICE = median(Price),
SUM_DOGS = sum(Dogs)
)
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时top_n(df.median, 100, SUM_DOGS),R并没有给我带有100个最高值的城市SUM_DOGS.它只是回来了df.median.
为什么?
我有一个数据框df,看起来像这样...
"ID","ReleaseYear","CriticPlayerPrefer","n","CountCriticScores","CountUserScores"
"1",1994,"Both",1,5,283
"2",1994,"Critics",0,0,0
"3",1994,"Players",0,0,0
"4",1995,"Both",3,17,506
"5",1995,"Critics",0,0,0
"6",1995,"Players",0,0,0
"7",1996,"Both",18,163,3536
"8",1996,"Critics",2,18,97
"9",1996,"Players",3,20,79
Run Code Online (Sandbox Code Playgroud)
我想翻转数据框,使列如下所示:
"ReleaseYear","Both","Critics","Players"
每个栏位Both',Critics andPlayers would be then` 的值。
当我尝试运行此...
require(dcast)
chartData.CriticPlayerPreferByYear <- dcast(
data = df,
formula = ReleaseYear ~ CriticPlayerPrefer,
fill = 0,
value.var = n
)
Run Code Online (Sandbox Code Playgroud)
...我得到这个错误:
Error in match(x, table, nomatch = 0L) :
'match' requires vector arguments
Run Code Online (Sandbox Code Playgroud)
这里有什么问题?我如何解决它?
我有一个数据集列表。
dfList <- list(df1,df2,df3)
Run Code Online (Sandbox Code Playgroud)
每个数据集看起来像这样。
apples, oranges
1, 2
NA, 4
Run Code Online (Sandbox Code Playgroud)
我想以编程方式将每个数据帧的NAs更改为0s。我该怎么做呢?
到目前为止我的代码...
lapply(
X = dfList,
FUN = cbind,
is.na = FALSE
)
Run Code Online (Sandbox Code Playgroud)