我想说这是一个绝对的编程初学者,所以请原谅这个问题是多么基本.
我试图更好地理解R中的"原子"类,也许这适用于编程中的类.我理解字符,逻辑和复杂数据类之间的区别,但我很难找到数字类和整数类之间的根本区别.
假设我有一个简单x <- c(4, 5, 6, 6)的整数向量,这对于整数类是有意义的.但是,当我这样做class(x),我得到[1] "numeric".然后,如果我将此向量转换为整数类x <- as.integer(x).除了类不同之外,它返回相同的精确数字列表.
我的问题是为什么会出现这种情况,以及为什么一组整数的默认类是一个数字类,以及将整数设置为数字而不是整数的优点和缺点是什么.
我在尝试使用Nokogiri运行rake任务时遇到此错误.
这是代码.
namespace :tops do
desc "Get Tops Description"
task get_description: :environment do
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open("http://ceratoboutique.com/collections/tops"))
price = Array.new
items = Array.new
brands = Array.new
sale_price = Array.new
image = Array.new
item_url = Array.new
price = doc.xpath("//del").collect {|node| node.text.strip}
items = doc.xpath("//div/a/h4").collect {|node| node.text.strip}
brands = doc.xpath("//span[contains(@class,'vendor')]").collect {|node| node.text.strip}
sale_price = doc.xpath("//span[contains(@class, 'price')]/text()").collect {|node| node.text.strip}
image = doc.xpath("/div/a/img/@src").collect {|node| node.text.strip}
item_url = doc.css('div.details a').map { |link| link['href'] }.collect
price.each do |prices|
Tops.create(description: price)
end
end
end …Run Code Online (Sandbox Code Playgroud) 我有一系列的价值观
=> [0.0, 4.76, 0.0, Infinity, NaN, 2.63, 0.74, 10.0, NaN, NaN, NaN, NaN, 0.0, NaN, NaN, NaN, NaN, NaN, Infinity, 5.26, NaN, 0.0, NaN, 3.45, 2.5, NaN, 10.0, 0.0, NaN, 2.94, NaN, NaN, 0.0, 2.04, 0.0, 11.11, NaN, NaN, 1.23, NaN, NaN, 11.11, NaN, NaN, NaN, 0.0, 9.68, NaN, NaN, 10.0, 5.0, 3.7, 10.0, Infinity, 0.0, 0.0, 1.41, NaN, 3.45, NaN]
Run Code Online (Sandbox Code Playgroud)
当我运行这个脚本来删除NaN时,它删除了一些但不是所有的NaN.
def remove_from_array(numArray)
numArray.inject(0) do |i|
if numArray[i].nan?
numArray.delete_at(i)
end
i += 1
end
numArray
end
Run Code Online (Sandbox Code Playgroud)
我错过了什么?