Skip to content

Instantly share code, notes, and snippets.

@14021939
Created October 29, 2013 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 14021939/7210098 to your computer and use it in GitHub Desktop.
Save 14021939/7210098 to your computer and use it in GitHub Desktop.
Rのデータフレーム(data.frame)について ref: http://qiita.com/14021939/items/3436a153119bb88d49df
$ R
> name <- c('suzuki','sato','yamada')
> height <- c('172','165','184')
> weight <- c('60','58','75')
> users_table <- data.frame(name,height,weight)
> users_table
name height weight
1 suzuki 172 60
2 sato 165 58
3 yamada 184 75
> users_table[c('name')]
name
1 suzuki
2 sato
3 yamada
> users_table[c('height')]
height
1 172
2 165
3 184
> users_table[c('height','weight')]
height weight
1 172 60
2 165 58
3 184 75
> users_table$name
[1] suzuki sato yamada
Levels: sato suzuki yamada
> with(users_table, height[ name == "yamada"])
[1] 184
Levels: 165 172 184
> users_table
name height weight
1 suzuki 172 60
2 sato 165 58
3 yamada 184 75
> point <- c(100,30,40)
> users_table <- data.frame(users_table, point)
> users_table
name height weight point
1 suzuki 172 60 100
2 sato 165 58 30
3 yamada 184 75 40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment