我在Windows 7中使用Rsutdio和knitr来渲染简单的gvisTable时遇到了麻烦.这是我的代码
```{r results='asis'}
require(googleVis)
op <- options(gvis.plot.tag="chart")
data(iris)
t = gvisTable(data = iris)
print(t)
```
Run Code Online (Sandbox Code Playgroud)
这是我的错误:
pandoc.exe:无法检索https://www.google.com/jsapi?callback=displayChartTableID14c4345d7f3 FailedConnectionException2"www.google.com"443真正连接:失败(连接超时(WSAETIMEDOUT))Erreur:pandoc文档转换失败,错误61
我的Rstudio版本是:0.98.1091我的SessionInfo是:
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plotrix_3.5-10 data.table_1.9.4 googleVis_0.5.6 knitr_1.8
loaded via a namespace (and not attached):
[1] chron_2.3-45 digest_0.6.4 evaluate_0.5.5 formatR_1.0 htmltools_0.2.6 plyr_1.8.1 Rcpp_0.11.3
[8] reshape2_1.4 RJSONIO_1.3-0 rmarkdown_0.3.11 stringr_0.6.2 tools_3.1.2 yaml_2.1.13Run Code Online (Sandbox Code Playgroud)
或者此代码完全正常:
```{r results='asis'} …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的数据框
df = spark.createDataFrame([(None,1,3),(2,1,3),(2,1,3)], ['a','b','c'])
+----+---+---+
| a| b| c|
+----+---+---+
|null| 1| 3|
| 2| 1| 3|
| 2| 1| 3|
+----+---+---+
Run Code Online (Sandbox Code Playgroud)
当我应用countDistinct这个数据帧,我觉得取决于方法不同的结果:
df.distinct().count()
Run Code Online (Sandbox Code Playgroud)
2
这是我的结果,除了最后两行是相同的,但第一行与其他两行是不同的(由于空值)
import pyspark.sql.functions as F
df.agg(F.countDistinct("a","b","c")).show()
Run Code Online (Sandbox Code Playgroud)
1个
对我而言,F.countDistinct处理null价值的方式似乎并不直观。
对您来说,它看起来是错误还是正常?如果是正常的话,我该如何写出与第一种方法完全相同但又能输出第一种方法的结果的东西。
我想根据 2 个布尔条件通过按位 AND 运算来改变我的数据帧
df %>% mutate(newVariable = ifelse(variable1 == "value1" & variable2 == "value2, variable3, NULL)
Run Code Online (Sandbox Code Playgroud)
所以在 PySpark 中测试了这个:
import pyspark.sql.functions as func
df.withColumn("newVariable", func.when( \
func.col("variable1") == "value1" & func.col("variable2") == "value2", \
func.col("variable3")))
Run Code Online (Sandbox Code Playgroud)
但我有一个错误
使用 Spark DataFrame 创建这种新变量的正确方法是什么?