2012-02-19 17 views
-4

100から100までのデータセットがあるとします。すべての数の対数を取って変換したい。 Rではどうしますか?既存のデータセットを変更する

+10

'ログ(data_set)'ここからスタート – mbq

+3

:http://cran.r-project.org/ doc/manuals/R-intro.pdf –

答えて

11

まず、サンプルデータを作成します。正の乱数で100×100の行列を作成しました。

## Save the fake data into the object called "Data" 
> Data <- matrix(abs(rnorm(10000)),100,100) 

## We can confirm the dimensions of the matrix like so 
> dim(Data) 
[1] 100 100 

## We can confirm that it is a matrix like so 
> class(Data) 
[1] "matrix" 

## We can take a peak at rows 1 to 5 and columns 1 to 2 like so 
> Data[1:5,1:2] 
      [,1]  [,2] 
[1,] 1.5814281 0.216556739 
[2,] 0.8939682 0.007296336 
[3,] 1.7937537 0.955205600 
[4,] 0.4994752 1.982777723 
[5,] 1.3459607 1.328990348 

ここで、これらの数値の対数をとって、新しいオブジェクトとして保存しましょう。

## First we can take the natural log and save it in the object "Natural" 
Natural <- log(Data) 

## Or we can take the log base 10 and save it in the object "Base10" 
Base10 <- log10(Data) 

## To see all of the objects in your working memory, we can type the following 
ls() 

さらにヘルプが必要な場合はRの基本は、これらのウェブサイトを試して:

  1. http://www.r-tutor.com/
  2. http://twitter.com/#!/RLangTip
+1

ニース、完全かつ丁重な答え。よくできました。 –

+1

下の2つのリンクはかなり価値があります。 – Iterator

関連する問題