I am making a summary data frame from multiple data frames. The code I am using works correctly to replace the first row in the new frame but does not work for any other row.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var scoreLabel: UILabel!
var points: Int = 0
func randomPoint() -> CGPoint {
let randomPoint: CGPoint = CGPoint(x:CGFloat(arc4random()%320),y:CGFloat(arc4random()%568))
return randomPoint
}
func randomColor() -> UIColor {
let red = CGFloat(drand48())
let green = CGFloat(drand48())
let blue = CGFloat(drand48())
return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
}
func spawnEnemy() {
let enemy: UIButton = UIButton(frame: CGRect(x: 160, y: 160, width: 150, height: 150))
enemy.backgroundColor = randomColor()
enemy.center = randomPoint()
enemy.addTarget(self, action: Selector("buttonPushed:"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(enemy)
}
func buttonPushed(sender : UIButton) {
sender.backgroundColor = UIColor.blackColor()
points = points + 1
scoreLabel.textAlignment = .Center
scoreLabel.text = "\(points)"
scoreLabel.backgroundColor = UIColor.blackColor()
if sender.frame.height < 50 || sender.frame.width < 50 {
sender.frame = CGRectMake(sender.frame.origin.x, sender.frame.origin.y, 50, 50)
sender.backgroundColor = self.randomColor()
sender.center = self.randomPoint()
return
}
}
override func viewDidLoad() {
super.viewDidLoad()
NSTimer.scheduledTimerWithTimeInterval(0.75, target: self, selector: Selector("spawnEnemy"), userInfo: nil, repeats: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
I can run and print just the sum function the second time I use it and I get the correct value. However, it will not overwrite the value in the corresponding row in the new data frame.
答案 0 :(得分:0)
Your problem is probably that your Dimensions are factors but you expect them to be strings. Try
iptables -A INPUT -m mac --mac-source aa:bb:cc:dd:ee:ff -j DROP
I use stringsAsFactors = FALSE to prevent conversion to factors. I hate stringsAsFactors. First thing I learned from http://adv-r.had.co.nz/Data-structures.html was to use tableCols<-
gsub(
pattern = "^\\s",
replacement = "",
x = strsplit(as.character( tableCols ), ',' )[[1]]
)
Table<-
data.frame(
Dimension = tableCols,
All_users = numeric(24),
Non_bounce = numeric(24),
stringsAsFactors = FALSE
)
on one's variables anytime one finds them misbehaving.
Another thing I notice is that strsplit on commas was converting
str()
to [Sessions], [_Pages/session] ... note the underscore at the front of the second column name is actually a space. I use gsub to strip the leading whitespace.