我有一列温度范围(如果只记录了一个读数,则为单一温度),如下所示:
"117-118"
"117-118"
"117-122"
"122-128"
"123"
"118-124"
"118-124"
"118-124"
"123-128"
"91-101"
...
在R中,如何将该色谱柱分成两列(即低温和高温色谱柱)?
答案 0 :(得分:1)
newData <- read.table(text = input, sep = "-", fill = TRUE)
将read.table与自定义分隔符一起使用:
means <- rowMeans(newData, na.rm = TRUE)
请注意空格将填入NA。如果你想要平均值,你可以这样做:
strsplit
您还可以在评论中提及sapply
和newData <- t(sapply(strsplit(input, "-"), function(x) as.numeric(c(x, x)[1:2])))
# If you want NAs as before, change from c(x, x) to c(x, NA)
,如下所示:
GIDSignIn* signIn = [GIDSignIn sharedInstance];
// Xcode error: Property 'fetchEmailToggle' not found on object type 'LoginViewController', did you mean to access instance variable 'fetchEmailToggle'?
if (self.fetchEmailToggle.isEnabled) {
signIn.shouldFetchBasicProfile = YES;
}
[signIn setClientID: kClientId];
[signIn setScopes:[NSArray arrayWithObject:@"https://www.googleapis.com/auth/plus.login"]];
[signIn setDelegate: self];
// Xcode error: Property 'statusField' not found on object type 'LoginViewController'
self.statusField.text = @"Initialized auth2...";
答案 1 :(得分:1)
感谢@akrun和其他人提供的一些有用的提示,我找到了一种方法来完成这项工作:
temp <- c("117-118", "117-118", "117-122", "122-128" ,"123", "118-124", "118-124", "118-124", "123-128", "91-101")
low <- as.numeric(lapply(strsplit(temp,"-"), function(x) x[1]))
high <- as.numeric(lapply(strsplit(temp,"-"), function(x) x[2]))
结果如下:
> low
[1] 117 117 117 122 123 118 118 118 123 91
> high
[1] 118 118 122 128 NA 124 124 124 128 101
在单值的情况下,将该值分配给两个列表可以按如下方式进行(可能不是最好的方法,但它有效):
high[is.na(high)] <- low[is.na(high)]
导致这个结果:
> high
[1] 118 118 122 128 123 124 124 124 128 101