column_to_rownames: Add a Column as Rownames

Description Usage Arguments Value Examples

View source: R/column_to_rownames.R

Description

Takes an existing column and uses it as rownames instead. This is useful when turning a data.frame into a matrix. Inspired by the tibble package's column_to_row which is now deprecated if done on a tibble object. By coercing to a data.frame this problem is avoided.

Usage

1
column_to_rownames(x, loc = 1)

Arguments

x

An object that can be coerced to a data.frame.

loc

The column location as either an integer or string index location. Must be unique row names.

Value

Returns a data.frame with the specified column moved to rownames.

Examples

1
2
3

Example output

               state.area         x       y     state.division
Alabama             51609  -86.7509 32.5901 East South Central
Alaska             589757 -127.2500 49.2500            Pacific
Arizona            113909 -111.6250 34.2192           Mountain
Arkansas            53104  -92.2992 34.7336 West South Central
California         158693 -119.7730 36.5341            Pacific
Colorado           104247 -105.5130 38.6777           Mountain
Connecticut          5009  -72.3573 41.5928        New England
Delaware             2057  -74.9841 38.6777     South Atlantic
Florida             58560  -81.6850 27.8744     South Atlantic
Georgia             58876  -83.3736 32.3329     South Atlantic
Hawaii               6450 -126.2500 31.7500            Pacific
Idaho               83557 -113.9300 43.5648           Mountain
Illinois            56400  -89.3776 40.0495 East North Central
Indiana             36291  -86.0808 40.0495 East North Central
Iowa                56290  -93.3714 41.9358 West North Central
Kansas              82264  -98.1156 38.4204 West North Central
Kentucky            40395  -84.7674 37.3915 East South Central
Louisiana           48523  -92.2724 30.6181 West South Central
Maine               33215  -68.9801 45.6226        New England
Maryland            10577  -76.6459 39.2778     South Atlantic
Massachusetts        8257  -71.5800 42.3645        New England
Michigan            58216  -84.6870 43.1361 East North Central
Minnesota           84068  -94.6043 46.3943 West North Central
Mississippi         47716  -89.8065 32.6758 East South Central
Missouri            69686  -92.5137 38.3347 West North Central
Montana            147138 -109.3200 46.8230           Mountain
Nebraska            77227  -99.5898 41.3356 West North Central
Nevada             110540 -116.8510 39.1063           Mountain
New Hampshire        9304  -71.3924 43.3934        New England
New Jersey           7836  -74.2336 39.9637    Middle Atlantic
New Mexico         121666 -105.9420 34.4764           Mountain
New York            49576  -75.1449 43.1361    Middle Atlantic
North Carolina      52586  -78.4686 35.4195     South Atlantic
North Dakota        70665 -100.0990 47.2517 West North Central
Ohio                41222  -82.5963 40.2210 East North Central
Oklahoma            69919  -97.1239 35.5053 West South Central
Oregon              96981 -120.0680 43.9078            Pacific
Pennsylvania        45333  -77.4500 40.9069    Middle Atlantic
Rhode Island         1214  -71.1244 41.5928        New England
South Carolina      31055  -80.5056 33.6190     South Atlantic
South Dakota        77047  -99.7238 44.3365 West North Central
Tennessee           42244  -86.4560 35.6767 East South Central
Texas              267339  -98.7857 31.3897 West South Central
Utah                84916 -111.3300 39.1063           Mountain
Vermont              9609  -72.5450 44.2508        New England
Virginia            40815  -78.2005 37.5630     South Atlantic
Washington          68192 -119.7460 47.4231            Pacific
West Virginia       24181  -80.6665 38.4204     South Atlantic
Wisconsin           56154  -89.9941 44.5937 East North Central
Wyoming             97914 -107.2560 43.0504           Mountain
               state.area         x       y     state.division
Alabama             51609  -86.7509 32.5901 East South Central
Alaska             589757 -127.2500 49.2500            Pacific
Arizona            113909 -111.6250 34.2192           Mountain
Arkansas            53104  -92.2992 34.7336 West South Central
California         158693 -119.7730 36.5341            Pacific
Colorado           104247 -105.5130 38.6777           Mountain
Connecticut          5009  -72.3573 41.5928        New England
Delaware             2057  -74.9841 38.6777     South Atlantic
Florida             58560  -81.6850 27.8744     South Atlantic
Georgia             58876  -83.3736 32.3329     South Atlantic
Hawaii               6450 -126.2500 31.7500            Pacific
Idaho               83557 -113.9300 43.5648           Mountain
Illinois            56400  -89.3776 40.0495 East North Central
Indiana             36291  -86.0808 40.0495 East North Central
Iowa                56290  -93.3714 41.9358 West North Central
Kansas              82264  -98.1156 38.4204 West North Central
Kentucky            40395  -84.7674 37.3915 East South Central
Louisiana           48523  -92.2724 30.6181 West South Central
Maine               33215  -68.9801 45.6226        New England
Maryland            10577  -76.6459 39.2778     South Atlantic
Massachusetts        8257  -71.5800 42.3645        New England
Michigan            58216  -84.6870 43.1361 East North Central
Minnesota           84068  -94.6043 46.3943 West North Central
Mississippi         47716  -89.8065 32.6758 East South Central
Missouri            69686  -92.5137 38.3347 West North Central
Montana            147138 -109.3200 46.8230           Mountain
Nebraska            77227  -99.5898 41.3356 West North Central
Nevada             110540 -116.8510 39.1063           Mountain
New Hampshire        9304  -71.3924 43.3934        New England
New Jersey           7836  -74.2336 39.9637    Middle Atlantic
New Mexico         121666 -105.9420 34.4764           Mountain
New York            49576  -75.1449 43.1361    Middle Atlantic
North Carolina      52586  -78.4686 35.4195     South Atlantic
North Dakota        70665 -100.0990 47.2517 West North Central
Ohio                41222  -82.5963 40.2210 East North Central
Oklahoma            69919  -97.1239 35.5053 West South Central
Oregon              96981 -120.0680 43.9078            Pacific
Pennsylvania        45333  -77.4500 40.9069    Middle Atlantic
Rhode Island         1214  -71.1244 41.5928        New England
South Carolina      31055  -80.5056 33.6190     South Atlantic
South Dakota        77047  -99.7238 44.3365 West North Central
Tennessee           42244  -86.4560 35.6767 East South Central
Texas              267339  -98.7857 31.3897 West South Central
Utah                84916 -111.3300 39.1063           Mountain
Vermont              9609  -72.5450 44.2508        New England
Virginia            40815  -78.2005 37.5630     South Atlantic
Washington          68192 -119.7460 47.4231            Pacific
West Virginia       24181  -80.6665 38.4204     South Atlantic
Wisconsin           56154  -89.9941 44.5937 East North Central
Wyoming             97914 -107.2560 43.0504           Mountain

textshape documentation built on May 29, 2021, 1:07 a.m.