我绘制了虹膜数据ggplot2.似乎ggplot2将数据自动标准化为(0.1)间隔.如何在没有任何标准化操作的情况下绘制数据?
library(ggplot2)
p <- ggpcp(iris, vars = names(iris[1:4]))
p + geom_line(aes(color = Species)) + ylim(0,8)
Run Code Online (Sandbox Code Playgroud)
我不是母语为英语的人,我很抱歉模棱两可.实际上,虹膜数据从0到8各不相同.我想绘制的数据准确反映实际值,而不是标准化值(将原始数据转换为(0,1)间隔).
我知道如何使用zip+ 比较Scala中的两个列表forall。
我的问题是我们如何比较两种DataFrame模式。也就是说,我们希望将列名与其可为null的属性进行匹配。
我的想法是使用哈希映射存储{列名称:nullable},然后进行比较。我想这可行,但是还有其他惯用的方式吗?
我知道如何从sparkContext. 有没有办法从中获取 jobID / ApplicationID SparkSession?
在sparkContext,我们可以
sc.applicationId
res0: String = app-20150224184813-11531
Run Code Online (Sandbox Code Playgroud) 假设我们有private[feature] trait ImputerParams extends Params.
那么我就有了class Imputer extend ImputerParams。
我的问题是我需要实现所有方法吗Params?根据 Scala 的文档,我应该这样做。然而,当我阅读真正的生产代码时,我发现Imputer并没有实现 中的所有方法Params,并且它运行良好。所以我很困惑。
如果我想了解更多信息,我应该阅读哪些主题?
我在Scala中遇到过这个函数def nullable: Boolean = true.我理解这个函数做了什么,但我想知道这种函数是否有特定的名称,以及不使用的动机是什么var
我是 Scala 的新手,我正在阅读这段代码。
我理解第一个val bucketizers是作为变量的函数,并val newCols称为bucketizers.
但是,我不明白为什么在bucketizers(idx)(filteredDataset(inputCol).cast(DoubleType))函数调用之后有一个括号bucketizers(idx)。我查了一些高级主题,包括闭包、高阶函数和链函数调用,但我认为我没有找到答案。
问题:这个括号叫什么?我们可以用另一种方式重写它吗?
代码:
val bucketizers: Seq[UserDefinedFunction] = seqOfSplits.zipWithIndex.map { case (splits, idx) =>
udf { (feature: Double) =>
Bucketizer.binarySearchForBuckets(splits, feature, keepInvalid)
}.withName(s"bucketizer_$idx")
}
val newCols = inputColumns.zipWithIndex.map { case (inputCol, idx) =>
bucketizers(idx)(filteredDataset(inputCol).cast(DoubleType))
}
Run Code Online (Sandbox Code Playgroud) 我已经阅读了其他相关问题,但我没有得到答案.
码:
inputType.zip(inputColName).zipWithIndex.map {
case (inputType, inputColName, idx) =>
inputType match {
case **DoubleType** => println("test1")
case _ => println('test2 ')
}
}
Run Code Online (Sandbox Code Playgroud)
DoubleType模式类型与预期类型不兼容.找到DoubleType.type.必需:(DataType,String).
我尝试了两个简化版本,语法看起来正确.
List(1,2,3).zip(List(4,5,6)).map { case(a, b) =>
a match {case 1 => println(s"First is $a, second is $b")
case _ => println("test")}}
Run Code Online (Sandbox Code Playgroud)
以下也有效
inputType.zipWithIndex.map {
case (inputType, idx) =>
inputType match {
case DoubleType => println("test1")
case _ => println('test2 ')
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么zip添加后,为什么我有这种模式匹配类型错误.
我遇到了这个问题:
给定包含user_id,时间戳和收入的收入交易表,您如何找到每个用户的第三次购买?
我知道如何使用窗口函数来解决它,但我不知道如何在没有窗口函数的情况下解决它.例如,相关子查询.
如果我们想要n购买,您的方法是否有效?
我知道Try/Success/Failure与Try Catch之间存在差异.官方文件也有一个很好的例子:
import scala.io.StdIn
import scala.util.{Try, Success, Failure}
def divide: Try[Int] = {
val dividend = Try(StdIn.readLine("Enter an Int that you'd like to divide:\n").toInt)
val divisor = Try(StdIn.readLine("Enter an Int that you'd like to divide by:\n").toInt)
val problem = dividend.flatMap(x => divisor.map(y => x/y))
problem match {
case Success(v) =>
println("Result of " + dividend.get + "/"+ divisor.get +" is: " + v)
Success(v)
case Failure(e) =>
println("You must've divided by zero or entered something that's not an Int. Try …Run Code Online (Sandbox Code Playgroud) 我正在尝试暂停和恢复 groutine。我知道我可以sleep跑步,但我正在寻找就像一个按钮“暂停/恢复”而不是一个计时器。
这是我的尝试。我正在使用通道的阻塞功能来暂停,并select根据通道值切换要执行的内容。但是,输出总是Running在我的情况下。
func main() {
ctx := wctx{}
go func(ctx wctx) {
for {
time.Sleep(1 * time.Second)
select {
case <-ctx.pause:
fmt.Print("Paused")
<-ctx.pause
case <-ctx.resume:
fmt.Print("Resumed")
default:
fmt.Print("Running \n")
}
}
}(ctx)
ctx.pause <- struct{}{}
ctx.resume <- struct{}{}
}
type wctx struct {
pause chan struct{}
resume chan struct{}
}
Run Code Online (Sandbox Code Playgroud) scala ×6
apache-spark ×3
channel ×1
concurrency ×1
exception ×1
ggplot2 ×1
go ×1
goroutine ×1
inheritance ×1
mysql ×1
oop ×1
plot ×1
r ×1
sql ×1
traits ×1