有没有办法在不导入文件的情况下获取文件中的行数?
到目前为止,这就是我正在做的事情
myfiles <- list.files(pattern="*.dat")
myfilesContent <- lapply(myfiles, read.delim, header=F, quote="\"")
for (i in 1:length(myfiles)){
  test[[i]] <- length(myfilesContent[[i]]$V1)
}
Run Code Online (Sandbox Code Playgroud)
但由于每个文件都很大,所以太耗费时间.
我试图从包含每个字符中至少一个的固定数量的字符生成随机序列.
例如有合奏
m = letters[1:3] 
我想创建一个N = 10个元素的序列,其中至少包含每个m字符中的一个,如
a
a
a
a
b
c
c
c
c
a
Run Code Online (Sandbox Code Playgroud)
我试过sample(n,N,replace=T)但是这样也是一个序列
a
a
a
a
a
c
c
c
c
a
Run Code Online (Sandbox Code Playgroud)
可以生成不包含的内容b.
我正在使用以下地理附加模型
library(gamair)
library(mgcv)
data(mack)    
mack$log.net.area <- log(mack$net.area)
gm2 <- gam(egg.count ~ s(lon,lat,bs="gp",k=100,m=c(2,10,1)) +
                       s(I(b.depth^.5)) +
                       s(c.dist) +
                       s(temp.20m) +
                       offset(log.net.area),
                       data = mack, family = tw, method = "REML")
Run Code Online (Sandbox Code Playgroud)
如何使用它来预测没有协变量数据的egg.count新位置的值,如?(lon/lat)kriging
例如,假设我想egg.count在这些新位置进行预测
    lon lat
1  -3.00  44
4  -2.75  44
7  -2.50  44
10 -2.25  44
13 -2.00  44
16 -1.75  44
Run Code Online (Sandbox Code Playgroud)
b.depth但这里我不知道协变量( , c.dist, temp.20m, )的值log.net.area。
我有两个变量A,B我想写一个代码,如果两个变量之一相等
151 or 156 or 720
Run Code Online (Sandbox Code Playgroud)
而另一个不等于这些数字之一,则第三个变量C = 0等于1.
所以举个例子
1) if A = 151 and B = 700 then C = 1 
2) if A = 151 and B = 720 then C = 0
3) if A = 140 and B = 700 then C = 0
Run Code Online (Sandbox Code Playgroud)
这是代码
int A = 0
cin >> A;
int B = 0
cin >> B;
int C=0;
int DECKlist[3] = {151,156,720}
for(int d=0; d<3;d++){
      if(A== …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的 3d 数组
datamonth <- array(0, dim = c(length(LONG),length(LATG),length(YEAR)))
>dim(datamonth)
[1] 361 181  30
Run Code Online (Sandbox Code Playgroud)
其中前两个维度是经度和纬度(我有一个 1 度间隔的网格)。我想做的是计算每个网格点的数据月平均值,例如
Cell 1 
LON -180 -179
LAT  -90 -89
year 1: MeanCell1_yr
year 2: MeanCell1_yr    .
.
.
year 30: MeanCell1_yr
MeanCell1TOT = mean(MeanCell1_yr)
Run Code Online (Sandbox Code Playgroud)
非常感谢
我有这种类型的数据框
YEAR   MONTH  DAY  HOUR       LON      LAT
1860     10      3   13      -19.50   3.00          
1860     10      3   17      -19.50   4.00                          
1860     10      3   21      -19.50   5.00                          
1860     10      5   5       -20.50   6.00                          
1860     10      5   13      -21.50   7.00                          
1860     10      5   17      -21.50   8.00                          
1860     10      6   1       -22.50   9.00                          
1860     10      6   5       -22.50   10.00                         
1860     12      5   9       -22.50   -7.00                         
1860     12      5   18      -23.50   -8.00                         
1860     12      5   22      -23.50   -9.00                         
1860     12      6   6       -24.50   -10.00                                    
1860 …Run Code Online (Sandbox Code Playgroud) 我有这样的数据框
   x           y          z
10             10         0      
00021          21         11    
022            22         1                                         
13610206     13610206     1     
13610207     13610207     1     
13610208     13610208     1     
13610209     13610209     1     
13610210     13610210     1 
Run Code Online (Sandbox Code Playgroud)
其中第二列是y = as.numeric(as.character(x)),第三列是z = diff(y).我想做的是添加这样的列
   x           y          z               xnew
10             10         0                10
00021          21         11               00021 
022            22         1                00021                                  
13610206     13610206     13610184         13610206
13610207     13610207     1                13610206
13610208     13610208     1                13610206
13610209     13610209     1                13610206
13610210     13610210     1                13610206
Run Code Online (Sandbox Code Playgroud)
即,如果z = 1,则xnew等于z与1不同的先前x.