|
Creating Data in R
Typically data will be imported from external sources. However, for small or quick analyses, it may be appropriate to manually enter the data directly into R. Creating a vector in R using combine function
Vectors can be created in R using the combine (c) function: : VectorName = c(Value1, Value2, Value3, etc...) EXAMPLE: > UserName = c("Bill", "William", "Ted") > UserAge = c(42, 46, 38) > UserWeight = c(198, 203, 175) Creating a dataframe from individual vectors in R
Individual vectors can be combined to form a dataframe in R per the following: DataFrameName = data.frame(VectorName1, VectorName2, VectorName3, etc...) EXAMPLE: > UserData = data.frame(UserName, UserAge, UserWeight) > UserData UserName UserAge UserWeight Bill 42 198 William 46 203 Ted 38 175 Creating a dataframe in R using a spreadsheet interface
R conveniently has a spreadsheet interface that can be used to enter data into a dataframe using the fix function. This is accomplished by:
NewDataFrame = data.frame() fix(NewDataFrame) EXAMPLE: > NewDataFrame = data.frame() > fix(NewDataFrame) |