这是一个看似简单的问题,我无法找到答案。
我有一个数据框
df <- data.frame(respondent = factor(c(1, 2, 3, 4, 5, 6)), language = factor(c("English", "English", "French", "French, German", "German", "German")))
因子级别名称反映了调查回复。大多数受访者都是单语,但有些人会说法语和德语。我想分开&#34;法语,德语&#34;等级为两个。
如何做到这一点?
答案 0 :(得分:2)
我们可以使用let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: "your-shared-secret")
SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
switch result {
case .success(let receipt):
let productId = "com.musevisions.SwiftyStoreKit.Subscription"
// Verify the purchase of a Subscription
let purchaseResult = SwiftyStoreKit.verifySubscription(
ofType: .autoRenewable, // or .nonRenewing (see below)
productId: productId,
inReceipt: receipt)
switch purchaseResult {
case .purchased(let expiryDate, let items):
print("\(productId) is valid until \(expiryDate)\n\(items)\n")
case .expired(let expiryDate, let items):
print("\(productId) is expired since \(expiryDate)\n\(items)\n")
case .notPurchased:
print("The user has never purchased \(productId)")
}
case .error(let error):
print("Receipt verification failed: \(error)")
}
}
中的separate_rows
,然后使用tidyr
将mutate
转换回language
。生成的factor
列将是每个单独语言的级别因素:
language
<强>结果:强>
library(dplyr)
library(tidyr)
df = df %>%
separate_rows(language) %>%
mutate(language = factor(language))