Saturday, August 30, 2014
New Era of Self-Discipline
New Era of Self-Discipline starts now!
Monday, August 18, 2014
Persistence
Persistence is the common trait of anyone who has had a significant impact on the world.
坚持是世界上成功人士共有的品质。
如果在被银行拒绝了242次之后,霍华德-舒尔茨放弃了,就不会有星巴克;如果在被出版社拒绝了数年之后,J.K.罗琳放弃了,就不会有《哈利波特》;如果他的主题公园被否定了302次之后,华特·迪士尼放弃了,就不会有迪士尼乐园……嗯,像傻逼一样坚持,才会有牛逼的结果。
坚持是世界上成功人士共有的品质。
如果在被银行拒绝了242次之后,霍华德-舒尔茨放弃了,就不会有星巴克;如果在被出版社拒绝了数年之后,J.K.罗琳放弃了,就不会有《哈利波特》;如果他的主题公园被否定了302次之后,华特·迪士尼放弃了,就不会有迪士尼乐园……嗯,像傻逼一样坚持,才会有牛逼的结果。
Wednesday, August 13, 2014
Tuesday, August 12, 2014
B1/B2签证有效期和在美停留时间的问题
一、关于签证有效期
首先我们要知道当我们历经困难从签证官手里拿到自己的签证的时候,签证上面有个时间
这个我们叫做签证有效期。
B1/B2一般是一年多次往返的,这个只跟你申请的签证类型有关,与你填表的时候写的预计赴美时间和在美停留时间实际上关系不大!
当B1/B2签证被美国外交部批准,一般来说会是一年多次往返(visa上会注明multiple)。这个一年是指从签证获准之日起后的365天,都是签证有效期。
在这个有效期内,你有权选择任何日子来美,也可以放弃这项权利。
多次往返理论上讲可以是今天飞来美国,明天飞回中国,第三天又飞来美国,... ..., 直到签证过期。
二、关于在美停留时间或者又叫有效居留期,停留时间
当我们历尽千辛飞到美国的第一站后,首先要同美国国土安全部(不同于之前的美国外交部,他们工作独立,无权互相干涉)的官员会面,由他们来决定父母在美国的居留时间,也就是通常所说的过海关。这之后才是正真意义上的踏上了美国国土。
对于B1/B2签证,停留期最长不超过183天。绝大多数情况下(人权上和道义上),会给到这个上限,即使是父母在同一个签证有效期内多次来美国。另外这个居留到期日理论上可以比签证到期日还晚。
例如父母在签证到期日前一天到达美国,也可以获得183天的居留权。
美国国土安全部的官员会将I-94出入境记录卡附在父母的护照上,离境时必须归还此卡。
总结,在签证有效期内,想什么时候来美国就什么时候来,想来几回就来几回,如同走大路。而居留时间长短则由不得你,从0天(遣返)到183天不等,天知道,如果你对美国国土安全或美国国家利益构成威胁,往少了数数,否则,往大了数。
首先我们要知道当我们历经困难从签证官手里拿到自己的签证的时候,签证上面有个时间
这个我们叫做签证有效期。
B1/B2一般是一年多次往返的,这个只跟你申请的签证类型有关,与你填表的时候写的预计赴美时间和在美停留时间实际上关系不大!
当B1/B2签证被美国外交部批准,一般来说会是一年多次往返(visa上会注明multiple)。这个一年是指从签证获准之日起后的365天,都是签证有效期。
在这个有效期内,你有权选择任何日子来美,也可以放弃这项权利。
多次往返理论上讲可以是今天飞来美国,明天飞回中国,第三天又飞来美国,... ..., 直到签证过期。
二、关于在美停留时间或者又叫有效居留期,停留时间
当我们历尽千辛飞到美国的第一站后,首先要同美国国土安全部(不同于之前的美国外交部,他们工作独立,无权互相干涉)的官员会面,由他们来决定父母在美国的居留时间,也就是通常所说的过海关。这之后才是正真意义上的踏上了美国国土。
对于B1/B2签证,停留期最长不超过183天。绝大多数情况下(人权上和道义上),会给到这个上限,即使是父母在同一个签证有效期内多次来美国。另外这个居留到期日理论上可以比签证到期日还晚。
例如父母在签证到期日前一天到达美国,也可以获得183天的居留权。
美国国土安全部的官员会将I-94出入境记录卡附在父母的护照上,离境时必须归还此卡。
总结,在签证有效期内,想什么时候来美国就什么时候来,想来几回就来几回,如同走大路。而居留时间长短则由不得你,从0天(遣返)到183天不等,天知道,如果你对美国国土安全或美国国家利益构成威胁,往少了数数,否则,往大了数。
Thursday, August 7, 2014
Wednesday, August 6, 2014
Delete columns of data frame in R
> head(data)
chr genome region
1 chr1 hg19_refGene CDS
2 chr1 hg19_refGene exon
3 chr1 hg19_refGene CDS
4 chr1 hg19_refGene exon
5 chr1 hg19_refGene CDS
6 chr1 hg19_refGene exon
and I want to remove the 2nd column.E3Cfc<-E3Cfc[,!(names(E3Cfc)=="pk.bound")]
> Data$genome <- NULL
> head(Data)
chr region
1 chr1 CDS
2 chr1 exon
3 chr1 CDS
4 chr1 exon
5 chr1 CDS
6 chr1 exon
As pointed out in the comments, here are some other possibilities:Data[2] <- NULL # Wojciech Sobala
Data[[2]] <- NULL # same as above
Data <- Data[,-2] # Ian Fellows
Data <- Data[-2] # same as above
You can remove multiple columns via:Data[1:2] <- list(NULL) # Marek
Data[1:2] <- NULL # does not work!
Be careful with matrix-subsetting though, as you can end up with a vector:Data <- Data[,-(2:3)] # vector
Data <- Data[,-(2:3),drop=FALSE] # still a data.frame
Delete a list of elements from data frame in R
This might be an easy question but i still need some help for using R.
I have a data.frame (main_data), lets say..
I have a data.frame (main_data), lets say..
NAMES AGE LOC
Jyo 23 Hyd
Abid 27 Kar
Ras 24 Pun
Poo 25 Goa
Sus 28 Kar
I wish to remove a few rows based on a list of names. So lets say I have another list of table as follows:NAMES_list
Jyo
Ras
Poo
So based on this list, if any of the names match to my above
"main_data" table, then I would like to remove the whole row contianing
them, so the result should be as followsNAMES AGE LOC
Abid 27 Kar
Sus 28 Kar
Solution:
Use
%in% :
|
Monday, August 4, 2014
Resolve Problem in Installing RCurl
Resolve Problem in Installing RCurl, Problem stated as below.
> install.packages("RCurl")
Installing package into ‘/home/hufeng/R/x86_64-pc-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/RCurl_1.95-4.3.tar.gz'
Content type 'application/x-gzip' length 879143 bytes (858 Kb)
opened URL
==================================================
downloaded 858 Kb
* installing *source* package ‘RCurl’ ...
** package ‘RCurl’ successfully unpacked and MD5 sums checked
checking for curl-config... no
Cannot find curl-config
ERROR: configuration failed for package ‘RCurl’
* removing ‘/home/hufeng/R/x86_64-pc-linux-gnu-library/3.0/RCurl’
Warning in install.packages :
installation of package ‘RCurl’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpDnCukv/downloaded_packages’
I installed libcurl4-gnutls-dev and the problem was solved.
In your shell:
> install.packages("RCurl")
Installing package into ‘/home/hufeng/R/x86_64-pc-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/RCurl_1.95-4.3.tar.gz'
Content type 'application/x-gzip' length 879143 bytes (858 Kb)
opened URL
==================================================
downloaded 858 Kb
* installing *source* package ‘RCurl’ ...
** package ‘RCurl’ successfully unpacked and MD5 sums checked
checking for curl-config... no
Cannot find curl-config
ERROR: configuration failed for package ‘RCurl’
* removing ‘/home/hufeng/R/x86_64-pc-linux-gnu-library/3.0/RCurl’
Warning in install.packages :
installation of package ‘RCurl’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpDnCukv/downloaded_packages’
I installed libcurl4-gnutls-dev and the problem was solved.
In your shell:
sudo apt-get -y build-dep libcurl4-gnutls-dev
sudo apt-get -y install libcurl4-gnutls-dev
Sunday, August 3, 2014
R which Function
which(x, arr.ind = FALSE, useNames = TRUE)
arrayInd(ind, .dim, .dimnames = NULL, useNames = FALSE)
x
: logical vector or array. NAs are allowed and omitted (treated as if FALSE)arr.ind
: logical; should array indices be returned when x is an array?ind
: integer-valued index vector, as resulting from which(x).dim
: integer vector.dimnames
: optional list of character dimnames(.), of which only .dimnames[[1]] is useduseNames
: logical indicating if the value of arrayInd() should have (non-null) dimnames at all> BOD
Time demand 1 1 8.3 2 2 10.3 3 3 19.0 4 4 16.0 5 5 15.6 6 7 19.8
> which(BOD$demand == 16)
[1] 4
> x <- matrix(1:9,3,3) > x
[,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9
> which(x %% 3 == 0, arr.ind=TRUE)
row col [1,] 3 1 [2,] 3 2 [3,] 3 3
> which(x %% 3 == 0, arr.ind=FALSE)
[1] 3 6 9
The do.call function
R has an interesting function called do.call. This
function allows you to call any R function, but instead of writing
out the arguments one by one, you can use a list to hold the
arguments of the function. While it may not seem useful on the
surface, a simple example will help to show how powerful do.call
is.
Suppose we have three comma-separated text files that have information on the same three variables. Here's a look at the first few lines in one of the files:
Suppose we have three comma-separated text files that have information on the same three variables. Here's a look at the first few lines in one of the files:
a,b,x,y
b,B,2.49778634403711,-0.351307445767206
b,A,-0.594683138631719,1.19629936975021
b,D,1.14857619580259,0.653315728121014
c,A,0.957476532595248,0.935608419299617
It's easy to read each one in with
read.csv, and then to call the rbind (combine by
rows) function to make one big data frame. (Remember that rbind
will only work if all the data frames being combined have the same variable
names.)> one = read.csv('1.csv')
> nrow(one)
[1] 21
> two = read.csv('2.csv')
> nrow(two)
[1] 25
> three = read.csv('3.csv')
> nrow(three)
[1] 27
> big = rbind(one,two,three)
> nrow(big)
[1] 73
As I said, that was pretty easy. But now suppose we have
20 csv files that we want to read and combine. We could do what we
did with the three files, but, not only would it get tiring, there's
a chance of making an error when we have to type so many commands.
In the past, when we've had problems like this, sapply was able
to help. Let's try it here, by writing a function that will take a
number, create a filename by pasting .csv at the end, and reading
in the data:> allframes = sapply(1:20,function(x)read.csv(paste(x,'csv',sep='.')))
> head(allframes)
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
a factor,21 factor,25 factor,27 factor,25 factor,27 factor,21 factor,24
b factor,21 factor,25 factor,27 factor,25 factor,27 factor,21 factor,24
x Numeric,21 Numeric,25 Numeric,27 Numeric,25 Numeric,27 Numeric,21 Numeric,24
y Numeric,21 Numeric,25 Numeric,27 Numeric,25 Numeric,27 Numeric,21 Numeric,24
[,8] [,9] [,10] [,11] [,12] [,13] [,14]
a factor,28 factor,23 factor,23 factor,22 factor,26 factor,24 factor,23
b factor,28 factor,23 factor,23 factor,22 factor,26 factor,24 factor,23
x Numeric,28 Numeric,23 Numeric,23 Numeric,22 Numeric,26 Numeric,24 Numeric,23
There were no errors, but the result certainly is strange
looking! While we haven't talked about it before, the "s" in sapply
stands for simplify, and the problem that we've just seen is that
sapply tried too hard to simplify our result. It created an
odd matrix, where each element represents one of the columns of one of
the files we read in. Fortunately, there's a function that's closely related
to sapply called lapply. The difference between sapply and
lapply is that lapply will never try to simplify its
results. It will always return a list, the same length as its first
argument, with each element of the list resulting in the function we
passed to lapply operating on one element of the first argument.
In our case, calling lapply instead of sapply will give
us a list of length 20, where each element is the result of calling
read.csv on one of the 20 files. This is where do.call
comes in. Instead of having to pass 20 data frames to rbind, we
can use do.call to pass all 20 of them to rbind, since they
are in a list, and that's exactly what do.call is looking for.> allframes = lapply(1:20,function(x)read.csv(paste(x,'csv',sep='.')))
> sapply(allframes,nrow)
[1] 21 25 27 25 27 21 24 28 23 23 22 26 24 23 25 29 28 30 27 29
> answer = do.call(rbind,allframes)
> nrow(answer)
[1] 507
We can combine all the data frames without storing them
separately or passing them individually to rbind.
Difference between `=` and `<-` in R
- The operators <- and = assign into the environment in which they are evaluated.
- The operator <- can be used anywhere.
- The operator = is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions.
Subscribe to:
Posts (Atom)